Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Add DrivingTableSelectionRule #55513

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KKould
Copy link

@KKould KKould commented Jan 30, 2025

Why I'm doing:

#52399

support similar to #55376: If the table and driving table are only in an OR relationship, cross join is converted to union all

What I'm doing:

DrivingTableSelectionRule is used to adjust the position of the driving table according to the on predicate of the inner join when multiple tables are cross joined and the root is an inner join. Reduce the overhead caused by Join in this case

mysql> explain logical select *  from T where T.a = (select a from T0) and T.b = (select b from T1) or T.c = (select c from T2);
+-------------------------------------------------------------------------------------------------------------+
| Explain String                                                                                              |
+-------------------------------------------------------------------------------------------------------------+
| - Output => [1:a, 2:b, 3:c]                                                                                 |
|     - NESTLOOP/INNER JOIN [1:a = 4:a AND 2:b = 9:b OR 3:c = 14:c] => [1:a, 2:b, 3:c]                        |
|             Estimates: {row: 6, cpu: 1728.00, memory: 7200.00, network: 0.00, cost: 16017132.00}            |
|         - UNION => [4: a, 9: b, 14: c]                                                                      |
|                 Estimates: {row: 2, cpu: ?, memory: ?, network: ?, cost: 1.6001706E7}                       |
|             - NESTLOOP/CROSS JOIN => [4:a, 9:b, 14:c]                                                       |
|                     Estimates: {row: 1, cpu: 32000000.00, memory: 800.00, network: 0.00, cost: 16001676.00} |
|                     14:c := null                                                                            |
|                 - ASSERT LE 1                                                                               |
|                         Estimates: {row: 1, cpu: ?, memory: ?, network: ?, cost: 30.0}                      |
|                     - EXCHANGE(GATHER)                                                                      |
|                             Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 30.0}                  |
|                         - SCAN [T0] => [4:a]                                                                |
|                                 Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 6.0}               |
|                                 partitionRatio: 1/1, tabletRatio: 1/1                                       |
|                 - EXCHANGE(BROADCAST)                                                                       |
|                         Estimates: {row: 1, cpu: ?, memory: ?, network: ?, cost: 46.0}                      |
|                     - ASSERT LE 1                                                                           |
|                             Estimates: {row: 1, cpu: ?, memory: ?, network: ?, cost: 30.0}                  |
|                         - EXCHANGE(GATHER)                                                                  |
|                                 Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 30.0}              |
|                             - SCAN [T1] => [9:b]                                                            |
|                                     Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 6.0}           |
|                                     partitionRatio: 1/1, tabletRatio: 1/1                                   |
|             - ASSERT LE 1                                                                                   |
|                     Estimates: {row: 1, cpu: 0.00, memory: 0.00, network: 0.00, cost: 30.00}                |
|                     4:a := null                                                                             |
|                     9:b := null                                                                             |
|                 - EXCHANGE(GATHER)                                                                          |
|                         Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 30.0}                      |
|                     - SCAN [T2] => [14:c]                                                                   |
|                             Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 6.0}                   |
|                             partitionRatio: 1/1, tabletRatio: 1/1                                           |
|         - EXCHANGE(BROADCAST)                                                                               |
|                 Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 162.0}                             |
|             - SCAN [T] => [1:a, 2:b, 3:c]                                                                   |
|                     Estimates: {row: 3, cpu: ?, memory: ?, network: ?, cost: 18.0}                          |
|                     partitionRatio: 1/1, tabletRatio: 1/1                                                   |
+-------------------------------------------------------------------------------------------------------------+

Implementation idea:

Analyze the corresponding relationship between the tables of the two columns in the BinaryPredicateOperator through the on predicate of the inner join, and establish an undirected graph. When all edges only have the same table as the endpoint, the table is a driving table, which is the top layer of the inner join table to replace(if the replaced node is not the driving table)

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • 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:

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

Signed-off-by: Kould <kould2333@gmail.com>
@KKould KKould requested a review from a team as a code owner January 30, 2025 13:43
@mergify mergify bot assigned KKould Jan 30, 2025
@KKould KKould changed the title feat: add DrivingTableSelectionRule [Enhancement] Add DrivingTableSelectionRule Jan 30, 2025
@KKould KKould requested a review from a team as a code owner February 2, 2025 14:15
@KKould KKould force-pushed the feat/driving_table_selection branch from 5e4a8e1 to 393cf57 Compare February 2, 2025 14:23
Signed-off-by: Kould <kould2333@gmail.com>
@KKould KKould force-pushed the feat/driving_table_selection branch from 393cf57 to c98645b Compare February 4, 2025 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant