Skip to content

fix: preserve TopK dynamic filters across recursive CTE iterations - #26670

Open
Kristofferjoha wants to merge 5 commits into
apache:mainfrom
Kristofferjoha:fix/topk-recursive-26642
Open

Kristofferjoha wants to merge 5 commits into
apache:mainfrom
Kristofferjoha:fix/topk-recursive-26642

Conversation

@Kristofferjoha

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Closes #26642.

Rationale for this change

TopK dynamic filters inside recursive CTEs stop updating the scan because SortExec::reset_state() creates a new filter on each iteration, while the scan still references the original one. This prevents pruning during recursive queries.

What changes are included in this PR?

  • Reset the existing shared dynamic filter instead of replacing it.
  • Rebuild the TopK filter state using the existing DynamicFilterPhysicalExpr.
  • Add a recursive TopK regression test in cte.slt.

Depends on #26056 for DynamicFilterPhysicalExpr::reset(). It hasn't been merged yet, but it has been approved, so I based this change on its implementation.

What is the testing strategy for this PR?

The new cte.slt case checks that the recursive query returns 1–4 and that the Parquet scan outputs 30 rows instead of 300, pruning 27 row groups across three iterations.

Are there any user-facing changes?

No.

@Kristofferjoha Kristofferjoha changed the title Fix/topk recursive 26642 fix: preserve TopK dynamic filters across recursive CTE iterations Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TopK dynamic filters don't prune inside recursive CTEs

2 participants