starrocks icon indicating copy to clipboard operation
starrocks copied to clipboard

[Enhancement] eliminate unnecessary project

Open before-Sunrise opened this issue 1 year ago • 3 comments

Why I'm doing:

before this pr: two project cause const column unpacking in first project, so second project's input always be non-const column, which will influence performance

| PLAN FRAGMENT 3                                                                                 |
|  OUTPUT EXPRS:                                                                                  |
|   PARTITION: UNPARTITIONED                                                                      |
|                                                                                                 |
|   STREAM DATA SINK                                                                              |
|     EXCHANGE ID: 04                                                                             |
|     RANDOM                                                                                      |
|                                                                                                 |
|   3:Project                                                                                     |
|   |  <slot 21> : array_length(20: expr)                                                         |
|   |                                                                                             |
|   2:Project                                                                                     |
|   |  <slot 20> : CAST('["{"factoryCalendar":{"entries":[{"startDate":"86...' AS ARRAY<VARCHAR>) |
|   |                                                                                             |
|   1:UNION                                                                                       |
|      constant exprs:                                                                            |
|          1                                                                                      |
|          2

What I'm doing:

add a new map in ExpressionMapping, if one columnRef operator is in this map, which means this column is generated by a const expr, so we can use the corresponding value(const expr) in map to replace it.

so plan will be :

| PLAN FRAGMENT 3                                                                                               |
|  OUTPUT EXPRS:                                                                                                |
|   PARTITION: UNPARTITIONED                                                                                    |
|                                                                                                               |
|   STREAM DATA SINK                                                                                            |
|     EXCHANGE ID: 03                                                                                           |
|     RANDOM                                                                                                    |
|                                                                                                               |
|   2:Project                                                                                                   |
|   |  <slot 21> : array_length(CAST('["{"factoryCalendar":{"entries":[{"startDate":"86...' AS ARRAY<VARCHAR>)) |
|   |                                                                                                           |
|   1:UNION                                                                                                     |
|      constant exprs:                                                                                          |
|          NULL                                                                                                 |
|          'id'

only have one project node, because the lower project node's output column is not used by any other node, so it can be eliminated by other rules. Fixes #issue

What type of PR is this:

  • [ ] BugFix
  • [ ] Feature
  • [x] Enhancement
  • [ ] Refactor
  • [ ] UT
  • [ ] Doc
  • [ ] Tool

Does this PR entail a change in behavior?

  • [ ] Yes, this PR will result in a change in behavior.
  • [x] No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • [ ] Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • [ ] Parameter changes: default values, similar parameters but with different default values
  • [ ] Policy changes: use new policy to replace old one, functionality automatically enabled
  • [ ] Feature removed
  • [ ] Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • [ ] I have added test cases for my bug fix or my new feature
  • [ ] This pr needs user documentation (for new or modified features or behaviors)
  • [ ] I have added documentation for my new feature or new function
  • [ ] This is a backport pr

Bugfix cherry-pick branch check:

  • [x] I have checked the version labels which the pr will be auto-backported to the target branch
    • [ ] 3.3
    • [ ] 3.2
    • [ ] 3.1
    • [ ] 3.0
    • [ ] 2.5

Documentation PRs only:

If you are submitting a PR that adds or changes English documentation and have not included Chinese documentation, then you can check the box to request GPT to translate the English doc to Chinese. Please ensure to uncheck the Do not translate box if translation is needed. The workflow will generate a new PR with the Chinese translation after this PR is merged.

  • [ ] Yes, translate English markdown files with GPT
  • [x] Do not translate

before-Sunrise avatar Aug 12 '24 11:08 before-Sunrise

Any updates on this PR?

fieldsfarmer avatar Aug 29 '24 15:08 fieldsfarmer

Any updates on this PR?

I will deal with it tomorrow

before-Sunrise avatar Sep 01 '24 02:09 before-Sunrise

[Java-Extensions Incremental Coverage Report]

:white_check_mark: pass : 0 / 0 (0%)

github-actions[bot] avatar Sep 03 '24 08:09 github-actions[bot]

[FE Incremental Coverage Report]

:white_check_mark: pass : 100 / 102 (98.04%)

file detail

path covered_line new_line coverage not_covered_line_detail
:large_blue_circle: com/starrocks/sql/optimizer/transformer/ExpressionMapping.java 19 20 95.00% [156]
:large_blue_circle: com/starrocks/sql/optimizer/transformer/RelationTransformer.java 39 40 97.50% [1290]
:large_blue_circle: com/starrocks/sql/optimizer/Optimizer.java 1 1 100.00% []
:large_blue_circle: com/starrocks/sql/optimizer/transformer/QueryTransformer.java 10 10 100.00% []
:large_blue_circle: com/starrocks/sql/optimizer/rule/tree/InlineCteProjectPruneRule.java 22 22 100.00% []
:large_blue_circle: com/starrocks/sql/optimizer/transformer/OptExprBuilder.java 3 3 100.00% []
:large_blue_circle: com/starrocks/sql/optimizer/transformer/SqlToScalarOperatorTranslator.java 4 4 100.00% []
:large_blue_circle: com/starrocks/sql/optimizer/operator/Projection.java 2 2 100.00% []

github-actions[bot] avatar Sep 03 '24 08:09 github-actions[bot]

[BE Incremental Coverage Report]

:white_check_mark: pass : 0 / 0 (0%)

github-actions[bot] avatar Sep 03 '24 08:09 github-actions[bot]

@Mergify backport branch-3.3

before-Sunrise avatar Sep 04 '24 01:09 before-Sunrise

backport branch-3.3

✅ Backports have been created

mergify[bot] avatar Sep 04 '24 01:09 mergify[bot]

@Mergify backport branch-3.2

before-Sunrise avatar Sep 04 '24 01:09 before-Sunrise

backport branch-3.2

✅ Backports have been created

mergify[bot] avatar Sep 04 '24 01:09 mergify[bot]