Updated implementation

This commit is contained in:
Maksim Kita 2024-04-09 18:52:45 +03:00
parent 1218cf1568
commit 6c307f043e
2 changed files with 27 additions and 7 deletions

View File

@ -349,8 +349,30 @@ static size_t tryPushDownOverJoinStep(QueryPlan::Node * parent_node, QueryPlan::
size_t updated_steps = 0;
/** If result filter to left or right stream has column that is one of the stream inputs, we need distinguish filter column from
* actual input column. It is necessary because after filter step, filter column became constant column with value 1, and
* not all JOIN algorithms properly work with constants.
*
* Example: SELECT key FROM ( SELECT key FROM t1 ) AS t1 JOIN ( SELECT key FROM t1 ) AS t2 ON t1.key = t2.key WHERE key;
*/
auto update_stream_filter_node_if_needed = [&](ActionsDAG & stream_filter, const Block & stream_header)
{
auto & stream_filter_output_nodes = stream_filter.getOutputs();
const auto & stream_filter_node = stream_filter_output_nodes[0];
if (!stream_header.has(stream_filter_node->result_name))
return false;
auto & alias_node = stream_filter.addAlias(*stream_filter_node, "__filter" + stream_filter_node->result_name);
stream_filter_output_nodes.insert(stream_filter_output_nodes.begin(), &alias_node);
return true;
};
if (join_filter_push_down_actions.left_stream_filter_to_push_down)
{
bool updated_filter = update_stream_filter_node_if_needed(*join_filter_push_down_actions.left_stream_filter_to_push_down, left_stream_input_header);
if (updated_filter)
join_filter_push_down_actions.left_stream_filter_removes_filter = true;
updated_steps += addNewFilterStepOrThrow(parent_node,
nodes,
join_filter_push_down_actions.left_stream_filter_to_push_down,
@ -365,6 +387,10 @@ static size_t tryPushDownOverJoinStep(QueryPlan::Node * parent_node, QueryPlan::
if (join_filter_push_down_actions.right_stream_filter_to_push_down)
{
bool updated_filter = update_stream_filter_node_if_needed(*join_filter_push_down_actions.right_stream_filter_to_push_down, right_stream_input_header);
if (updated_filter)
join_filter_push_down_actions.right_stream_filter_removes_filter = true;
updated_steps += addNewFilterStepOrThrow(parent_node,
nodes,
join_filter_push_down_actions.right_stream_filter_to_push_down,

View File

@ -1,16 +1,10 @@
1
1
1
1
1
1 1
1
1
1
1
1
1 1
1 1
1 1
1 1
1 1
1 2