diff options
| author | aozeritsky <[email protected]> | 2023-09-23 17:36:55 +0300 |
|---|---|---|
| committer | aozeritsky <[email protected]> | 2023-09-23 17:52:28 +0300 |
| commit | 95e7bf1f39cebddccbd7661f63cf88a8c523118b (patch) | |
| tree | 5ec64c0502c7b862aa074246047d42dc0ff58785 | |
| parent | ec7779ee94a6a770b850290ea546704ad48cec40 (diff) | |
Fill costs fields
| -rw-r--r-- | ydb/library/yql/dq/opt/dq_opt_join_cost_based.cpp | 2 | ||||
| -rw-r--r-- | ydb/library/yql/dq/opt/dq_opt_join_cost_based_generic.cpp | 11 | ||||
| -rw-r--r-- | ydb/library/yql/sql/pg/optimizer.cpp | 2 | ||||
| -rw-r--r-- | ydb/library/yql/sql/pg/optimizer_ut.cpp | 16 |
4 files changed, 22 insertions, 9 deletions
diff --git a/ydb/library/yql/dq/opt/dq_opt_join_cost_based.cpp b/ydb/library/yql/dq/opt/dq_opt_join_cost_based.cpp index e37ed79ff88..b581859b7c8 100644 --- a/ydb/library/yql/dq/opt/dq_opt_join_cost_based.cpp +++ b/ydb/library/yql/dq/opt/dq_opt_join_cost_based.cpp @@ -997,6 +997,8 @@ public: TOutput output; output.Input = &Input; BuildOutput(&output, result.get()); + output.Rows = result->Stats->Nrows; + output.TotalCost = *result->Stats->Cost; if (Log) { Log(output.ToString()); } diff --git a/ydb/library/yql/dq/opt/dq_opt_join_cost_based_generic.cpp b/ydb/library/yql/dq/opt/dq_opt_join_cost_based_generic.cpp index b4bf3be73ff..95459586414 100644 --- a/ydb/library/yql/dq/opt/dq_opt_join_cost_based_generic.cpp +++ b/ydb/library/yql/dq/opt/dq_opt_join_cost_based_generic.cpp @@ -192,7 +192,11 @@ TExprBase DqOptimizeEquiJoinWithCosts( return node; } + int cols = 0; state.CollectJoins(equiJoin.Arg(equiJoin.ArgCount() - 2).Ptr()); + for (auto& rel : state.Input.Rels) { + cols += rel.TargetVars.size(); + } state.Input.Normalize(); std::unique_ptr<IOptimizer> opt = std::unique_ptr<IOptimizer>(optFactory(std::move(state.Input))); state.Result = opt->JoinSearch(); @@ -205,9 +209,14 @@ TExprBase DqOptimizeEquiJoinWithCosts( joinArgs.push_back(state.BuildTree(ctx, 0)); joinArgs.push_back(equiJoin.Arg(equiJoin.ArgCount() - 1)); - return Build<TCoEquiJoin>(ctx, equiJoin.Pos()) + auto res = Build<TCoEquiJoin>(ctx, equiJoin.Pos()) .Add(joinArgs) .Done(); + + + typesCtx.StatisticsMap[res.Raw()] = std::make_shared<TOptimizerStatistics>(state.Result.Rows, cols, state.Result.TotalCost); + + return res; } } // namespace NYql::NDq diff --git a/ydb/library/yql/sql/pg/optimizer.cpp b/ydb/library/yql/sql/pg/optimizer.cpp index 8a3745c0568..33f04365171 100644 --- a/ydb/library/yql/sql/pg/optimizer.cpp +++ b/ydb/library/yql/sql/pg/optimizer.cpp @@ -167,6 +167,8 @@ void TPgOptimizer::LogNode(const TString& prefix, void* node) IOptimizer::TOutput TPgOptimizer::MakeOutput(Path* path) { TOutput output = {{}, &Input}; + output.Rows = path->rows; + output.TotalCost = path->total_cost; MakeOutputJoin(output, path); return output; } diff --git a/ydb/library/yql/sql/pg/optimizer_ut.cpp b/ydb/library/yql/sql/pg/optimizer_ut.cpp index ccc717cc5dc..5fecfcd8d89 100644 --- a/ydb/library/yql/sql/pg/optimizer_ut.cpp +++ b/ydb/library/yql/sql/pg/optimizer_ut.cpp @@ -33,8 +33,8 @@ Y_UNIT_TEST(PgJoinSearch2Rels) { auto res = optimizer->JoinSearch(); auto resStr = res.ToString(); Cerr << resStr; - TString expected = R"__(Rows: 0.00 -TotalCost: 0.00 + TString expected = R"__(Rows: 500000000.00 +TotalCost: 10000001260000260.00 { Inner Join Loop Strategy @@ -79,8 +79,8 @@ Y_UNIT_TEST(PgJoinSearch2RelsLeft) { auto res = optimizer->JoinSearch(); auto resStr = res.ToString(); Cerr << resStr; - TString expected = R"__(Rows: 0.00 -TotalCost: 0.00 + TString expected = R"__(Rows: 500000000.00 +TotalCost: 1650702509.00 { Left Join Loop Strategy @@ -125,8 +125,8 @@ Y_UNIT_TEST(PgJoinSearch2RelsRight) { auto res = optimizer->JoinSearch(); auto resStr = res.ToString(); Cerr << resStr; - TString expected = R"__(Rows: 0.00 -TotalCost: 0.00 + TString expected = R"__(Rows: 500000000.00 +TotalCost: 1260000259.00 { Left Join Loop Strategy @@ -163,8 +163,8 @@ Y_UNIT_TEST(PgJoinSearch3Rels) { auto res = optimizer->JoinSearch(); auto resStr = res.ToString(); Cerr << resStr; - TString expected = R"__(Rows: 0.00 -TotalCost: 0.00 + TString expected = R"__(Rows: 25000000000.00 +TotalCost: 25100000272571156.00 { Inner Join Hash Strategy |
