Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
The closest match is #26816, but it describes LIMIT being applied globally across outer groups and returning incorrect rows. This report is a different, still-reproducible shape: a root LIMIT 0 on a correlated scalar subquery whose projection references an outer column is rejected instead of producing an empty scalar result. No open issue with the current error or this exact behavior was found.
Branch Name
main
Also reproduced on 4.2-dev and v4.2.8.
Commit ID
1064837ae2648aa20e5e1abb7edd0564493e6b4d (local main used for this report)
Additional verified revisions:
4.2-dev:7400cae392e90fa94b8cf54dc8520c3c136478844.2-devpre-[4.2] Fix correlated scalar and grouped ENUM/SET conversions #32841 baseline:dcf39656af283d3d55222470b3b223587b2c46aav4.2.8:10d204b8763f19b2b37ba2147d1d4c1a7828d6d4
Other Environment Information
- Hardware parameters: macOS arm64
- OS type: macOS
- Others: standalone local
mo-service, 1 CN / 1 TN / 1 Log service, MySQL text protocol; no unit tests involved
Actual Behavior
A correlated scalar subquery with root LIMIT 0 fails when its result expression references an outer column.
On the reported main revision, both reproduction queries fail with:
ERROR 20102 (HY000): wrapped correlated scalar projection cannot be safely decorrelated is not yet implemented
The error text differs by revision:
4.2-dev@7400cae: the filtered form reportscorrelated pagination across nested boundaries or correlated expressions is not yet implemented; the unfiltered form reports an unsupported correlated expression executor error.v4.2.8@10d204b: both forms report an unsupported correlated expression executor error.
The same failure is present before and after #32841, so this is not being reported as a regression introduced by that PR.
Expected Behavior
Both queries should return one row per outer row, with NULL for the scalar result:
a x
1 NULL
11 NULL
LIMIT 0 makes the inner query empty. An empty scalar subquery should evaluate to NULL; the outer projection must not be evaluated for a nonexistent inner row.
Steps to Reproduce
DROP DATABASE IF EXISTS correlated_limit_zero;
CREATE DATABASE correlated_limit_zero;
USE correlated_limit_zero;
CREATE TABLE t1(a INT);
CREATE TABLE t2(d INT);
INSERT INTO t1 VALUES (1), (11);
INSERT INTO t2 VALUES (4);
-- Fails on main, 4.2-dev, and v4.2.8.
SELECT a,
(SELECT a FROM t2 WHERE d > a LIMIT 0) AS x
FROM t1
ORDER BY a;
-- Also fails on all three revisions.
SELECT a,
(SELECT a FROM t2 LIMIT 0) AS x
FROM t1
ORDER BY a;Controls that work and isolate the failure to an outer-reference scalar projection:
-- LIMIT 1 works: returns (1, 1), (11, NULL).
SELECT a,
(SELECT a FROM t2 WHERE d > a LIMIT 1) AS x
FROM t1 ORDER BY a;
-- A constant correlated projection works and returns NULL for both rows.
SELECT a,
(SELECT 1 FROM t2 WHERE d > a LIMIT 0) AS x
FROM t1 ORDER BY a;
-- A truly uncorrelated scalar works and returns NULL for both rows.
SELECT a,
(SELECT d FROM t2 LIMIT 0) AS x
FROM t1 ORDER BY a;
-- Correlated EXISTS and IN with LIMIT 0 also work and return false.
SELECT a, EXISTS(SELECT 1 FROM t2 WHERE d > a LIMIT 0) AS x
FROM t1 ORDER BY a;
SELECT a, a IN(SELECT d FROM t2 WHERE d > a LIMIT 0) AS x
FROM t1 ORDER BY a;Additional information
On 4.2-dev, pkg/sql/plan/correlated_pagination.go explicitly treats a semantic-root LIMIT 0 as making the whole subquery empty. The observed failure is therefore inconsistent with the intended empty-subquery handling.
Related closed issue: #26816. Its verification covered correlated LIMIT 1 global-group semantics and some LIMIT 0 cases, but the outer-reference projection shapes above remain broken on the revisions listed here.
Activity
Fix correlated scalar subquery with LIMIT 0 (#32871)
[4.2-dev] Fix correlated scalar subquery with LIMIT 0 (#32870)
XuPeng-SH commentedon Nov 23, 2026
转测:本单的两个普通表相关标量子查询
LIMIT 0原始场景已有两个分支修复:#32871 合入main(46079446),#32870 合入4.2-dev(5245da02)。4.2-dev合入树与c63d7e6f相同,该版本 Required 和双路多 CN BVT 通过;另有复核的单 CN MySQL 协议及作者定向 BVT 记录。main合入树同6f199d83,有作者 SQL/BVT 记录,但最终 head 的 Required 未通过,不当作全套 CI 已通过。请在两个合入版本分别复跑原有带/不带
WHERE的查询,核每个外层行返回有类型的 SQL NULL,正向LIMIT 1及EXISTS/IN对照不回归;同时核max_dop=1、保存结果表元数据和受限角色按原规则拒绝。#33056 的旧有 untyped-NULL 排序问题和 #33057 的特殊result_scan支持另行跟踪,不在本次验收范围。未验证已发布 4.2.8 或生产部署;本次是交接,不是正式验收。slyunnn commentedon Nov 23, 2026
Regression and extended verification for #32869 (2026-11-23)
Fixed for the reported ordinary-table SELECT shapes on main and 4.2-dev. Branch-specific PREPARE/CTAS boundaries are retained and stated below.
Verification Environment
Both latest remote refs were fetched before validation and checked in separate clean source directories:
main@f86cc46cfc5d5e4a0e2e52af6e4cbd58f9f9c449—refactor(vector): remove the grouping bitmap (gsp) from Vector (#33020) (#33075), built with Go1.27.1/GOEXPERIMENT=simd.4.2-dev@f811a8673b44f592e5f60db10843de119d662e89—fix(tae): bound catalog replay input memory (#33078), built with Go1.26.5.Each branch independently ran a native
2 CN / 1 TN / 1 Log service / Proxytopology, sequentially on Proxy6001, CN116001, CN216002. All three endpoints actually executed the SQL and protocol regressions, returned the expected version prefix (f86cc46cfc/f811a8673b), and passed post-error/post-test health checks. These are regression executions, not just connectivity checks. Clients used MySQL text SQL plus explicit Go MySQL-driver binary prepared operations.The main binary embeds full VCS revision and
vcs.modified=false; SHA-256 is97d9d4e683f65642f02462a2b595451f391ede9795e425a078faeec07ef4a71b. The 4.2 binary SHA-256 isd04bf3f98db223e68fbf9b59ce96e6b67a59f82d5954e01e3acba585b64ec990. Go1.26.5did not emit optional VCS stamps for that build: identity was corroborated by the clean full-SHA checkout, retained build command with the embedded commit prefix, new binary hash and runtime version checks at all three endpoints. No service source, existing binaries, Docker configuration or old data was modified. The local 4.2 ONNX download and macOS library-search-path setup issues were repaired before acceptance; their failed setup attempts are not product failures.What Was Covered
WHERE d > a, return(1,NULL)and(11,NULL); the scalar's wire type isINT, not an untyped NULL placeholder.LIMIT 0 OFFSET 1, arithmetic correlation, a discarded invalid-value projection,LIMIT 1, constant/uncorrelated scalar,EXISTS,IN, nested empty-inputCOUNT, andmax_dop=1controls.20checks per endpoint.20102) and affected CTAS/function-wrapper refusal (20102), with positive binary preparedLIMIT 1rebinding. This is its existing planner contract, not a claim of main/4.2 feature parity. The protocol script performs22checks per endpoint.META_SCANexcludes the detached wrapper from executable table metadata. The persisted authorization closure still requires that wrapper's table privilege: ordinary table/root-zero and saved-result queries are denied with20101before necessary grants and succeed afterward. The original scalar result retains its type.20101for the restricted role after both ordinary tables are granted. Main also retains its tested control-call denial. No broad equivalence claim is made for other uncorrelated/dead-control-call forms.2/2cases,39/39runner statements. Independently on 4.2-dev, each endpoint passed2/2cases,38/38statements. All final recording/replay groups had0failures and0skips; internal protocol counts are separate from the runner's one script statement.9/9branch-targeting checks on the independent 4.2 branch and the integrated daily branch; integrated four-case replay with existing [Bug]: 4.2-dev Sysbench random_points TPS 下降 84%,二分指向 PR #32878(待隔离复验) #32965 passed4/4cases and62/62statements.v4.2.8or production deployments. The separately tracked untyped-NULL sorting ([Bug]: ORDER BY a view with untyped correlated LIMIT 0 NULL panics in vector.Shuffle #33056) and special wrappedresult_scansources ([Feature Request]: Support folded result_scan sources in correlated scalar LIMIT 0 wrappers #33057) are outside this acceptance; direct typed saved-result reads and authorization are covered.Findings
main repair #32871,
Fix correlated scalar subquery with LIMIT 0, merged as46079446d00d40e1cef91e653378ff49c52a5895, final head6f199d837fd838348ff67c0d16e2ec22e5de5946. 4.2-dev repair #32870,[4.2-dev] Fix correlated scalar subquery with LIMIT 0, merged as5245da02028eeea2174c7d5b09b20584176834ab, final headc63d7e6fa0f8f781f533bf7eb7b5b9c1c0a2e6c2. Separate ancestor checks confirm inclusion in each tested branch.The reported root
LIMIT 0SELECTs now produce an empty scalar result without evaluating the discarded outer-reference projection. Catalog/authorization dependencies survive folding; detached metadata does not interfere with the testedmax_dop=1execution and saved-result table listing.The branch contracts differ. Main supports the tested correlated-zero prepared queries and typed CTAS control; 4.2 intentionally fails closed for those prepared/wrapped shapes. These were first observed as extension mismatches and then checked against the 4.2 source and existing PREPARE guard test; the results are not described as equivalent support. Plain direct CTAS is also a recorded unsupported boundary on main. This conclusion covers the reported ordinary-table SELECT bug, not every correlated-subquery form.
Large-data regression is not required for this planner/empty-scalar defect. The original two-row fixture plus duplicate/NULL/empty and type/privilege controls directly cover the relevant semantic boundary. Both same-version CN endpoints were exercised; no engine-parallelism claim is inferred from MOTR scheduling.
MOTR / BVT Coverage
1ea137a2cc09508fd1d6fe29b670143ed46e346c; branchtest/issue-32869-scalar-limit-zero-main; single source commitaeb3533ddccfc13d90deba23132c87fa03e71eaa, daily cherry-pick0733ee6881f1b1953ed774dd1edeadb238cfc31cin main daily PR #382.7ee76c16f9bac6fdb65939d56c997344474791bb; branchtest/issue-32869-scalar-limit-zero-4.2-dev; single source commite37179ca79f4adf3927db334c33523a7ad5f7fff, daily cherry-pick6454a7ad45e00ccc9ab4dad4d85b0b0b7fe4d702in 4.2-dev daily PR #381.Each issue branch has one
test: add MOTR regression for #32869commit, independently recorded branch-appropriate SQL/protocol goldens and environment-configurable Go/sh protocol coverage. The independent 4.2 discovery count is562; the daily count is564after preserving #32965's two cases. PRs are authored byslyunnn. No per-issue MOTR PR was created. Fixtures and endpoint runs were serial (-j 1) because role and database lifecycle ownership is shared within the group.Final Conclusion
Fixed for the two reported ordinary-table correlated scalar
LIMIT 0SELECT shapes on both tested maintenance branches. The stated 4.2 PREPARE/wrapper restrictions remain intentional unsupported boundaries. Keep #32869 open and add the user-requestedcloselabel; no issue-state transition is requested.