Skip to content

refactor(sql): reduce copies of query context in PlannerContext - #20630

Open
FrankChen021 wants to merge 2 commits into
apache:masterfrom
FrankChen021:reduce-planner-query-context-copies
Open

FrankChen021 wants to merge 2 commits into
apache:masterfrom
FrankChen021:reduce-planner-query-context-copies

Conversation

@FrankChen021

Copy link
Copy Markdown
Member

Description

PlannerContext stored the query context as a mutable map, and every queryContext() call built a new QueryContext (a sorted copy) from it. queryContext() is called many times during planning.

This PR makes PlannerContext hold a single immutable QueryContext and return it directly:

  • queryContextMap() now returns an immutable snapshot.
  • The four places that wrote into that map during planning (INSERT/REPLACE segment granularity, catalog rowsPerSegment, REPLACE time chunks, export file format) now use the new PlannerContext#setQueryContextParameter, which replaces the context with an overridden copy.
  • Added QueryContext#override(QueryContextParameter<T>, T). It, and the existing override(Map), now copy the context once instead of twice, and still keep keys sorted.
  • Removed the unused PlannerContext#addAllToQueryContext.

This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths.

Copilot AI balanced review requested due to automatic review settings October 19, 2026 03:13

This comment was marked as outdated.

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No actionable issues found in this review. The QueryContext override paths preserve sorted-key and null-removal behavior, and all four former planner-map writes now update the immutable context before later query/task construction.

Reviewed 6 of 6 changed files.

Validation: git diff --check 84e88bb46c68c59333f2aa55c343416c628ae1d0 b4ed0c4d73a5c0f9d8b2941008cf6f0085cbf89b passed; no tests or builds were run.


This is an automated review by Codex GPT-5.6-Luna(max)

@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Oct 19, 2026
@FrankChen021 FrankChen021 added this to the 40.0.0 milestone Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approval Recommended Used when AI completes a review and reports no findings Area - Querying

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants