|
24 | 24 | #include "velox/expression/ScopedVarSetter.h" |
25 | 25 |
|
26 | 26 | namespace facebook::axiom::optimizer { |
27 | | - |
28 | | -void Cost::add(const Cost& other) { |
29 | | - inputCardinality += other.inputCardinality; |
30 | | - fanout += other.fanout; |
31 | | - setupCost += other.setupCost; |
32 | | -} |
33 | | - |
34 | 27 | namespace { |
35 | 28 |
|
36 | 29 | const auto& relTypeNames() { |
@@ -216,8 +209,7 @@ void RelationOp::printCost(bool detail, std::stringstream& out) const { |
216 | 209 | auto ctx = queryCtx(); |
217 | 210 | if (ctx && ctx->contextPlan()) { |
218 | 211 | auto plan = ctx->contextPlan(); |
219 | | - auto totalCost = plan->cost.unitCost + plan->cost.setupCost; |
220 | | - auto pct = 100 * cost_.inputCardinality * cost_.unitCost / totalCost; |
| 212 | + auto pct = 100 * cost_.cost() / plan->cost.cost(); |
221 | 213 | out << " " << std::fixed << std::setprecision(2) << pct << "% "; |
222 | 214 | } |
223 | 215 | if (detail) { |
@@ -353,7 +345,7 @@ Join::Join( |
353 | 345 | cost_.inputCardinality = inputCardinality(); |
354 | 346 | cost_.fanout = fanout; |
355 | 347 |
|
356 | | - const float buildSize = right->cost().inputCardinality; |
| 348 | + const float buildSize = right->resultCardinality(); |
357 | 349 | const auto numRightColumns = |
358 | 350 | static_cast<float>(right->input()->columns().size()); |
359 | 351 | auto rowCost = numRightColumns * Costs::kHashExtractColumnCost; |
@@ -535,7 +527,7 @@ Aggregation::Aggregation( |
535 | 527 | // being unique after n values is 1 - (1/d)^n. |
536 | 528 | auto nOut = cardinality - |
537 | 529 | cardinality * |
538 | | - std::pow(1.0F - (1.0F / cardinality), input_->resultCardinality()); |
| 530 | + std::pow(1.0F - (1.0F / cardinality), cost_.inputCardinality); |
539 | 531 |
|
540 | 532 | cost_.fanout = nOut / cost_.inputCardinality; |
541 | 533 | const auto numGrouppingKeys = static_cast<float>(groupingKeys.size()); |
@@ -802,8 +794,7 @@ UnionAll::UnionAll(RelationOpPtrVector inputsVector) |
802 | 794 | : RelationOp{RelType::kUnionAll, nullptr, Distribution{}, inputsVector[0]->columns()}, |
803 | 795 | inputs{std::move(inputsVector)} { |
804 | 796 | for (auto& input : inputs) { |
805 | | - cost_.inputCardinality += |
806 | | - input->cost().inputCardinality * input->cost().fanout; |
| 797 | + cost_.inputCardinality += input->resultCardinality(); |
807 | 798 | } |
808 | 799 |
|
809 | 800 | cost_.fanout = 1; |
|
0 commit comments