Skip to content

planner: fix deferred window subquery rewrite - #67203

Open
hawkingrei wants to merge 13 commits into
pingcap:masterfrom
hawkingrei:issue-67152-window-in-subquery
Open

hawkingrei wants to merge 13 commits into
pingcap:masterfrom
hawkingrei:issue-67152-window-in-subquery

Conversation

@hawkingrei

@hawkingrei hawkingrei commented Mar 22, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #67152

Problem Summary:

LAST_VALUE(...) OVER (...) IN (SELECT ...) is legal in the select list, but TiDB reports planner:3593 during planning.
The same window expression works with a constant IN (...) list, so the failure comes from the subquery rewrite path instead of window-function semantics.

What changed and how does it work?

resolveWindowFunction() needs to discover correlated outer columns for subqueries inside deferred window expressions.
Before this change, appendAuxiliaryFieldsForSubqueries() rewrote the whole IN (subquery) / compare-subquery wrapper during that discovery step.
That early rewrite visited the outer window expression before window outputs were materialized, so the legal window function fell into ErrWindowInvalidWindowFuncUse.

This PR changes that discovery path to build only the inner subquery plan with the corresponding subquery context.
That keeps correlated-column discovery intact while avoiding premature rewrites of the outer deferred window expression.

The regression test covers:

  • LAST_VALUE(...) OVER (...) IN (SELECT ...)
  • EXPLAIN FORMAT='brief' for the same query
  • a nearby compare-subquery variant: = ANY (SELECT ...)

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Fix planner error 3593 for window functions used as the left operand of an IN/ANY subquery in the select list.

Summary by CodeRabbit

  • Bug Fixes

    • Improved query planning for window functions used with correlated subqueries and comparisons (IN/EXISTS/=ANY), preserving planner state and ensuring stable, correct results.
  • Tests

    • Added and expanded tests covering window+subquery scenarios (including nested cases) and updated expected plan outputs for stability.

@ti-chi-bot ti-chi-bot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner labels Mar 22, 2026
@pantheon-ai

pantheon-ai Bot commented Mar 22, 2026 •

Copy link
Copy Markdown

Review Complete

Findings: 0 issues
Posted: 0
Duplicates/Skipped: 0

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 22, 2026
@coderabbitai

coderabbitai Bot commented Mar 22, 2026 •

Copy link
Copy Markdown

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Introduces a dedicated subquery plan builder that extracts subquery expressions, clones and builds their inner plans to discover correlated outer columns and inject auxiliary select fields; centralizes subquery enter/restore state handling; updates tests and expectations for window+subquery scenarios.

Changes

Cohort / File(s) Summary
Subquery plan helpers (new file)
pkg/planner/core/subquery_plan_builder.go
Adds subquery-specific helpers: subqueryExprExtractor, subqueryBuildState + PlanBuilder.enterSubqueryBuild, cloning/parsing of inner ResultSetNode, buildSubqueryPlanForAuxiliaryFields, appendAuxiliaryFieldsForSubqueries, and findColumnNameByUniqueID.
Plan builder refactor
pkg/planner/core/expression_rewriter.go, pkg/planner/core/logical_plan_builder.go
Refactors subquery build state handling to use enterSubqueryBuild; removes prior inline visitor/state logic from logical_plan_builder.go and delegates subquery auxiliary-field work to the new module.
Tests — behavior & expectations
pkg/planner/core/casetest/windows/window_with_exist_subquery_test.go, pkg/planner/core/casetest/windows/testdata/window_push_down_suite_out.json, pkg/planner/core/casetest/windows/testdata/window_push_down_suite_xut.json
Adds test cases reproducing/validating window+subquery scenarios (issue #67152); updates expected plan JSONs to reflect changed Column# identifiers and removes duplicated scalar-subquery lines.
Unit tests for PlanBuilder state
pkg/planner/core/planbuilder_test.go
Adds subtests ensuring buildSubqueryPlanForAuxiliaryFields and expression rewriter preserve PlanBuilder state; adds restoreNodeTextForTest and imports format.
Build update
pkg/planner/core/BUILD.bazel
Adds subquery_plan_builder.go to the core go_library srcs.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Planner
    participant PlanBuilder
    participant Parser
    participant CorrelationDetector

    Client->>Planner: Request plan for query with subquery-containing exprs
    Planner->>PlanBuilder: appendAuxiliaryFieldsForSubqueries(exprs, selectFields)
    PlanBuilder->>PlanBuilder: subqueryExprExtractor.collect(exprs)
    alt recognized subquery expr
        PlanBuilder->>Parser: restore & parse cloned inner ResultSetNode
        Parser-->>PlanBuilder: inner AST (ResultSetNode)
        PlanBuilder->>PlanBuilder: enterSubqueryBuild(snapshot outer scope)
        PlanBuilder->>PlanBuilder: buildResultSetNode(innerQuery)
        PlanBuilder-->>PlanBuilder: inner logical plan
        PlanBuilder->>CorrelationDetector: ExtractCorrelatedCols4LogicalPlan(innerPlan)
        CorrelationDetector-->>PlanBuilder: correlated outer column uniqueIDs
        PlanBuilder->>PlanBuilder: map uniqueIDs -> ast.ColumnName, append Auxiliary select fields
        PlanBuilder->>PlanBuilder: restore outer scope
    else fallback
        PlanBuilder->>PlanBuilder: b.rewrite(expr, true) to produce subquery plan
    end
    PlanBuilder-->>Planner: augmented selectFields / plan
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

size/XL, ok-to-test

Suggested reviewers

  • qw4990
  • AilinKid
  • winoros

Poem

🐰 I hopped through ASTs and cloned each nest,
I traced outer columns and gave them a guest.
Windows now hum with subqueries in tune,
Tests turn green beneath a silver moon.
Carrot cheers for the CI soon! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'planner: fix deferred window subquery rewrite' directly refers to the main change: a fix for the subquery rewrite path in window-function planning logic.
Description check ✅ Passed The PR description follows the template with Issue Number (close #67152), problem summary, detailed explanation of the change, completed test checklist, and release note provided.
Linked Issues check ✅ Passed The PR code changes directly address the linked issue #67152: they fix the planner error (3593) for window functions used as left operands of IN/ANY subqueries by refactoring auxiliary field discovery to avoid premature subquery rewrites.
Out of Scope Changes check ✅ Passed All changes are scoped to the window subquery rewrite fix: new subquery_plan_builder.go with auxiliary field handling, refactored expression_rewriter.go, updated testdata, and added regression tests for issue #67152.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@hawkingrei hawkingrei added the AI-Correction Bugfix by AI label Mar 22, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
pkg/planner/core/logical_plan_builder.go (1)

2644-2674: Consider sharing this subquery-state push/pop with expressionRewriter.buildSubquery().

This is now a second copy of the same outerSchemas / outerNames / outerBlockExpand / subQueryCtx / subQueryHintFlags / windowSpecs choreography from pkg/planner/core/expression_rewriter.go. Any future PlanBuilder state added to one path can easily be missed in the other. A small shared helper would make this logic much easier to audit.

As per coding guidelines, "Follow existing package-local conventions first and keep style consistent with nearby files."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/planner/core/logical_plan_builder.go` around lines 2644 - 2674, Extract
the duplicated subquery-state push/pop logic into a shared PlanBuilder helper
(e.g., PlanBuilder.pushSubqueryState or a small helper that returns a restore
function) and replace the copy in both logical_plan_builder.go and
expression_rewriter.go to call it; the helper should accept the subquery context
and the plan node (so it can detect LogicalJoin and pick FullSchema/FullNames),
perform the outerSchemas/outerNames cloning, append
outerBlockExpand/currentBlockExpand, save and set subQueryCtx, subQueryHintFlags
and windowSpecs, and return a closure or token that restores those fields
(popping outerSchemas/outerNames/outerBlockExpand, restoring currentBlockExpand,
windowSpecs, subQueryCtx and subQueryHintFlags) to be used in a defer in both
buildResultSetNode and expressionRewriter.buildSubquery.
pkg/planner/core/issuetest/planner_issue_test.go (1)

322-323: Consider adding .Check() to verify EXPLAIN output.

The EXPLAIN query runs without verifying the plan structure. While this is sufficient to confirm no ERROR 3593 is thrown (the main fix), other EXPLAIN tests in this file validate expected plan nodes. Adding a basic Check() would make the test more robust against future regressions in plan generation.

💡 Optional: Add basic plan verification
-		tk.MustQuery("explain format='brief' select /* issue:67152 explain */ last_value(a) over (order by a) in (select b from t) from t")
+		tk.MustQuery("explain format='brief' select /* issue:67152 explain */ last_value(a) over (order by a) in (select b from t) from t").
+			MultiCheckContain([]string{"Window", "HashJoin"})
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/planner/core/issuetest/planner_issue_test.go` around lines 322 - 323,
Replace the bare tk.MustQuery("explain format='brief' select /* issue:67152
explain */ last_value(a) over (order by a) in (select b from t) from t") with a
query assertion that calls .Check(...) on the returned result to verify the
EXPLAIN output contains the expected plan node(s); specifically, assert that the
brief EXPLAIN for the query containing last_value(a) over (order by a) includes
a "Window" (or "last_value") node string so the test validates the plan
structure as well as absence of ERROR 3593.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/planner/core/logical_plan_builder.go`:
- Around line 2626-2642: The subquery extractor currently only builds the RHS
subquery plan for CompareSubqueryExpr and PatternInExpr and then short-circuits,
which misses scalar subqueries nested on the non-subquery (left) side; update
the logic in subqueryExprExtractor so that when handling ast.CompareSubqueryExpr
and ast.PatternInExpr (the branches that set subq and sCtx to
handlingCompareSubquery/handlingInSubquery) you also recurse into or scan the
non-subquery operand to collect any nested subquery nodes (or call the existing
rewrite(ctx, expr, ...) path for that operand) before returning, ensuring outer
correlations (e.g., t.k) are discovered and included in the subquery plan
construction.

---

Nitpick comments:
In `@pkg/planner/core/issuetest/planner_issue_test.go`:
- Around line 322-323: Replace the bare tk.MustQuery("explain format='brief'
select /* issue:67152 explain */ last_value(a) over (order by a) in (select b
from t) from t") with a query assertion that calls .Check(...) on the returned
result to verify the EXPLAIN output contains the expected plan node(s);
specifically, assert that the brief EXPLAIN for the query containing
last_value(a) over (order by a) includes a "Window" (or "last_value") node
string so the test validates the plan structure as well as absence of ERROR
3593.

In `@pkg/planner/core/logical_plan_builder.go`:
- Around line 2644-2674: Extract the duplicated subquery-state push/pop logic
into a shared PlanBuilder helper (e.g., PlanBuilder.pushSubqueryState or a small
helper that returns a restore function) and replace the copy in both
logical_plan_builder.go and expression_rewriter.go to call it; the helper should
accept the subquery context and the plan node (so it can detect LogicalJoin and
pick FullSchema/FullNames), perform the outerSchemas/outerNames cloning, append
outerBlockExpand/currentBlockExpand, save and set subQueryCtx, subQueryHintFlags
and windowSpecs, and return a closure or token that restores those fields
(popping outerSchemas/outerNames/outerBlockExpand, restoring currentBlockExpand,
windowSpecs, subQueryCtx and subQueryHintFlags) to be used in a defer in both
buildResultSetNode and expressionRewriter.buildSubquery.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 15d252f7-dc7a-464f-ad4e-dd2829095a1e

📥 Commits

Reviewing files that changed from the base of the PR and between 3b531d4 and 5771bb6.

📒 Files selected for processing (2)
  • pkg/planner/core/issuetest/planner_issue_test.go
  • pkg/planner/core/logical_plan_builder.go

Comment thread pkg/planner/core/logical_plan_builder.go Outdated
@codecov

codecov Bot commented Mar 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.02198% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.5128%. Comparing base (8c2319e) to head (eafeabc).
⚠️ Report is 582 commits behind head on master.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #67203        +/-   ##
================================================
- Coverage   77.8088%   77.5128%   -0.2961%     
================================================
  Files          2023       1943        -80     
  Lines        556523     543665     -12858     
================================================
- Hits         433024     421410     -11614     
- Misses       121753     122252       +499     
+ Partials       1746          3      -1743     
Flag Coverage Δ
integration 40.9276% <45.0549%> (-7.1981%) ⬇️
unit 76.6885% <78.0219%> (+0.3052%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 61.5065% <ø> (ø)
parser ∅ <ø> (∅)
br 48.8710% <ø> (-11.9884%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/planner/core/logical_plan_builder.go`:
- Around line 2617-2684: The temporary subquery build in
buildSubqueryPlanForAuxiliaryFields runs buildResultSetNode but only restores a
subset of PlanBuilder state; snapshot and restore all mutable planner fields
touched by the probe (at minimum b.correlatedAggMapper, b.curClause,
b.skipAggMap-related state, and any other maps/lists that buildResultSetNode may
mutate such as handleHelper state) or perform the probe on an isolated
PlanBuilder clone (create a shallow copy or new PlanBuilder and run
buildResultSetNode there) so the outer builder state is unchanged; update the
defer block to restore the saved fields (or discard the cloned builder) and add
a regression unit test that exercises a correlated aggregate + inner HAVING
through this codepath to ensure no leakage.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cbb52e03-0420-4946-9227-10f865976124

📥 Commits

Reviewing files that changed from the base of the PR and between 5771bb6 and 789ab31.

📒 Files selected for processing (4)
  • pkg/planner/core/casetest/windows/testdata/window_push_down_suite_out.json
  • pkg/planner/core/casetest/windows/testdata/window_push_down_suite_xut.json
  • pkg/planner/core/casetest/windows/window_with_exist_subquery_test.go
  • pkg/planner/core/logical_plan_builder.go

Comment thread pkg/planner/core/logical_plan_builder.go Outdated
@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

@pantheon-ai pantheon-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Code looks good. No issues found.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot

@pantheon-ai

pantheon-ai Bot commented Mar 22, 2026 •

Copy link
Copy Markdown

⏳ @hawkingrei I've received your follow-up and will continue on this pull request. I'll update this comment when I have something to share.

ℹ️ Learn more details on Pantheon AI.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 22, 2026 •

Copy link
Copy Markdown

Review failed due to infrastructure/execution failure after retries. Please re-trigger review.

ℹ️ Learn more details on Pantheon AI.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

Comment thread pkg/planner/core/logical_plan_builder.go Outdated
@ti-chi-bot ti-chi-bot Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 24, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/planner/core/subquery_plan_builder.go (1)

159-175: Consider adding a brief comment explaining the cloning approach.

The serialize-reparse pattern is correct for this use case (where the cloned AST is only used for correlated column discovery and doesn't need the resolve context). A short comment would help future readers understand why a deep-clone utility wasn't used instead.

📝 Suggested documentation
+// cloneResultSetNodeForAuxiliaryFields creates a clone of the result set node by
+// serializing it to SQL and reparsing. This avoids the complexity of deep-cloning
+// AST nodes while providing a fresh copy that can be built without affecting the
+// original. The cloned AST lacks resolution context, which is acceptable since it's
+// only used for correlated outer-column discovery.
 func cloneResultSetNodeForAuxiliaryFields(ctx base.PlanContext, node ast.ResultSetNode) (ast.ResultSetNode, error) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/planner/core/subquery_plan_builder.go` around lines 159 - 175, Add a
short explanatory comment above cloneResultSetNodeForAuxiliaryFields describing
the chosen "serialize then reparse" cloning approach: note that the function
serializes the node with format.NewRestoreCtx and reparses it with
parser.New().ParseOneStmt because we only need a syntactic copy for
correlated-column discovery (no name-resolution or resolve context required), so
a full deep-clone utility or resolver-aware copy isn’t necessary; mention that
this approach intentionally drops resolver context and is acceptable for
auxiliary subqueries to avoid surprising future readers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/planner/core/subquery_plan_builder.go`:
- Around line 159-175: Add a short explanatory comment above
cloneResultSetNodeForAuxiliaryFields describing the chosen "serialize then
reparse" cloning approach: note that the function serializes the node with
format.NewRestoreCtx and reparses it with parser.New().ParseOneStmt because we
only need a syntactic copy for correlated-column discovery (no name-resolution
or resolve context required), so a full deep-clone utility or resolver-aware
copy isn’t necessary; mention that this approach intentionally drops resolver
context and is acceptable for auxiliary subqueries to avoid surprising future
readers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c2ceefa5-8923-4455-8765-389b0aec176c

📥 Commits

Reviewing files that changed from the base of the PR and between 329fed5 and 73381fc.

📒 Files selected for processing (5)
  • pkg/planner/core/BUILD.bazel
  • pkg/planner/core/expression_rewriter.go
  • pkg/planner/core/logical_plan_builder.go
  • pkg/planner/core/planbuilder_test.go
  • pkg/planner/core/subquery_plan_builder.go
💤 Files with no reviewable changes (1)
  • pkg/planner/core/logical_plan_builder.go
✅ Files skipped from review due to trivial changes (1)
  • pkg/planner/core/BUILD.bazel

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

Review completed with mixed results due to infrastructure constraints:

Execution Summary:

  • critical_review: Failed (timeout after 40+ min)
  • review_code: Failed (timeout after 40+ min)
  • review_agent_v1.1: Completed - NO_ISSUES found

Prior Review Finding (P2):
From the previous review session, a P2 issue was identified:

The subqueryExprExtractor.Enter() method returns (n, true) for PatternInExpr and CompareSubqueryExpr, setting skipChildren=true. This prevents AST traversal into LHS expressions (v.Expr for PatternInExpr, v.L for CompareSubqueryExpr). Since buildSubqueryPlanForAuxiliaryFields() only processes RHS subqueries, nested subqueries in the LHS would not have their correlated columns discovered.

Location: pkg/planner/core/logical_plan_builder.go lines ~2547-2565

Recommendation:
The author should verify that nested subqueries in the LHS of IN/Compare expressions within window functions are properly handled, or confirm this edge case is not applicable to the intended fix scope.

ℹ️ Learn more details on Pantheon AI.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

The master agent encountered an error while processing. Please try again later.

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 26, 2026
@ti-chi-bot ti-chi-bot Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 26, 2026
@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 27, 2026 •

Copy link
Copy Markdown

The master agent encountered an error while processing. Please try again later.

ℹ️ Learn more details on Pantheon AI.

@ti-chi-bot ti-chi-bot Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 30, 2026
@ti-chi-bot

ti-chi-bot Bot commented Mar 30, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign guo-shaoge for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hawkingrei

Copy link
Copy Markdown
Contributor Author

/retest

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

The master agent encountered an error while processing. Please try again later.

ℹ️ Learn more details on Pantheon AI.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

The master agent encountered an error while processing. Please try again later.

ℹ️ Learn more details on Pantheon AI.

@hawkingrei
hawkingrei requested a review from qw4990 March 31, 2026 04:53
@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

The master agent encountered an error while processing. Please try again later.

ℹ️ Learn more details on Pantheon AI.

@Mini256

Mini256 commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Mar 31, 2026 •

Copy link
Copy Markdown

Review failed due to infrastructure/execution failure after retries. Please re-trigger review.

ℹ️ Learn more details on Pantheon AI.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Apr 1, 2026 •

Copy link
Copy Markdown

⏳ @hawkingrei I've received your follow-up and will continue on this pull request. I'll update this comment when I have something to share.

ℹ️ Learn more details on Pantheon AI.

@hawkingrei

Copy link
Copy Markdown
Contributor Author

@pantheon-bot review

@pantheon-ai

pantheon-ai Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

Review Complete

Findings: 0 issues
Posted: 0
Duplicates/Skipped: 0

ℹ️ Learn more details on Pantheon AI.

Comment on lines +194 to +197
rewriter := &expressionRewriter{
schema: outerSchema,
names: outerNames,
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We'd better use the getExpressionRewriter to reuse the pool.

Comment on lines +121 to +129
var sb strings.Builder
restoreCtx := format.NewRestoreCtx(format.DefaultRestoreFlags, &sb)
if err := node.Restore(restoreCtx); err != nil {
return nil, err
}
charset, collation := ctx.GetSessionVars().GetCharsetInfo()
p := parserutil.GetParser()
defer parserutil.DestroyParser(p)
stmt, err := p.ParseOneStmt(sb.String(), charset, collation)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we need to restore it first, then parse it again?
This seems buggy and costly.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI-Correction Bugfix by AI ok-to-test Indicates a PR is ready to be tested. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/planner SIG: Planner size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ERROR 3593 when a window function is used as the left operand of an IN subquery within the SELECT list

3 participants