Skip to content

Commit 0d6e89f

Browse files
committed
pull up estimated cardinality from child
1 parent 3d1a1a9 commit 0d6e89f

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

src/optimizer/column_lifetime_analyzer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ void ColumnLifetimeAnalyzer::AddVerificationProjection(unique_ptr<LogicalOperato
222222

223223
// Create a projection and swap the operators accordingly
224224
auto projection = make_uniq<LogicalProjection>(table_index, std::move(expressions));
225+
if (child->has_estimated_cardinality) {
226+
projection->SetEstimatedCardinality(child->estimated_cardinality);
227+
}
225228
projection->children.emplace_back(std::move(child));
226229
child = std::move(projection);
227230

src/optimizer/late_materialization.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,22 +331,34 @@ bool LateMaterialization::TryLateMaterialization(unique_ptr<LogicalOperator> &op
331331
if (root_type == LogicalOperatorType::LOGICAL_TOP_N) {
332332
// for top-n we need to order on expressions, so we need to order AFTER the final projection
333333
auto proj = make_uniq<LogicalProjection>(proj_index, std::move(final_proj_list));
334+
if (join->has_estimated_cardinality) {
335+
proj->SetEstimatedCardinality(join->estimated_cardinality);
336+
}
334337
proj->children.push_back(std::move(join));
335338

336339
for (auto &order : final_orders) {
337340
ReplaceTableReferences(*order.expression, proj_index);
338341
}
339342
auto order = make_uniq<LogicalOrder>(std::move(final_orders));
343+
if (proj->has_estimated_cardinality) {
344+
order->SetEstimatedCardinality(proj->estimated_cardinality);
345+
}
340346
order->children.push_back(std::move(proj));
341347

342348
op = std::move(order);
343349
} else {
344350
// for limit/sample we order on row-id, so we need to order BEFORE the final projection
345351
// because the final projection removes row-ids
346352
auto order = make_uniq<LogicalOrder>(std::move(final_orders));
353+
if (join->has_estimated_cardinality) {
354+
order->SetEstimatedCardinality(join->estimated_cardinality);
355+
}
347356
order->children.push_back(std::move(join));
348357

349358
auto proj = make_uniq<LogicalProjection>(proj_index, std::move(final_proj_list));
359+
if (order->has_estimated_cardinality) {
360+
proj->SetEstimatedCardinality(order->estimated_cardinality);
361+
}
350362
proj->children.push_back(std::move(order));
351363

352364
op = std::move(proj);

src/optimizer/sum_rewriter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ void SumRewriterOptimizer::RewriteSums(unique_ptr<LogicalOperator> &op) {
167167

168168
// push the projection to replace the aggregate
169169
auto proj = make_uniq<LogicalProjection>(proj_index, std::move(projection_expressions));
170+
if (op->has_estimated_cardinality) {
171+
proj->SetEstimatedCardinality(op->estimated_cardinality);
172+
}
170173
proj->children.push_back(std::move(op));
171174
op = std::move(proj);
172175
}

0 commit comments

Comments
 (0)