Repository navigation
Optimize join performance by extracting common expressions - #71537
antaljanosbenjamin merged 36 commits into
Conversation
|
This is an automated comment for commit 5219035 with description of existing statuses. It's updated for the latest CI running ✅ Click here to open a full report in a separate page Successful checks
|
7bcabee to
911d775
Compare
|
@novikd The pr is ready to be review |
|
And of course I messed up something and my test is failing... Checking out. |
|
Done. |
…rmance-by-extracting-common-exprs
…rmance-by-extracting-common-exprs
…rmance-by-extracting-common-exprs
|
I think the test failures are not related. @novikd could you please have a look at it once you will have time? |
| rerunFunctionResolve(function_node, getContext()); | ||
|
|
||
| // The optimization only makes sense on the top level | ||
| if (node != join_node->getJoinExpression() || !getSettings()[Setting::optimize_extract_common_expressions]) |
There was a problem hiding this comment.
Can join_node be nullptr at this moment?
There was a problem hiding this comment.
I changed the code so we use a reference instead of this unnecessary pointer. This way we express that it cannot be nullptr.
| { | ||
| auto * and_node = maybe_and_node->as<FunctionNode>(); | ||
| if (!and_node || and_node->getFunctionName() != "and") | ||
| return {}; // one of the nodes is not an "AND", thus there is no common expression to extract |
There was a problem hiding this comment.
How would it work with A | (A & B) | (A & C)? It can be replaced with just A.
Of course, we can't optimize A | (B & C) | (D & E)
There was a problem hiding this comment.
But it can probably be done in a separate PR.
There was a problem hiding this comment.
Yes, currently single arguments won't be considered to extract. It is a reasonable expectation that it should work, so I am happy to add it in another PR, but I wouldn't like to drag this PR more than it is necessary.
| } | ||
|
|
||
| // If all the arguments of the OR expression is eliminated or one argument is completely eliminated, there is no need for new node. | ||
| if (new_or_arguments.empty() || has_completely_extracted_and_expression) |
There was a problem hiding this comment.
So you support (A & B) | (A & B & C) -> A & B, but not A | (A & B) -> A
Resolves #70802
The optimization will be turned on by default with #71926, because that fixes the cases which this optimization might break.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Add option to extract common expressions from
WHEREandONexpressions in order to reduce the number of hash tables used during joins. Can be enabled byoptimize_extract_common_expressions = 1.Documentation entry for user-facing changes
CI Settings (Only check the boxes if you know what you are doing):