Skip to content

[4.2] Fix correlated scalar and grouped ENUM/SET conversions - #32841

Merged
XuPeng-SH merged 4 commits into
4.2-devfrom
codex/4.2-26030-32819-combined
Nov 17, 2026
Merged

XuPeng-SH merged 4 commits into
4.2-devfrom
codex/4.2-26030-32819-combined

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Fixes #32819
Related to #26030
Related to #28687

What this PR does / why we need it:

  • Normalize supported wrapped correlated scalar projections above the decorrelation join while preserving the match marker, NULL-on-empty behavior, and scalar cardinality semantics.
  • Reuse a flattened scalar only within the same expression and compatible binding context. Statement-stable functions such as NOW() and CURRENT_DATE() remain reusable; repeated varying or conditional mixed-correlated shapes fail closed instead of duplicating evaluation or mutating a shared subquery plan.
  • Preserve ENUM ordinal and SET bitmap provenance through grouped numeric expressions, using the existing conversion paths and rejecting non-reversible conversions.

Validation on host 57 with Go 1.26.4:

  • pkg/sql/plan normal and race tests passed.
  • Direct consumers pkg/sql/plan/function, pkg/sql/plan/rule, and pkg/sql/colexec/external passed.
  • Scalar correlated projection BVT passed 77/77 twice; grouped ENUM/SET numeric BVT passed 84/84 twice, with teardown verified after each run.
  • Incremental vet and lint passed; golangci-lint reported 0 issues. Molint reported five unchanged baseline checkrecover diagnostics.
  • gofmt and git diff --check passed.

Follow-up validation for statement-stable scalar reuse on macOS/arm64 with Go 1.26.4:

  • New regression tests failed at 61391b6066 for statement timestamp/date and nested timestamp reuse; the fix passes these cases while preserving rejection of RAND(), SYSDATE() and RANDOM_BYTES().
  • Full pkg/sql/plan tests passed. The extended scalar correlated projection BVT passed 89/89 twice, covering column-bound TRUE/FALSE/NULL results and repeated prepared execution; teardown was verified after each run.
  • Service build, vet, incremental golangci-lint (0 issues), gofmt and whitespace checks passed.

Scope boundary: nested no-FROM scalar numeric arithmetic still reproduces on the base branch and is not covered by these fixes.

@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner November 17, 2026 05:58
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 61391b6066f0943566567d502ea55c7661dc7382

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 61391b6066f0943566567d502ea55c7661dc7382

Assessment: request_changes

One reproduced regression remains: the new scalar stability guard rejects statement-stable NOW() subqueries. Otherwise, the implementation coherently reuses existing decorrelation, pagination, match-marker and ENUM/SET conversion owners.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

  • P2 pkg/sql/plan/flatten_subquery.go:259: SELECT (SELECT NOW()) BETWEEN lo AND hi FROM time_bounds, with TIMESTAMP column bounds containing the current date.
    Impact: Previously supported SQL now fails with error 20102. IsRealTimeRelated classifies statement-stable NOW() as varying, so BETWEEN's repeated scalar reference is rejected. Preserve statement-stable singleton results while retaining protection for genuinely varying expressions, and add regression coverage.
    Evidence: statement-stable-candidate.jsonl records the failure; the identical probe using all eight merge-base production files passes and returns 1 in statement-stable-baseline.jsonl. The plain NOW() control passes on both. Receipts: checks/1794897334126048261-2.json (candidate exit 1) and checks/1794897384133579979-2.json (baseline exit 0). builtInCurrentTimestamp reads the fixed statement timestamp through proc.GetUnixTime().

Validation:

  • Full planner and function suites passed: owners-test.jsonl; receipt 1794896858838305524-2.json.

  • Rule and external consumer suites passed: consumer-test.jsonl; receipt 1794897046115346589-2.json.

  • go vet passed for all four packages: vet.log; receipt 1794897208782855858-2.json.

  • Single-CN SQL probes passed for grouped numeric and lexical behavior, NULLs, cardinality, repeated BETWEEN, prepared parameters and intended rejection paths: sql-contract.jsonl; receipt 1794897004734707540-2.json.

  • Candidate/baseline SQL comparison confirmed the NOW regression. Complete discussion coverage, command receipts, retained logs and source fingerprints were reconciled in validation-audit.json.

  • Isolation preflight, fresh native build, formatting and whitespace checks passed. Frozen source remains unchanged.

Limitations:

  • Full distributed BVT and author-reported race/lint results were not independently verified; supplied local_validation contains no receipts. Live SQL validation used one CN.

@matrix-meow matrix-meow added size/XXL Denotes a PR that changes 2000+ lines and removed size/XL Denotes a PR that changes [1000, 1999] lines labels Nov 17, 2026
@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 5265c9c46cdf9d7b0cc07fcc002081cf6655cd4c

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mo-bot review · mo-bot-local · review

Commit: 5265c9c46cdf9d7b0cc07fcc002081cf6655cd4c

Assessment: approve

No actionable defect remains. Expression-local reuse coherently uses existing join and conversion owners. The NOW regression identified in review 5934103316 is resolved.

Model: gpt-6.1-sol / max

Session: 01a1e395-a6d9-7ad1-bf20-81f1c6210100 · slot 2 · generation 0

Validation:

  • Current pkg/sql/plan suite passed with three unchanged unrelated skips; receipt checks/1794902854914201276-2.json.

  • Isolated single-CN SQL probe passed statement-stable bounds, prepared executions, scalar cardinality/empty-input and ENUM/SET numeric/lexical checks; receipt checks/1794903006332394103-2.json.

  • Reconciled prior same-PR function, rule/external and vet evidence for unchanged coverage; retained in reuse-audit.json.

  • Preflight, formatting, whitespace, native provenance and clean-head audits passed. validation-audit.json matches receipts and retained logs; discussion-assessment.json covers all five discussion items.

Limitations:

  • Runtime SQL validation used one CN. Distributed BVT, race and lint claims were not independently verified.

  • Supplied CI evidence was pending.

@XuPeng-SH

XuPeng-SH commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · superseded

Commit: 9eea241e7f588971659e6e5fcbc2f73fcaebfdd9

PR closed or head changed

This branch was successfully deployed

No deployments
ci — 9eea241e Deployed Nov 17, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XXL Denotes a PR that changes 2000+ lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants