From 9eb95d9ac18eef1b72e4e4fbdf884da3fb2bab94 Mon Sep 17 00:00:00 2001 From: alexpaniman Date: Fri, 17 Jul 2026 09:29:39 +0300 Subject: [CBO] Switch to byte side when selecting which side to shuffle and it can be either (#46651) --- ydb/core/kqp/executer_actor/kqp_tasks_graph_ut.cpp | 20 ++++++++++---------- ydb/core/kqp/opt/cbo/solver/kqp_opt_dphyp_solver.h | 2 +- .../kqp/opt/cbo/solver/kqp_opt_join_cost_based.cpp | 2 +- .../data/join_order/tpch4_1000s_column_store.json | 20 ++++++++++---------- ydb/core/kqp/ut/join/kqp_join_order_ut.cpp | 4 ++-- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/ydb/core/kqp/executer_actor/kqp_tasks_graph_ut.cpp b/ydb/core/kqp/executer_actor/kqp_tasks_graph_ut.cpp index 03c256c149e..849e02048f8 100644 --- a/ydb/core/kqp/executer_actor/kqp_tasks_graph_ut.cpp +++ b/ydb/core/kqp/executer_actor/kqp_tasks_graph_ut.cpp @@ -1045,22 +1045,22 @@ Y_UNIT_TEST_SUITE(TKqpTasksGraphBuild) { AssertNoCrossNodeCopyChannels(dist); UNIT_ASSERT_VALUES_EQUAL(dist.TasksPerStage.size(), 6u); - UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 0), 360); - UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 1), 360); - UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 2), 360); - UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 3), 360); - UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 4), 360); + UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 0), 256); + UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 1), 570); + UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 2), 570); + UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 3), 256); + UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 4), 71); UNIT_ASSERT_VALUES_EQUAL(dist.Count(0, 5), 1); UNIT_ASSERT_VALUES_EQUAL(dist.NodesUsed(), NODE_COUNT); UNIT_ASSERT_VALUES_EQUAL(dist.UnplacedTasks, 0); AssertNodeDistribution(dist, 0, { - /* stage 0 */ { {3, 120} }, - /* stage 1 */ { {3, 120} }, - /* stage 2 */ { {3, 120} }, - /* stage 3 */ { {3, 120} }, - /* stage 4 */ { {3, 120} }, + /* stage 0 */ { {2, 104}, {3, 16} }, + /* stage 1 */ { {4, 30}, {5, 90} }, + /* stage 2 */ { {4, 30}, {5, 90} }, + /* stage 3 */ { {2, 104}, {3, 16} }, + /* stage 4 */ { {1, 71} }, /* stage 5 */ { {1, 1} }, }); } diff --git a/ydb/core/kqp/opt/cbo/solver/kqp_opt_dphyp_solver.h b/ydb/core/kqp/opt/cbo/solver/kqp_opt_dphyp_solver.h index 33c9a5ab195..d32e768a760 100644 --- a/ydb/core/kqp/opt/cbo/solver/kqp_opt_dphyp_solver.h +++ b/ydb/core/kqp/opt/cbo/solver/kqp_opt_dphyp_solver.h @@ -1131,7 +1131,7 @@ template void TDPHypSolverShuffleElimination::EmitC // TODO: we can remove shuffle from here, joinkeys.size() == getshufflehashargscount() isn't nescesary condition. GetShuffleHashFuncArgsCount must be equal, otherwise we will reshuffle. // bool sameHashFuncArgCount = (lhsHashFuncArgCnt == rhsHashFuncArgCnt); if (lhsShuffled && rhsShuffled /* we don't support not shuffling two inputs in the execution, so we must shuffle at least one*/) { - if (leftNode->Stats.Nrows < rightNode->Stats.Nrows) { + if (leftNode->Stats.ByteSize < rightNode->Stats.ByteSize) { lhsShuffled = false; } else { rhsShuffled = false; diff --git a/ydb/core/kqp/opt/cbo/solver/kqp_opt_join_cost_based.cpp b/ydb/core/kqp/opt/cbo/solver/kqp_opt_join_cost_based.cpp index f0d823a743b..4ee7e4e53ff 100644 --- a/ydb/core/kqp/opt/cbo/solver/kqp_opt_join_cost_based.cpp +++ b/ydb/core/kqp/opt/cbo/solver/kqp_opt_join_cost_based.cpp @@ -489,7 +489,7 @@ private: right->Stats.LogicalOrderings.GetShuffleHashFuncArgsCount() == static_cast(edge->RightJoinKeys.size()); if (lhsShuffled && rhsShuffled /* we don't support not shuffling two inputs in the execution, so we must shuffle at least one*/) { - if (left->Stats.Nrows < right->Stats.Nrows) { + if (left->Stats.ByteSize < right->Stats.ByteSize) { lhsShuffled = false; } else { rhsShuffled = false; diff --git a/ydb/core/kqp/ut/join/data/join_order/tpch4_1000s_column_store.json b/ydb/core/kqp/ut/join/data/join_order/tpch4_1000s_column_store.json index c596b1b1a9d..5d5fdb9daf4 100644 --- a/ydb/core/kqp/ut/join/data/join_order/tpch4_1000s_column_store.json +++ b/ydb/core/kqp/ut/join/data/join_order/tpch4_1000s_column_store.json @@ -11,20 +11,20 @@ "args": [ { - "op_name":"TableFullScan", - "table":"orders" + "op_name":"HashShuffle", + "args": + [ + { + "op_name":"TableFullScan", + "table":"lineitem" + } + ] } ] }, { - "op_name":"HashShuffle", - "args": - [ - { - "op_name":"TableFullScan", - "table":"lineitem" - } - ] + "op_name":"TableFullScan", + "table":"orders" } ] } diff --git a/ydb/core/kqp/ut/join/kqp_join_order_ut.cpp b/ydb/core/kqp/ut/join/kqp_join_order_ut.cpp index 2af7ff87dcd..561b54747c5 100644 --- a/ydb/core/kqp/ut/join/kqp_join_order_ut.cpp +++ b/ydb/core/kqp/ut/join/kqp_join_order_ut.cpp @@ -874,8 +874,8 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) { { auto join = joinFinder.Find({"t1", "t2", "t3"}); UNIT_ASSERT_EQUAL(join.Join, "InnerJoin (BlockHash)"); - UNIT_ASSERT(join.LhsShuffled); - UNIT_ASSERT(!join.RhsShuffled); + UNIT_ASSERT(!join.LhsShuffled); + UNIT_ASSERT(join.RhsShuffled); } UNIT_ASSERT(resultSets.size() == 1); -- cgit v1.3