Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL fails with error Subquery returns more than 1 row #30433

Open
wshwsh12 opened this issue Dec 6, 2021 · 7 comments
Open

SQL fails with error Subquery returns more than 1 row #30433

wshwsh12 opened this issue Dec 6, 2021 · 7 comments

Comments

@wshwsh12
Copy link
Contributor

wshwsh12 commented Dec 6, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Same environment with #30326

tidb/bin/tidb-server &
mysql -h "127.0.0.1" -u root -P 4000 -D testdb < mysql_bk.sql

mysql_bk.sql: mysql_bk.sql.txt

Run the following sql:

select
    (
        select
            c4
        from
            t_cpsvpb
    ) as c7
from
    (
        select
            ref_0.c_13sfid as c0
        from
            t_x7zqmd as ref_0
        where
            0 <> 0
    ) as subq_0;

2. What did you expect to see? (Required)

Empty set (0.001 sec)

3. What did you see instead (Required)

ERROR 1242 (21000): Subquery returns more than 1 row

4. What is your TiDB version? (Required)

4.0,5.0,5.1,5.2,5.3, master

@wshwsh12 wshwsh12 added the type/bug The issue is confirmed as a bug. label Dec 6, 2021
@wshwsh12 wshwsh12 added affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. labels Dec 6, 2021
@wshwsh12
Copy link
Contributor Author

wshwsh12 commented Dec 6, 2021

Another case:

drop table t; 
drop table empty_table;
create table t(a int);
insert into t values(1),(2);
create table empty_table(a int);
select 
    (select a as a3 from t) 
from (
    select a as a2 from empty_table
) as subq_1;

TiDB: ERROR 1242 (21000): Subquery returns more than 1 row
Mysql: Empty set (0.001 sec)

@sylzd
Copy link
Contributor

sylzd commented Dec 6, 2021

/assign

@sylzd
Copy link
Contributor

sylzd commented Dec 7, 2021

/type compatibility

@sylzd
Copy link
Contributor

sylzd commented Dec 7, 2021

  • the case can be simplified further
select      (select a as a3 from t)  from empty_table;
  • the reason is:

error ERROR 1242 (21000): Subquery returns more than 1 row is returned at preprocessing(rewriteWithPreprocess) and (expressionRewriter).handleScalarSubquery.
I'm thinking about how to know if the subQuery or table is empty at preprocessing stage. 🤔 Besides, is it really a bug? I think the result of tidb is reasonable, and it's a compatibility issue.

@XuHuaiyu XuHuaiyu added sig/planner SIG: Planner and removed sig/execution SIG execution labels Dec 14, 2021
@yudongusa
Copy link

@winoros this seems to be a candidate of subq rewrite refactor feature.

@winoros
Copy link
Member

winoros commented Dec 15, 2021

@winoros this seems to be a candidate of subq rewrite refactor feature.

yes, this is an issue about how we deal with the subquery in the rewriting/resolving phase.
I use another issue to track it.
Remove the bug label, use the compatibility label instead.

@winoros
Copy link
Member

winoros commented Dec 15, 2021

It's not a one that can be easily backported.
So we also remove the affects-* label.
This would be re-considered when we implement this feature.

@winoros winoros removed type/bug The issue is confirmed as a bug. severity/major affects-4.0 This bug affects 4.0.x versions. affects-5.0 This bug affects 5.0.x versions. affects-5.1 This bug affects 5.1.x versions. affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. labels Dec 15, 2021
@sylzd sylzd removed their assignment Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants