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

Panic triggered at expression.ExplainExpressionList (planner/core/explain.go:335) #42587

Closed
JZuming opened this issue Mar 25, 2023 · 10 comments
Closed
Assignees
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@JZuming
Copy link

JZuming commented Mar 25, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Setup the environment:

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

mysql_bk.sql: mysql_bk.txt

Testcase

select  
  ref_39.c17 as c0
from 
  (t1 as ref_39
    left outer join t2 as ref_40
    on (ref_39.c13 = ref_40.vkey ))
where (case when exists (
              select  
                  ref_73.c9 as c0
                from 
                  t1 as ref_73
                union
                select  
                  null + 83 as c0
                from 
                  t6 as ref_77
                where (ref_40.pkey = null) and (2 > ( 
                  select 1 as c0
                    from 
                      t1 as ref_85
                    where exists (
                                select  
                                  ref_103.c25 as c0
                                from 
                                  t3 as ref_103
                                where ref_85.c13 = ref_103.c25 
                                ) 
                      limit 1
                  ))
                )  then null else 1 end
    ) >= 1;

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

No panic.

3. What did you see instead (Required)

ERROR 1105 (HY000): runtime error: index out of range [0] with length 0

Log of TiDB server:

[ERROR] [conn.go:1039] ["connection running loop panic"] [conn=2199023260581] [lastSQL="select  
      ref_39.c17 as c0
    from 
      (t1 as ref_39
        left outer join t2 as ref_40
        on (ref_39.c13 = ref_40.vkey ))
    where (case when exists (
                  select  
                      ref_73.c9 as c0
                    from 
                      t1 as ref_73
                    union
                    select  
                      null + 83 as c0
                    from 
                      t6 as ref_77
                    where (ref_40.pkey = null) and (2 > ( 
                      select 1 as c0
                        from 
                          t1 as ref_85
                        where exists (
                                    select  
                                      ref_103.c25 as c0
                                    from 
                                      t3 as ref_103
                                    where ref_85.c13 = ref_103.c25 
                                   ) 
                         limit 1
                      ))
                   )  then null else 1 end
        ) >= 1"] [err="runtime error: index out of range [0] with length 0"] [stack="github.com/pingcap/tidb/server.(*clientConn).Run.func1
    /root/tidb/server/conn.go:1042
runtime.gopanic
    /usr/local/go/src/runtime/panic.go:884
runtime.goPanicIndex
    /usr/local/go/src/runtime/panic.go:113
github.com/pingcap/tidb/expression.ExplainExpressionList
    /root/tidb/expression/explain.go:122
github.com/pingcap/tidb/planner/core.(*PhysicalProjection).ExplainInfo
    /root/tidb/planner/core/explain.go:335
github.com/pingcap/tidb/planner/core.(*Explain).getOperatorInfo
    /root/tidb/planner/core/common_plans.go:1138
github.com/pingcap/tidb/planner/core.(*Explain).prepareOperatorInfo
    /root/tidb/planner/core/common_plans.go:1051
github.com/pingcap/tidb/planner/core.(*Explain).explainFlatOpInRowFormat
    /root/tidb/planner/core/common_plans.go:987
github.com/pingcap/tidb/planner/core.(*Explain).explainFlatPlanInRowFormat
    /root/tidb/planner/core/common_plans.go:936
github.com/pingcap/tidb/planner/core.(*Explain).RenderResult
    /root/tidb/planner/core/common_plans.go:888
github.com/pingcap/tidb/planner/core.GetExplainRowsForPlan
    /root/tidb/planner/core/common_plans.go:761
github.com/pingcap/tidb/session.(*session).SetProcessInfo
    /root/tidb/session/session.go:1545
github.com/pingcap/tidb/server.(*clientConn).dispatch.func2
    /root/tidb/server/conn.go:1297
runtime.gopanic
    /usr/local/go/src/runtime/panic.go:890
github.com/pingcap/tidb/executor.(*ExecStmt).Exec.func1
    /root/tidb/executor/adapter.go:459
runtime.gopanic
    /usr/local/go/src/runtime/panic.go:884
runtime.goPanicIndex
    /usr/local/go/src/runtime/panic.go:113
github.com/pingcap/tidb/expression.ExplainExpressionList
    /root/tidb/expression/explain.go:122
github.com/pingcap/tidb/planner/core.(*PhysicalProjection).ExplainInfo
    /root/tidb/planner/core/explain.go:335
github.com/pingcap/tidb/planner/core.(*Explain).getOperatorInfo
    /root/tidb/planner/core/common_plans.go:1138
github.com/pingcap/tidb/planner/core.(*Explain).prepareOperatorInfo
    /root/tidb/planner/core/common_plans.go:1051
github.com/pingcap/tidb/planner/core.(*Explain).explainFlatOpInRowFormat
    /root/tidb/planner/core/common_plans.go:987
github.com/pingcap/tidb/planner/core.(*Explain).explainFlatPlanInRowFormat
    /root/tidb/planner/core/common_plans.go:936
github.com/pingcap/tidb/planner/core.(*Explain).RenderResult
    /root/tidb/planner/core/common_plans.go:888
github.com/pingcap/tidb/planner/core.GetExplainRowsForPlan
    /root/tidb/planner/core/common_plans.go:761
github.com/pingcap/tidb/session.(*session).SetProcessInfo
    /root/tidb/session/session.go:1545
github.com/pingcap/tidb/executor.(*ExecStmt).Exec
    /root/tidb/executor/adapter.go:553
github.com/pingcap/tidb/session.runStmt
    /root/tidb/session/session.go:2332
github.com/pingcap/tidb/session.(*session).ExecuteStmt
    /root/tidb/session/session.go:2189
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt
    /root/tidb/server/driver_tidb.go:252
github.com/pingcap/tidb/server.(*clientConn).handleStmt
    /root/tidb/server/conn.go:2054
github.com/pingcap/tidb/server.(*clientConn).handleQuery
    /root/tidb/server/conn.go:1851
github.com/pingcap/tidb/server.(*clientConn).dispatch
    /root/tidb/server/conn.go:1337
github.com/pingcap/tidb/server.(*clientConn).Run
    /root/tidb/server/conn.go:1120
github.com/pingcap/tidb/server.(*Server).onConn
    /root/tidb/server/server.go:675"]

4. What is your TiDB version? (Required)

+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.1.0-alpha-27-gf5ca27ef3
Edition: Community
Git Commit Hash: f5ca27e
Git Branch: master
UTC Build Time: 2023-03-23 13:57:53
GoVersion: go1.20.2
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

@JZuming JZuming added the type/bug The issue is confirmed as a bug. label Mar 25, 2023
@JZuming JZuming changed the title "Runtime error: index out of range [0] with length 0" triggered at expression.ExplainExpressionList (planner/core/explain.go:335) Panic triggered at expression.ExplainExpressionList (planner/core/explain.go:335) Mar 25, 2023
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 may-affects-6.5 labels Mar 28, 2023
@VelocityLight VelocityLight added the affects-7.1 This bug affects the 7.1.x(LTS) versions. label Apr 20, 2023
@ti-chi-bot ti-chi-bot added the affects-7.5 This bug affects the 7.5.x(LTS) versions. label Oct 23, 2023
@Rustin170506 Rustin170506 moved this to 📋 Backlog in 🎒My Work Feb 21, 2024
@ti-chi-bot ti-chi-bot added the affects-8.1 This bug affects the 8.1.x(LTS) versions. label Apr 9, 2024
@Rustin170506 Rustin170506 moved this from 📋 Backlog to 🏊WIP in 🎒My Work May 6, 2024
@Rustin170506
Copy link
Member

I tested it locally, it has been fixed since v7.2.0.

@Rustin170506
Copy link
Member

This issue was accidentally fixed by #44164.

So we still encounter the same issue after disabling tidb_remove_orderby_in_subquery.

I'm not sure if it's worth fixing because we enabled it since v7.2.0. I will discuss it with the team this week.

@Rustin170506
Copy link
Member

The panic happened here:

builder.WriteString(schema.Columns[i].String())

@Rustin170506
Copy link
Member

Rustin170506 commented May 6, 2024

The stack looks like this:

[2024/05/06 15:35:10.395 +08:00] [ERROR] [conn.go:1013] ["connection running loop panic"] [conn=3231711242] [session_alias=] [lastSQL="select     ref_39.c17 as c0 from    (t1 as ref_39     left outer join t2 as ref_40     on (ref_39.c13 = ref_40.vkey )) where (case when exists (               select                     ref_73.c9 as c0                 from                    t1 as ref_73                 union                 select                     null + 83 as c0                 from                    t6 as ref_77                 where (ref_40.pkey = null) and (2 > (                    select 1 as c0                     from                        t1 as ref_85                     where exists (                                 select                                     ref_103.c25 as c0                                 from                                    t3 as ref_103                                 where ref_85.c13 = ref_103.c25                                  )                        limit 1                   ))                 )  then null else 1 end     ) >= 1"] [err="runtime error: index out of range [0] with length 0"] [stack="github.com/pingcap/tidb/pkg/server.(*clientConn).Run.func1\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1016\nruntime.gopanic\n\t/usr/local/go1.21/src/runtime/panic.go:914\nruntime.goPanicIndex\n\t/usr/local/go1.21/src/runtime/panic.go:114\ngithub.com/pingcap/tidb/pkg/expression.ExplainExpressionList\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/expression/explain.go:176\ngithub.com/pingcap/tidb/pkg/planner/core.(*PhysicalProjection).ExplainInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/explain.go:377\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).getOperatorInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1169\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).prepareOperatorInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1083\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatOpInRowFormat\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1019\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatPlanInRowFormat\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:960\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).RenderResult\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:912\ngithub.com/pingcap/tidb/pkg/planner/core.GetExplainRowsForPlan\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:783\ngithub.com/pingcap/tidb/pkg/session.(*session).SetProcessInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:1422\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).dispatch.func2\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1306\nruntime.gopanic\n\t/usr/local/go1.21/src/runtime/panic.go:920\ngithub.com/pingcap/tidb/pkg/executor.(*ExecStmt).Exec.func1\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/executor/adapter.go:451\nruntime.gopanic\n\t/usr/local/go1.21/src/runtime/panic.go:914\nruntime.goPanicIndex\n\t/usr/local/go1.21/src/runtime/panic.go:114\ngithub.com/pingcap/tidb/pkg/expression.ExplainExpressionList\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/expression/explain.go:176\ngithub.com/pingcap/tidb/pkg/planner/core.(*PhysicalProjection).ExplainInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/explain.go:377\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).getOperatorInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1169\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).prepareOperatorInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1083\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatOpInRowFormat\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1019\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatPlanInRowFormat\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:960\ngithub.com/pingcap/tidb/pkg/planner/core.(*Explain).RenderResult\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:912\ngithub.com/pingcap/tidb/pkg/planner/core.GetExplainRowsForPlan\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:783\ngithub.com/pingcap/tidb/pkg/session.(*session).SetProcessInfo\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:1422\ngithub.com/pingcap/tidb/pkg/executor.(*ExecStmt).Exec\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/executor/adapter.go:541\ngithub.com/pingcap/tidb/pkg/session.runStmt\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:2276\ngithub.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:2137\ngithub.com/pingcap/tidb/pkg/server.(*TiDBContext).ExecuteStmt\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/driver_tidb.go:294\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleStmt\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:2021\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleQuery\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1774\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).dispatch\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1348\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).Run\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1114\ngithub.com/pingcap/tidb/pkg/server.(*Server).onConn\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/server.go:739"]
1. github.com/pingcap/tidb/pkg/server.(*clientConn).Run.func1
   /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1016
2. runtime.gopanic
   /usr/local/go1.21/src/runtime/panic.go:914
3. runtime.goPanicIndex
   /usr/local/go1.21/src/runtime/panic.go:114
4. github.com/pingcap/tidb/pkg/expression.ExplainExpressionList
   /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/expression/explain.go:176
5. github.com/pingcap/tidb/pkg/planner/core.(*PhysicalProjection).ExplainInfo
   /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/explain.go:377
6. github.com/pingcap/tidb/pkg/planner/core.(*Explain).getOperatorInfo
   /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1169
7. github.com/pingcap/tidb/pkg/planner/core.(*Explain).prepareOperatorInfo
   /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1083
8. github.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatOpInRowFormat
   /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1019
9. github.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatPlanInRowFormat
   /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:960
10. github.com/pingcap/tidb/pkg/planner/core.(*Explain).RenderResult
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:912
11. github.com/pingcap/tidb/pkg/planner/core.GetExplainRowsForPlan
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:783
12. github.com/pingcap/tidb/pkg/session.(*session).SetProcessInfo
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:1422
13. github.com/pingcap/tidb/pkg/server.(*clientConn).dispatch.func2
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1306
14. runtime.gopanic
    /usr/local/go1.21/src/runtime/panic.go:920
15. github.com/pingcap/tidb/pkg/executor.(*ExecStmt).Exec.func1
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/executor/adapter.go:451
16. runtime.gopanic
    /usr/local/go1.21/src/runtime/panic.go:914
17. runtime.goPanicIndex
    /usr/local/go1.21/src/runtime/panic.go:114
18. github.com/pingcap/tidb/pkg/expression.ExplainExpressionList
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/expression/explain.go:176
19. github.com/pingcap/tidb/pkg/planner/core.(*PhysicalProjection).ExplainInfo
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/explain.go:377
20. github.com/pingcap/tidb/pkg/planner/core.(*Explain).getOperatorInfo
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1169
21. github.com/pingcap/tidb/pkg/planner/core.(*Explain).prepareOperatorInfo
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1083
22. github.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatOpInRowFormat
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:1019
23. github.com/pingcap/tidb/pkg/planner/core.(*Explain).explainFlatPlanInRowFormat
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:960
24. github.com/pingcap/tidb/pkg/planner/core.(*Explain).RenderResult
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:912
25. github.com/pingcap/tidb/pkg/planner/core.GetExplainRowsForPlan
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/planner/core/common_plans.go:783
26. github.com/pingcap/tidb/pkg/session.(*session).SetProcessInfo
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:1422
27. github.com/pingcap/tidb/pkg/executor.(*ExecStmt).Exec
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/executor/adapter.go:541
28. github.com/pingcap/tidb/pkg/session.runStmt
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:2276
29. github.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/session/session.go:2137
30. github.com/pingcap/tidb/pkg/server.(*TiDBContext).ExecuteStmt
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/driver_tidb.go:294
31. github.com/pingcap/tidb/pkg/server.(*clientConn).handleStmt
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:2021
32. github.com/pingcap/tidb/pkg/server.(*clientConn).handleQuery
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1774
33. github.com/pingcap/tidb/pkg/server.(*clientConn).dispatch
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1348
34. github.com/pingcap/tidb/pkg/server.(*clientConn).Run
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/conn.go:1114
35. github.com/pingcap/tidb/pkg/server.(*Server).onConn
    /Users/pingcap/workspace/bp-tidb-release-darwin-arm64-9mmc7-build-binaries/source/tidb/pkg/server/server.go:739

@Rustin170506
Copy link
Member

Rustin170506 commented May 7, 2024

create database testdb;
use testdb;


DROP TABLE IF EXISTS `t0`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `t0`
(
    `vkey` int(11)      DEFAULT NULL,
    `pkey` int(11)      DEFAULT NULL,
    `c0`   int(11)      DEFAULT NULL,
    `c1`   double       DEFAULT NULL,
    `c2`   varchar(100) DEFAULT NULL,
    `c3`   double       DEFAULT NULL,
    `c4`   double       DEFAULT NULL,
    `c5`   int(11)      DEFAULT NULL,
    `c6`   double NOT NULL,
    `c7`   int(11)      DEFAULT NULL,
    `c8`   int(11)      DEFAULT NULL,
    PRIMARY KEY (`c6`) /*T![clustered_index] CLUSTERED */
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `t0`
--

LOCK TABLES `t0` WRITE;
/*!40000 ALTER TABLE `t0`
    DISABLE KEYS */;
INSERT INTO `t0`
VALUES (1, 14000, NULL, -72.99, NULL, -64.2, 0, NULL, -97.54, NULL, NULL),
       (1, 13000, NULL, 0, NULL, 0, -33.89, NULL, -67.19, NULL, NULL),
       (1, 16000, NULL, -66.4, NULL, 8.71, 32.95, NULL, 0, NULL, NULL),
       (1, 17000, NULL, -10.88, NULL, 0, 0, NULL, 19.29, NULL, NULL),
       (1, 11000, NULL, 0.2, NULL, -96.9, 44.59, NULL, 20.8, NULL, NULL),
       (1, 12000, NULL, 95.15, NULL, 10.54, 69.22, NULL, 46.1, NULL, NULL),
       (1, 15000, NULL, -94.76, NULL, 0, -38.8, NULL, 73.7, NULL, NULL);
/*!40000 ALTER TABLE `t0`
    ENABLE KEYS */;
UNLOCK TABLES;


DROP TABLE IF EXISTS `t1`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `t1`
(
    `vkey` int(11)      DEFAULT NULL,
    `pkey` int(11)      DEFAULT NULL,
    `c9`   int(11)      DEFAULT NULL,
    `c10`  varchar(100) DEFAULT NULL,
    `c11`  varchar(100) DEFAULT NULL,
    `c12`  double       DEFAULT NULL,
    `c13`  int(11)      DEFAULT NULL,
    `c14`  int(11)      DEFAULT NULL,
    `c15`  int(11)      DEFAULT NULL,
    `c16`  double       DEFAULT NULL,
    `c17`  varchar(100) DEFAULT NULL,
    KEY `i2` (`pkey`, `c12`, `vkey`, `c16`, `c17`, `c11`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin /*T! SHARD_ROW_ID_BITS=6 */;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `t1`
--

LOCK TABLES `t1` WRITE;
/*!40000 ALTER TABLE `t1`
    DISABLE KEYS */;
INSERT INTO `t1`
VALUES (45, 260000, NULL, NULL, NULL, 27.43, NULL, NULL, NULL, 83.24, NULL),
       (45, 261000, NULL, NULL, NULL, 86.63, NULL, NULL, NULL, 56.53, NULL),
       (45, 262000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL),
       (45, 263000, NULL, NULL, NULL, -48.34, NULL, NULL, NULL, 6.75, NULL),
       (45, 264000, NULL, NULL, NULL, -27.91, NULL, NULL, NULL, -80.16, NULL),
       (45, 265000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -17.94, NULL),
       (45, 266000, NULL, NULL, NULL, -96.49, NULL, NULL, NULL, 0, NULL),
       (45, 267000, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, NULL),
       (23, 138000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -47.93, NULL),
       (23, 139000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -3.76, NULL),
       (23, 140000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -19.52, NULL),
       (23, 141000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -12.96, NULL),
       (23, 142000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 25.62, NULL),
       (23, 143000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -8.36, NULL),
       (23, 144000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL),
       (30, 181000, NULL, NULL, NULL, -10.45, NULL, NULL, NULL, NULL, NULL),
       (30, 182000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -25.26, NULL),
       (30, 183000, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL),
       (30, 184000, NULL, NULL, NULL, 0, NULL, NULL, NULL, 0, NULL),
       (30, 185000, NULL, NULL, NULL, -55.77, NULL, NULL, NULL, 0, NULL),
       (30, 186000, NULL, NULL, NULL, 44.47, NULL, NULL, NULL, NULL, NULL),
       (30, 187000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 30.58, NULL),
       (30, 188000, NULL, NULL, NULL, -80.47, NULL, NULL, NULL, 0, NULL),
       (46, 268000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
       (46, 269000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL),
       (46, 270000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL),
       (46, 271000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL),
       (46, 272000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 20.63, NULL),
       (25, 152000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 76.89, NULL),
       (25, 153000, NULL, NULL, NULL, -55.37, NULL, NULL, NULL, 72.44, NULL),
       (25, 154000, NULL, NULL, NULL, 57.46, NULL, NULL, NULL, -45.47, NULL),
       (25, 155000, NULL, NULL, NULL, 0, NULL, NULL, NULL, 14.51, NULL),
       (25, 156000, NULL, NULL, NULL, 26.15, NULL, NULL, NULL, NULL, NULL),
       (25, 157000, NULL, NULL, NULL, 52.79, NULL, NULL, NULL, 53.35, NULL),
       (25, 158000, NULL, NULL, NULL, 41.61, NULL, NULL, NULL, -94.89, NULL),
       (8, 50000, NULL, NULL, NULL, 57.29, NULL, NULL, NULL, 36.4, NULL),
       (8, 51000, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL),
       (8, 52000, NULL, NULL, NULL, 94.74, NULL, NULL, NULL, -5.47, NULL),
       (8, 53000, NULL, NULL, NULL, 0, NULL, NULL, NULL, 4.15, NULL),
       (8, 54000, NULL, NULL, NULL, 25.7, NULL, NULL, NULL, 0, NULL),
       (27, 167000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL),
       (27, 168000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -18.84, NULL),
       (27, 169000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 85.13, NULL),
       (27, 170000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL),
       (27, 171000, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -63.63, NULL);
/*!40000 ALTER TABLE `t1`
    ENABLE KEYS */;
UNLOCK TABLES;

DROP TABLE IF EXISTS `t2`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `t2`
(
    `vkey` int(11) NOT NULL,
    `pkey` int(11) DEFAULT NULL,
    `c18`  int(11) DEFAULT NULL,
    PRIMARY KEY (`vkey`) /*T![clustered_index] CLUSTERED */,
    KEY `i0` (`pkey`, `vkey`, `c18`),
    KEY `i1` (`vkey`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `t2`
--

LOCK TABLES `t2` WRITE;
/*!40000 ALTER TABLE `t2`
    DISABLE KEYS */;
/*!40000 ALTER TABLE `t2`
    ENABLE KEYS */;
UNLOCK TABLES;

DROP TABLE IF EXISTS `t3`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `t3`
(
    `vkey` int(11)      DEFAULT NULL,
    `pkey` int(11)      DEFAULT NULL,
    `c19`  double       DEFAULT NULL,
    `c20`  varchar(100) DEFAULT NULL,
    `c21`  double       DEFAULT NULL,
    `c22`  double       DEFAULT NULL,
    `c23`  int(11)      DEFAULT NULL,
    `c24`  int(11) NOT NULL,
    `c25`  int(11)      DEFAULT NULL,
    `c26`  double       DEFAULT NULL,
    `c27`  int(11)      DEFAULT NULL,
    PRIMARY KEY (`c24`) /*T![clustered_index] CLUSTERED */
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `t3`
--

LOCK TABLES `t3` WRITE;
/*!40000 ALTER TABLE `t3`
    DISABLE KEYS */;
/*!40000 ALTER TABLE `t3`
    ENABLE KEYS */;
UNLOCK TABLES;
DROP TABLE IF EXISTS `t5`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `t5`
(
    `vkey` int(11)      DEFAULT NULL,
    `pkey` int(11)      DEFAULT NULL,
    `c37`  double       DEFAULT NULL,
    `c38`  double       DEFAULT NULL,
    `c39`  varchar(100) DEFAULT NULL,
    `c40`  int(11)      DEFAULT NULL,
    `c41`  double       DEFAULT NULL,
    `c42`  int(11)      DEFAULT NULL
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `t5`
--

LOCK TABLES `t5` WRITE;
/*!40000 ALTER TABLE `t5`
    DISABLE KEYS */;
INSERT INTO `t5`
VALUES (2, 18000, NULL, 0, NULL, NULL, NULL, NULL),
       (2, 19000, NULL, NULL, NULL, NULL, -94.3, NULL),
       (2, 20000, NULL, 20.85, NULL, NULL, -8.18, NULL),
       (2, 21000, NULL, 0, NULL, NULL, 78.83, NULL),
       (2, 22000, NULL, -48.62, NULL, NULL, 0, NULL),
       (2, 23000, NULL, 0, NULL, NULL, 6.2, NULL),
       (2, 24000, NULL, -68.57, NULL, NULL, 0, NULL),
       (2, 25000, NULL, -12.27, NULL, NULL, 0, NULL),
       (3, 26000, -85.36, 0, NULL, NULL, 0, NULL),
       (3, 27000, 0, 0, NULL, NULL, -72.43, NULL),
       (3, 28000, NULL, 49.16, NULL, NULL, 0, NULL),
       (3, 29000, 10.63, -46.48, NULL, NULL, -17.22, NULL),
       (3, 30000, -67.64, 77.61, NULL, NULL, -99.47, NULL),
       (10, 63000, NULL, 24.2, NULL, NULL, 21.38, NULL),
       (10, 64000, NULL, 83.95, NULL, NULL, 34.4, NULL),
       (10, 65000, NULL, -33.25, NULL, NULL, 0, NULL),
       (16, 95000, 0, -81.1, NULL, NULL, 0, NULL),
       (16, 96000, 3.39, 64.81, NULL, NULL, -18.72, NULL),
       (16, 97000, 53.97, 0, NULL, NULL, 93.11, NULL),
       (17, 98000, 0, -70.27, NULL, NULL, 2.42, NULL),
       (17, 99000, 85.71, -82.64, NULL, NULL, NULL, NULL),
       (17, 100000, 47.64, 0, NULL, NULL, 0, NULL),
       (17, 101000, 67.3, -58.21, NULL, NULL, 0, NULL),
       (21, 122000, 0, NULL, NULL, NULL, 0, NULL),
       (21, 123000, 50.69, NULL, NULL, NULL, -89.2, NULL),
       (21, 124000, NULL, NULL, NULL, NULL, -93.31, NULL),
       (21, 125000, -63.84, NULL, NULL, NULL, -29.7, NULL),
       (21, 126000, 16.7, NULL, NULL, NULL, 24.5, NULL),
       (21, 127000, -31.89, NULL, NULL, NULL, 0, NULL),
       (21, 128000, 2.58, NULL, NULL, NULL, -86.1, NULL),
       (21, 129000, 12.76, NULL, NULL, NULL, 0, NULL),
       (22, 130000, -81.81, 0, NULL, NULL, -26.29, NULL),
       (22, 131000, -29.45, 65.3, NULL, NULL, 0, NULL),
       (22, 132000, 8.11, -91.38, NULL, NULL, 94.15, NULL),
       (22, 133000, NULL, -17.69, NULL, NULL, -65.74, NULL),
       (22, 134000, 0, 0, NULL, NULL, -82.62, NULL),
       (22, 135000, -59.5, 28.6, NULL, NULL, -58.52, NULL),
       (22, 136000, -85.2, 20.68, NULL, NULL, -2.3, NULL),
       (22, 137000, 0, 0, NULL, NULL, 0, NULL),
       (26, 159000, 0, 0, NULL, NULL, -5.58, NULL),
       (26, 160000, 0, 40.8, NULL, NULL, 0, NULL),
       (26, 161000, 38.22, 0, NULL, NULL, NULL, NULL),
       (26, 162000, -18.51, 73.59, NULL, NULL, -100.65, NULL),
       (26, 163000, 0, 17.54, NULL, NULL, 0, NULL),
       (26, 164000, 0, 0, NULL, NULL, 98.45, NULL),
       (26, 165000, NULL, 0, NULL, NULL, 0, NULL),
       (26, 166000, 0, 0, NULL, NULL, 46.68, NULL),
       (32, 196000, 0, NULL, NULL, NULL, 11.16, NULL),
       (32, 197000, NULL, NULL, NULL, NULL, 0, NULL),
       (32, 198000, -17.67, NULL, NULL, NULL, NULL, NULL),
       (32, 199000, 33.25, NULL, NULL, NULL, -66.69, NULL),
       (38, 227000, 68.22, 0, NULL, NULL, NULL, NULL),
       (38, 228000, 0, 0, NULL, NULL, 56.89, NULL),
       (38, 229000, 64.79, -40.61, NULL, NULL, 89.14, NULL),
       (38, 230000, NULL, -100.53, NULL, NULL, -40.1, NULL),
       (38, 231000, -8.98, -75.9, NULL, NULL, 29.86, NULL),
       (44, 256000, 46.98, 0, NULL, NULL, NULL, NULL),
       (44, 257000, NULL, -56.3, NULL, NULL, 36.23, NULL),
       (44, 258000, -12.39, 74.77, NULL, NULL, 0, NULL),
       (44, 259000, 10.45, NULL, NULL, NULL, 46.46, NULL),
       (53, 299000, 44.95, 48.49, NULL, NULL, -11.99, NULL),
       (53, 300000, 63.5, 13.31, NULL, NULL, 89.21, NULL),
       (53, 301000, NULL, 63.13, NULL, NULL, 0, NULL),
       (53, 302000, 35.59, 0, NULL, NULL, 0, NULL),
       (53, 303000, -5.73, NULL, NULL, NULL, 57.27, NULL),
       (53, 304000, -93.48, 78.11, NULL, NULL, 0, NULL),
       (53, 305000, -6.29, -66.2, NULL, NULL, 29.15, NULL),
       (53, 306000, 0, -36.21, NULL, NULL, 55.47, NULL),
       (54, 307000, -53.51, -52.47, NULL, NULL, NULL, NULL),
       (54, 308000, -89.13, 0, NULL, NULL, NULL, NULL),
       (54, 309000, -70.77, 0, NULL, NULL, NULL, NULL),
       (54, 310000, 0, 0, NULL, NULL, NULL, NULL),
       (54, 311000, -24.94, 0, NULL, NULL, NULL, NULL),
       (54, 312000, 37.1, 0, NULL, NULL, NULL, NULL),
       (56, 321000, 0, NULL, NULL, NULL, 0, NULL),
       (56, 322000, 26.7, 30.43, NULL, NULL, 5.72, NULL),
       (56, 323000, -32.36, 30.27, NULL, NULL, 13.52, NULL),
       (56, 324000, 61.62, -77.96, NULL, NULL, 0, NULL),
       (56, 325000, NULL, -45.95, NULL, NULL, 62.34, NULL),
       (56, 326000, 91.67, 71.17, NULL, NULL, 67.7, NULL),
       (56, 327000, 0, 0, NULL, NULL, -64.49, NULL),
       (56, 328000, 54.24, 0, NULL, NULL, -46.18, NULL);
/*!40000 ALTER TABLE `t5`
    ENABLE KEYS */;
UNLOCK TABLES;

DROP TABLE IF EXISTS `t6`;
/*!50001 DROP VIEW IF EXISTS `t6`*/;
SET @saved_cs_client = @@character_set_client;
/*!50503 SET character_set_client = utf8mb4 */;
/*!50001 CREATE VIEW `t6` AS
SELECT 1 AS `c0`,
       1 AS `c1`
        */;
SET character_set_client = @saved_cs_client;

/*!50001 DROP VIEW IF EXISTS `t6`*/;
/*!50001 CREATE ALGORITHM = UNDEFINED */ /*!50013 DEFINER =`root`@`%` SQL SECURITY DEFINER */ /*!50001 VIEW `t6` (`c0`, `c1`) AS
SELECT `subq_0`.`c1` AS `c0`, NULL AS `c1`
FROM (SELECT (SELECT `c8` AS `c8` FROM `testdb`.`t0` ORDER BY `c8` LIMIT 1,1) AS `c0`, `ref_0`.`pkey` AS `c1`
      FROM `testdb`.`t2` AS `ref_0`
      WHERE (((`ref_0`.`c18`) >= (SELECT `ref_0`.`vkey` AS `c0`
                                  FROM `testdb`.`t3` AS `ref_1`
                                  WHERE ((`ref_1`.`c26`) != (SELECT `ref_2`.`c37` AS `c0`
                                                             FROM `testdb`.`t5` AS `ref_2`
                                                             WHERE ((NULL) AND (FALSE))
                                                                OR (EXISTS (SELECT `ref_1`.`c26`                                                       AS `c0`,
                                                                                   `ref_3`.`c3`                                                        AS `c1`,
                                                                                   `ref_3`.`pkey`                                                      AS `c2`,
                                                                                   `ref_3`.`vkey`                                                      AS `c3`,
                                                                                   `ref_3`.`c6`                                                        AS `c4`,
                                                                                   `ref_1`.`c26`                                                       AS `c5`,
                                                                                   79                                                                  AS `c6`,
                                                                                   NULL                                                                AS `c7`,
                                                                                   `ref_3`.`vkey`                                                      AS `c8`,
                                                                                   `ref_3`.`c1`                                                        AS `c9`,
                                                                                   (SELECT `c17` AS `c17` FROM `testdb`.`t1` ORDER BY `c17` LIMIT 4,1) AS `c10`,
                                                                                   `ref_3`.`c4`                                                        AS `c11`,
                                                                                   `ref_3`.`c6`                                                        AS `c12`,
                                                                                   `ref_3`.`c6`                                                        AS `c13`,
                                                                                   `ref_2`.`c40`                                                       AS `c14`,
                                                                                   90                                                                  AS `c15`
                                                                            FROM `testdb`.`t0` AS `ref_3`
                                                                            WHERE NULL
                                                                            UNION ALL
                                                                            SELECT `ref_2`.`c41`                                                          AS `c0`,
                                                                                   `ref_2`.`c38`                                                          AS `c1`,
                                                                                   `ref_1`.`pkey`                                                         AS `c2`,
                                                                                   `ref_0`.`pkey`                                                         AS `c3`,
                                                                                   0.0                                                                    AS `c4`,
                                                                                   `ref_1`.`c21`                                                          AS `c5`,
                                                                                   -20                                                                    AS `c6`,
                                                                                   ((TRUE) IN
                                                                                    (SELECT (-97) = (-73) AS `c0`
                                                                                     FROM `testdb`.`t2` AS `ref_9`
                                                                                     WHERE NULL)) IS TRUE                                                 AS `c7`,
                                                                                   `ref_2`.`pkey`                                                         AS `c8`,
                                                                                   `ref_1`.`c26`                                                          AS `c9`,
                                                                                   `ref_1`.`c20`                                                          AS `c10`,
                                                                                   `ref_2`.`c41`                                                          AS `c11`,
                                                                                   `ref_2`.`c41`                                                          AS `c12`,
                                                                                   `ref_2`.`c37`                                                          AS `c13`,
                                                                                   (SELECT `vkey` AS `vkey` FROM `testdb`.`t2` ORDER BY `vkey` LIMIT 6,1) AS `c14`,
                                                                                   0                                                                      AS `c15`
                                                                            FROM `testdb`.`t2` AS `ref_4`
                                                                            WHERE (((SELECT `c39` AS `c39` FROM `testdb`.`t5` ORDER BY `c39` LIMIT 1,1)) IN
                                                                                   (SELECT DISTINCT `ref_5`.`c20` AS `c0`
                                                                                    FROM `testdb`.`t3` AS `ref_5`
                                                                                    WHERE (-0) BETWEEN (0) AND (-0)
                                                                                    UNION ALL
                                                                                    SELECT `ref_6`.`c17` AS `c0`
                                                                                    FROM `testdb`.`t1` AS `ref_6`
                                                                                    WHERE (FALSE)
                                                                                       OR ((`ref_6`.`c13`) =
                                                                                           (SELECT `ref_6`.`c13` AS `c0`
                                                                                            FROM `testdb`.`t5` AS `ref_7`
                                                                                            WHERE ((-0) < (0))
                                                                                              AND ((`ref_7`.`c41`) !=
                                                                                                   (SELECT DISTINCT `ref_8`.`c21` AS `c0`
                                                                                                    FROM `testdb`.`t3` AS `ref_8`
                                                                                                    WHERE (NOT ((-22) BETWEEN (-0) AND (-19)))
                                                                                                       OR ((82) > (91))
                                                                                                    ORDER BY `c0`
                                                                                                    LIMIT 1))
                                                                                            ORDER BY `c0`
                                                                                            LIMIT 1)))) IS TRUE))
                                                             ORDER BY `c0` DESC
                                                             LIMIT 1))
                                    AND ((NULL) OR ((-75) > (42)))
                                  ORDER BY `c0` DESC
                                  LIMIT 1)) AND ((-54) BETWEEN (68) AND (0)))
         OR ((`ref_0`.`vkey`) IS NULL)
      ORDER BY `c0`, `c1` DESC) AS `subq_0`
WHERE (`subq_0`.`c1`) IS NOT NULL
        */;


set @@tidb_remove_orderby_in_subquery = 0;

explain select ref_39.c17 as c0
from (t1 as ref_39
    left outer join t2 as ref_40
      on (ref_39.c13 = ref_40.vkey))
where (case
           when exists (select ref_73.c9 as c0
                        from t1 as ref_73
                        union
                        select null + 83 as c0
                        from t6 as ref_77
                        where (ref_40.pkey = null)
                          and (2 > (select 1 as c0
                                    from t1 as ref_85
                                    where exists (select ref_103.c25 as c0
                                                  from t3 as ref_103
                                                  where ref_85.c13 = ref_103.c25)
                                    limit 1))) then null
           else 1 end
          ) >= 1;

@Rustin170506
Copy link
Member

Tested it with the latest master, and it was fixed by #52836.

@Rustin170506
Copy link
Member

Fixed by this change:
image

@Rustin170506
Copy link
Member

explain
SELECT `subq_0`.`c1` AS `c0`, NULL AS `c1`
FROM (SELECT (SELECT `c8` AS `c8` FROM `testdb`.`t0` ORDER BY `c8` LIMIT 1,1) AS `c0`, `ref_0`.`pkey` AS `c1`
      FROM `testdb`.`t2` AS `ref_0`
      WHERE (((`ref_0`.`c18`) >= (SELECT `ref_0`.`vkey` AS `c0`
                                  FROM `testdb`.`t3` AS `ref_1`
                                  WHERE ((`ref_1`.`c26`) != (SELECT `ref_2`.`c37` AS `c0`
                                                             FROM `testdb`.`t5` AS `ref_2`
                                                             WHERE ((NULL) AND (FALSE))
                                                                OR (EXISTS (SELECT `ref_1`.`c26`                                                       AS `c0`,
                                                                                   `ref_3`.`c3`                                                        AS `c1`,
                                                                                   `ref_3`.`pkey`                                                      AS `c2`,
                                                                                   `ref_3`.`vkey`                                                      AS `c3`,
                                                                                   `ref_3`.`c6`                                                        AS `c4`,
                                                                                   `ref_1`.`c26`                                                       AS `c5`,
                                                                                   79                                                                  AS `c6`,
                                                                                   NULL                                                                AS `c7`,
                                                                                   `ref_3`.`vkey`                                                      AS `c8`,
                                                                                   `ref_3`.`c1`                                                        AS `c9`,
                                                                                   (SELECT `c17` AS `c17` FROM `testdb`.`t1` ORDER BY `c17` LIMIT 4,1) AS `c10`,
                                                                                   `ref_3`.`c4`                                                        AS `c11`,
                                                                                   `ref_3`.`c6`                                                        AS `c12`,
                                                                                   `ref_3`.`c6`                                                        AS `c13`,
                                                                                   `ref_2`.`c40`                                                       AS `c14`,
                                                                                   90                                                                  AS `c15`
                                                                            FROM `testdb`.`t0` AS `ref_3`
                                                                            WHERE NULL
                                                                            UNION ALL
                                                                            SELECT `ref_2`.`c41`                                                          AS `c0`,
                                                                                   `ref_2`.`c38`                                                          AS `c1`,
                                                                                   `ref_1`.`pkey`                                                         AS `c2`,
                                                                                   `ref_0`.`pkey`                                                         AS `c3`,
                                                                                   0.0                                                                    AS `c4`,
                                                                                   `ref_1`.`c21`                                                          AS `c5`,
                                                                                   -20                                                                    AS `c6`,
                                                                                   ((TRUE) IN
                                                                                    (SELECT (-97) = (-73) AS `c0`
                                                                                     FROM `testdb`.`t2` AS `ref_9`
                                                                                     WHERE NULL)) IS TRUE                                                 AS `c7`,
                                                                                   `ref_2`.`pkey`                                                         AS `c8`,
                                                                                   `ref_1`.`c26`                                                          AS `c9`,
                                                                                   `ref_1`.`c20`                                                          AS `c10`,
                                                                                   `ref_2`.`c41`                                                          AS `c11`,
                                                                                   `ref_2`.`c41`                                                          AS `c12`,
                                                                                   `ref_2`.`c37`                                                          AS `c13`,
                                                                                   (SELECT `vkey` AS `vkey` FROM `testdb`.`t2` ORDER BY `vkey` LIMIT 6,1) AS `c14`,
                                                                                   0                                                                      AS `c15`
                                                                            FROM `testdb`.`t2` AS `ref_4`
                                                                            WHERE (((SELECT `c39` AS `c39` FROM `testdb`.`t5` ORDER BY `c39` LIMIT 1,1)) IN
                                                                                   (SELECT DISTINCT `ref_5`.`c20` AS `c0`
                                                                                    FROM `testdb`.`t3` AS `ref_5`
                                                                                    WHERE (-0) BETWEEN (0) AND (-0)
                                                                                    UNION ALL
                                                                                    SELECT `ref_6`.`c17` AS `c0`
                                                                                    FROM `testdb`.`t1` AS `ref_6`
                                                                                    WHERE (FALSE)
                                                                                       OR ((`ref_6`.`c13`) =
                                                                                           (SELECT `ref_6`.`c13` AS `c0`
                                                                                            FROM `testdb`.`t5` AS `ref_7`
                                                                                            WHERE ((-0) < (0))
                                                                                              AND ((`ref_7`.`c41`) !=
                                                                                                   (SELECT DISTINCT `ref_8`.`c21` AS `c0`
                                                                                                    FROM `testdb`.`t3` AS `ref_8`
                                                                                                    WHERE (NOT ((-22) BETWEEN (-0) AND (-19)))
                                                                                                       OR ((82) > (91))
                                                                                                    ORDER BY `c0`
                                                                                                    LIMIT 1))
                                                                                            ORDER BY `c0`
                                                                                            LIMIT 1)))) IS TRUE))
                                                             ORDER BY `c0` DESC
                                                             LIMIT 1))
                                    AND ((NULL) OR ((-75) > (42)))
                                  ORDER BY `c0` DESC
                                  LIMIT 1)) AND ((-54) BETWEEN (68) AND (0)))
         OR ((`ref_0`.`vkey`) IS NULL)
      ORDER BY `c0`, `c1` DESC) AS `subq_0`
WHERE (`subq_0`.`c1`) IS NOT NULL;

Before #52836:

id estRows task access object operator info
Projection_158 0.00 root testdb.t2.pkey, <nil>->Column#203
└─TableDual_159 0.00 root rows:0

After the change:

id estRows task access object operator info
Projection_159 0.00 root testdb.t2.pkey, <nil>->Column#203
└─Projection_165 0.00 root <nil>->Column#202, testdb.t2.pkey
└─TableDual_166 0.00 root rows:0

@Rustin170506
Copy link
Member

Rustin170506 commented May 7, 2024

And the query's plan is:

+--------------------------------------------+---------+---------+-------------+---------------------------------------------------------------------------------------------------------------------------------------+
|id                                          |estRows  |task     |access object|operator info                                                                                                                          |
+--------------------------------------------+---------+---------+-------------+---------------------------------------------------------------------------------------------------------------------------------------+
|Projection_190                              |45.00    |root     |             |testdb.t1.c17                                                                                                                          |
|└─Selection_191                             |45.00    |root     |             |ge(case(Column#257, NULL, 1), 1)                                                                                                       |
|  └─Apply_193                               |56.25    |root     |             |CARTESIAN left outer semi join                                                                                                         |
|    ├─IndexJoin_198(Build)                  |56.25    |root     |             |left outer join, inner:TableReader_195, outer key:testdb.t1.c13, inner key:testdb.t2.vkey, equal cond:eq(testdb.t1.c13, testdb.t2.vkey)|
|    │ ├─TableReader_206(Build)              |45.00    |root     |             |data:TableFullScan_205                                                                                                                 |
|    │ │ └─TableFullScan_205                 |45.00    |cop[tikv]|table:ref_39 |keep order:false, stats:pseudo                                                                                                         |
|    │ └─TableReader_195(Probe)              |45.00    |root     |             |data:TableRangeScan_194                                                                                                                |
|    │   └─TableRangeScan_194                |45.00    |cop[tikv]|table:ref_40 |range: decided by [testdb.t1.c13], keep order:false, stats:pseudo                                                                      |
|    └─Union_211(Probe)                      |2531.25  |root     |             |                                                                                                                                       |
|      ├─Projection_212                      |2531.25  |root     |             |cast(testdb.t1.c9, bigint(20) BINARY)->Column#256                                                                                      |
|      │ └─TableReader_214                   |2531.25  |root     |             |data:TableFullScan_213                                                                                                                 |
|      │   └─TableFullScan_213               |2531.25  |cop[tikv]|table:ref_73 |keep order:false, stats:pseudo                                                                                                         |
|      └─Projection_215                      |0.00     |root     |             |<nil>->Column#256                                                                                                                      |
|        └─HashJoin_216                      |0.00     |root     |             |CARTESIAN inner join                                                                                                                   |
|          ├─Selection_229(Build)            |45.00    |root     |             |eq(testdb.t2.pkey, NULL), gt(2, Column#254)                                                                                            |
|          │ └─MaxOneRow_230                 |56.25    |root     |             |                                                                                                                                       |
|          │   └─Projection_231              |56.25    |root     |             |1->Column#254                                                                                                                          |
|          │     └─Limit_234                 |56.25    |root     |             |offset:0, count:1                                                                                                                      |
|          │       └─HashJoin_235            |56.25    |root     |             |semi join, equal:[eq(testdb.t1.c13, testdb.t3.c25)]                                                                                    |
|          │         ├─TableReader_241(Build)|561937.50|root     |             |data:Selection_240                                                                                                                     |
|          │         │ └─Selection_240       |561937.50|cop[tikv]|             |not(isnull(testdb.t3.c25))                                                                                                             |
|          │         │   └─TableFullScan_239 |562500.00|cop[tikv]|table:ref_103|keep order:false, stats:pseudo                                                                                                         |
|          │         └─TableReader_238(Probe)|70.31    |root     |             |data:Selection_237                                                                                                                     |
|          │           └─Selection_237       |70.31    |cop[tikv]|             |not(isnull(testdb.t1.c13))                                                                                                             |
|          │             └─TableFullScan_236 |70.38    |cop[tikv]|table:ref_85 |keep order:false, stats:pseudo                                                                                                         |
|          └─Selection_218(Probe)            |0.00     |root     |             |eq(testdb.t2.pkey, NULL)                                                                                                               |
|            └─Projection_226                |0.00     |root     |             |<nil>->Column#229, testdb.t2.pkey                                                                                                      |
|              └─TableDual_227               |0.00     |root     |             |rows:0                                                                                                                                 |
+--------------------------------------------+---------+---------+-------------+---------------------------------------------------------------------------------------------------------------------------------------+

So as you can see, if we reset the children projection's schmea, then we will get a panic. Because we use it in the probe side.

@Rustin170506 Rustin170506 moved this from 🏊WIP to ✅ Done in 🎒My Work May 7, 2024
@fixdb
Copy link
Contributor

fixdb commented May 21, 2024

@hi-rustin can you cherry-pick to 7.5?

@fixdb fixdb removed may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.1 This bug maybe affects 5.1.x versions. may-affects-5.2 This bug maybe affects 5.2.x versions. may-affects-5.3 This bug maybe affects 5.3.x versions. may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. may-affects-6.1 may-affects-6.5 labels Aug 1, 2024
ti-chi-bot bot pushed a commit that referenced this issue Aug 26, 2024
ti-chi-bot bot pushed a commit that referenced this issue Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. severity/moderate sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

6 participants