You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
createtablet1 (id bigint, is_removed boolean, year int, status varchar(50), primary key (id));
/* execute query sql */
with main as (select*from t1 where is_removed = false),
min_not_submitted as (select id from main where status ='unsubmitted'order by year limit1),
max_submitted as (selectmax(id) id from main)
selectmain.id=min_not_submitted.idAS is_submit,
if(main.id=max_submitted.idandmain.status='submitted', true, false) as is_revoke
from main left join min_not_submitted on1=1left join max_submitted on1=1
2. What did you expect to see? (Required)
return with no error
3. What did you see instead (Required)
receive an unexcepted error
Query: with main as (select * from t1 where is_removed = false), min_not_submitted as (select id from main where status = 'unsubmitted'...
Error Code: 1105
Can't find column test.t1.id in schema Column: [test.t1.id,test.t1.status,Column#30] Unique key: []
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0.004 sec
if we transfer this sql into non-cte style, it still has problem.
SELECT
t1.id = min_not_submitted.id AS is_submit,
IF(t1.id = max_submitted.id AND t1.status = 'submitted', TRUE, FALSE) AS is_revoke
FROM
t1
LEFT JOIN (
SELECT id
FROM t1
WHERE is_removed = false AND status = 'unsubmitted'
ORDER BY year
LIMIT 1
) AS min_not_submitted ON 1=1
LEFT JOIN (
SELECT MAX(id) AS id
FROM t1
WHERE is_removed = false
) AS max_submitted ON 1=1
WHERE
t1.is_removed = false;
SELECT
t1.id = min_not_submitted.id AS is_submit
FROM
t1
LEFT JOIN (
SELECT id
FROM t1
ORDER BY year
) AS min_not_submitted ON 1=1
LEFT JOIN (
SELECT MAX(id) AS id
FROM t1
) AS max_submitted ON 1=1
func TestIssue59145(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
tk.MustExec("create table t1 (id bigint, is_removed boolean, year int, status varchar(50), primary key (id));")
tk.MustExec(`
SELECT
t1.id = min_not_submitted.id AS is_submit
FROM
t1
LEFT JOIN (
SELECT id
FROM t1
ORDER BY year
) AS min_not_submitted ON 1=1
LEFT JOIN (
SELECT MAX(id) AS id
FROM t1
) AS max_submitted ON 1=1
`)
}
Bug Report
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
return with no error
3. What did you see instead (Required)
receive an unexcepted error
the stack is:
BUT when I remove
order by
clause or replace order by field 'year' to 'id', the result is successful4. What is your TiDB version? (Required)
Release Version: v8.5.1
Edition: Community
Git Commit Hash: fea86c8
Git Branch: HEAD
UTC Build Time: 2025-01-16 07:38:34
GoVersion: go1.23.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv
The text was updated successfully, but these errors were encountered: