@@ -331,22 +331,34 @@ bool LateMaterialization::TryLateMaterialization(unique_ptr<LogicalOperator> &op
331
331
if (root_type == LogicalOperatorType::LOGICAL_TOP_N) {
332
332
// for top-n we need to order on expressions, so we need to order AFTER the final projection
333
333
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
+ }
334
337
proj->children .push_back (std::move (join));
335
338
336
339
for (auto &order : final_orders) {
337
340
ReplaceTableReferences (*order.expression , proj_index);
338
341
}
339
342
auto order = make_uniq<LogicalOrder>(std::move (final_orders));
343
+ if (proj->has_estimated_cardinality ) {
344
+ order->SetEstimatedCardinality (proj->estimated_cardinality );
345
+ }
340
346
order->children .push_back (std::move (proj));
341
347
342
348
op = std::move (order);
343
349
} else {
344
350
// for limit/sample we order on row-id, so we need to order BEFORE the final projection
345
351
// because the final projection removes row-ids
346
352
auto order = make_uniq<LogicalOrder>(std::move (final_orders));
353
+ if (join->has_estimated_cardinality ) {
354
+ order->SetEstimatedCardinality (join->estimated_cardinality );
355
+ }
347
356
order->children .push_back (std::move (join));
348
357
349
358
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
+ }
350
362
proj->children .push_back (std::move (order));
351
363
352
364
op = std::move (proj);
0 commit comments