Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
- MatrixOne was built from the commit above and started locally with etc/launch/launch.toml.
- MySQL comparison version: 8.0.45.
- Every query was repeated three times with the same result.Actual Behavior
MatrixOne rejects scalar subqueries in the value expressions of both
REPLACE ... SET and REPLACE ... VALUES:
REPLACE ... SET: subquery in replace set value is not yet implemented
REPLACE ... VALUES: subquery in JOIN condition is not yet implemented
Preparing REPLACE ... SET with a scalar subquery is rejected by the same
replace set value binder guard before the prepared statement is created.
This restriction is specific to the value-binding paths. The following nearby
forms already work in MatrixOne and produce the same rows as MySQL:
REPLACE ... SETwith literal expressions;REPLACE ... SELECT;REPLACE ... SELECTwhose SELECT list contains a scalar subquery.
Expected Behavior
MatrixOne should accept scalar subqueries in REPLACE ... SET and
REPLACE ... VALUES, as MySQL 8.0.45 does. With the sample data below,
MAX(source_t.v) is 404, so both statements should replace row id=1 with
v=404. The prepared statement with @p=2 should use v=202.
Steps to Reproduce
CREATE DATABASE codex_replace_subquery_0907;
USE codex_replace_subquery_0907;
CREATE TABLE target_t (
id INT PRIMARY KEY,
v INT,
note VARCHAR(40)
);
CREATE TABLE source_t (
id INT PRIMARY KEY,
v INT
);
INSERT INTO target_t VALUES
(1,10,'one'),(2,20,'two'),(3,30,'three');
INSERT INTO source_t VALUES
(1,101),(2,202),(4,404);
-- Control: supported.
REPLACE INTO target_t SET id=1, v=99, note='literal';
-- Scalar subquery in SET value.
REPLACE INTO target_t
SET id=1,
v=(SELECT MAX(v) FROM source_t),
note='set-subquery';
-- Scalar subquery in VALUES value.
REPLACE INTO target_t(id,v,note)
VALUES(1,(SELECT MAX(v) FROM source_t),'values-subquery');
-- Control: the SELECT form, including a nested scalar subquery, is supported.
REPLACE INTO target_t(id,v,note)
SELECT id,(SELECT MAX(v) FROM source_t),'nested-select'
FROM source_t
WHERE id=2;
-- The SET form is also rejected during PREPARE.
PREPARE ps_replace FROM
'REPLACE INTO target_t
SET id=1,
v=(SELECT MAX(v) FROM source_t WHERE id<=?),
note="prepared"';
SET @p=2;
EXECUTE ps_replace USING @p;Additional information
The REPLACE ... SET rejection is explicit in
pkg/sql/plan/replace_value_binder.go. The VALUES form reaches a different
binder and reports an unrelated subquery in JOIN condition NYI message.
Activity
fix(plan): support scalar subqueries in REPLACE values (#28335)
Ariznawlll commentedon Sep 9, 2026
测试版本
maine8ae1e51f2b0f04b6d69d37ff6ccf8166736c9e6127.0.0.1:6001原问题验证
在目标表和两行源表上执行
REPLACE INTO ... VALUES (...,(SELECT MAX(v) ...))、REPLACE ... SET以及带参数的 PREPARE/EXECUTE。三轮均不再报“unsupported subquery”,结果分别写入(1,20)、(2,10)、(3,20)。Happy Path 覆盖
Unhappy Path 覆盖
ERROR 1242: Subquery returns more than 1 row。白盒验证
go test ./pkg/tests/issues -run '^TestIssue28299ReplaceValuesOrder$'连续 3 轮通过;其中使用独立故障点验证后到达 VALUES 分支先完成时仍保持 SQL 文本顺序。回归测试
issue_28299_replace_scalar_subquery.test已加入 PR paritial data type #152;录制后连续 3 轮通过(每轮 17 条 SQL 断言)。测试证据
156c477b1d8757b1de4f5784532b5ddd75d8744e。测试结论
测试通过。
fix(plan): support scalar subqueries in REPLACE values (matrixorigin#…
fix(plan): support scalar subqueries in REPLACE values (matrixorigin#…
fix(plan): support scalar subqueries in REPLACE values (matrixorigin#…