docs/agents/planner/window_subquery_notes.md
Background:
unknown column failure for correlated scalar subqueries nested inside window expressions.*ast.SubqueryExpr with asScalar=true, even when the user SQL was an IN, ANY, or ALL subquery.Root cause:
WINDOW specs, and related ORDER BY items.*ast.SubqueryExpr nodes and rewrote them through the scalar-subquery path only to collect correlated outer columns.MaxOneRow,EvalSubqueryFirstRow,IN / ANY / ALL subqueries can therefore fail with ERROR 1242 (21000): Subquery returns more than 1 row.Implementation choice:
appendAuxiliaryFieldsForSubqueries.*ast.SubqueryExpr.*ast.SubqueryExpr,*ast.ExistsSubqueryExpr,*ast.CompareSubqueryExpr,*ast.PatternInExpr when Sel != nil.EXISTS, IN, quantified compare, or scalar) while still exposing correlated outer columns from the resulting logical plan.Regression coverage:
EXISTS subqueries,USING / NATURAL JOIN outer-column lookup through FullSchema.TestWindowSubqueryRewrite adds direct coverage for valid multi-row non-scalar subqueries inside window expressions:
count(1 in (select t2.c1 from t2)) over ()count(1 = any (select t2.c1 from t2)) over ()Validation commands:
make failpoint-enablego test -run 'TestWindowSubqueryRewrite|TestWindowSubqueryOuterRef' -tags=intest,deadlock ./pkg/planner/core/casetest/windowsmake failpoint-disablemake lintDebugging takeaway: