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

A panic occurs when tidb_enable_ordered_result_mode is enabled #45044

Closed
Bowen-Tang opened this issue Jun 29, 2023 · 4 comments · Fixed by #48100
Closed

A panic occurs when tidb_enable_ordered_result_mode is enabled #45044

Bowen-Tang opened this issue Jun 29, 2023 · 4 comments · Fixed by #48100
Assignees
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@Bowen-Tang
Copy link

Bug Report

开启 tidb_enable_ordered_result_mode 后,SQL 执行 panic

1. Minimal reproduce step (Required)

8a55761aad6af508ff9754fb2dd900c

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

执行正常

3. What did you see instead (Required)

[2023/06/25 10:18:28.572 +08:00] [ERROR] [conn.go:1072] ["connection running loop panic"] [conn=8396308395326069831] [lastSQL="SELECT p.product_code \r\nFROM shop_upload_commodity_pic p\r\nGROUP BY p.product_code \r\nHAVING count(*)>1 \r\nORDER BY p.product_code \r\nlimit 10"] [err="runtime error: invalid memory address or nil pointer dereference"] [stack="github.com/pingcap/tidb/server.(*clientConn).Run.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1075\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:884\ngit.luolix.top/pingcap/tidb/executor.(*Compiler).Compile.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/compiler.go:54\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:884\nruntime.panicmem\n\t/usr/local/go/src/runtime/panic.go:260\nruntime.sigpanic\n\t/usr/local/go/src/runtime/signal_unix.go:837\ngit.luolix.top/pingcap/tidb/expression.(*Schema).ColumnIndex\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/schema.go:133\ngit.luolix.top/pingcap/tidb/expression.(*Schema).Contains\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/expression/schema.go:151\ngit.luolix.top/pingcap/tidb/planner/core.(*resultReorder).extractHandleCol\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/planner/core/rule_result_reorder.go:109\ngit.luolix.top/pingcap/tidb/planner/core.(*resultReorder).completeSort\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/planner/core/rule_result_reorder.go:55\ngit.luolix.top/pingcap/tidb/planner/core.(*resultReorder).completeSort\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/planner/core/rule_result_reorder.go:52\ngit.luolix.top/pingcap/tidb/planner/core.(*resultReorder).completeSort\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/planner/core/rule_result_reorder.go:52\ngit.luolix.top/pingcap/tidb/planner/core.(*resultReorder).optimize\n\t/

4. What is your TiDB version? (Required)

tidb 7.1

@Bowen-Tang Bowen-Tang added the type/bug The issue is confirmed as a bug. label Jun 29, 2023
@ti-chi-bot ti-chi-bot bot added 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 may-affects-7.1 labels Jun 29, 2023
@jebter jebter changed the title 开启 tidb_enable_ordered_result_mode 后,SQL 执行报错 A panic occurs when tidb_enable_ordered_result_mode is enabled Jun 29, 2023
@XuHuaiyu
Copy link
Contributor

Panic happened during optimizing. I'd like to change the label to sig/planner

@XuHuaiyu XuHuaiyu added sig/planner SIG: Planner and removed sig/execution SIG execution labels Jun 29, 2023
@chrysan
Copy link
Contributor

chrysan commented Jun 29, 2023

@Bowen-Tang Can you provide detailed reproduce steps?

@guo-shaoge
Copy link
Collaborator

guo-shaoge commented Jul 3, 2023

@Bowen-Tang Can you provide detailed reproduce steps?

set tidb_enable_ordered_result_mode = on;
create table t1(c1 int);
explain select * from t1 group by t1.c1 having count(1) > 1 order by count(1) limit 10;
MySQL [test]> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                 |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v7.1.0
Edition: Community
Git Commit Hash: 635a4362235e8a3c0043542e629532e3c7bb2756
Git Branch: HEAD
UTC Build Time: 2023-07-03 02:30:01
GoVersion: go1.20.1
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.001 sec)

MySQL [test]> set tidb_enable_ordered_result_mode = on;
Query OK, 0 rows affected (0.001 sec)

MySQL [test]> explain select * from t1 group by t1.c1 having count(1) > 1 order by count(1) limit 10;
ERROR 1105 (HY000): runtime error: invalid memory address or nil pointer dereference

stack

github.com/pingcap/tidb/expression.(*Schema).ColumnIndex
    /home/guojiangtao/work/tidb/expression/schema.go:133
github.com/pingcap/tidb/expression.(*Schema).Contains
    /home/guojiangtao/work/tidb/expression/schema.go:151
github.com/pingcap/tidb/planner/core.(*resultReorder).extractHandleCol
    /home/guojiangtao/work/tidb/planner/core/rule_result_reorder.go:109
github.com/pingcap/tidb/planner/core.(*resultReorder).completeSort
    /home/guojiangtao/work/tidb/planner/core/rule_result_reorder.go:55
github.com/pingcap/tidb/planner/core.(*resultReorder).completeSort
    /home/guojiangtao/work/tidb/planner/core/rule_result_reorder.go:52
github.com/pingcap/tidb/planner/core.(*resultReorder).completeSort
    /home/guojiangtao/work/tidb/planner/core/rule_result_reorder.go:52
github.com/pingcap/tidb/planner/core.(*resultReorder).optimize
    /home/guojiangtao/work/tidb/planner/core/rule_result_reorder.go:43
github.com/pingcap/tidb/planner/core.logicalOptimize
    /home/guojiangtao/work/tidb/planner/core/optimizer.go:1108
github.com/pingcap/tidb/planner/core.DoOptimize
    /home/guojiangtao/work/tidb/planner/core/optimizer.go:301
github.com/pingcap/tidb/planner.optimize
    /home/guojiangtao/work/tidb/planner/optimize.go:506
github.com/pingcap/tidb/planner.Optimize
    /home/guojiangtao/work/tidb/planner/optimize.go:329
github.com/pingcap/tidb/planner/core.(*PlanBuilder).buildExplain
    /home/guojiangtao/work/tidb/planner/core/planbuilder.go:5041
github.com/pingcap/tidb/planner/core.(*PlanBuilder).Build
    /home/guojiangtao/work/tidb/planner/core/planbuilder.go:794
github.com/pingcap/tidb/planner.buildLogicalPlan
    /home/guojiangtao/work/tidb/planner/optimize.go:550
github.com/pingcap/tidb/planner.optimize
    /home/guojiangtao/work/tidb/planner/optimize.go:471
github.com/pingcap/tidb/planner.Optimize
    /home/guojiangtao/work/tidb/planner/optimize.go:329
github.com/pingcap/tidb/executor.(*Compiler).Compile
    /home/guojiangtao/work/tidb/executor/compiler.go:98
github.com/pingcap/tidb/session.(*session).ExecuteStmt
    /home/guojiangtao/work/tidb/session/session.go:2177
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt
    /home/guojiangtao/work/tidb/server/driver_tidb.go:252
github.com/pingcap/tidb/server.(*clientConn).handleStmt

@guo-shaoge
Copy link
Collaborator

Seems (rs *resultReorder) extractHandleCol didn't handle other opetrators, like proj for this issue, so handleCol of lp's child is nil, and the logic didn't check if handleCol is nil or not, which makes this nil pointer error.

@ti-chi-bot ti-chi-bot added affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. and removed 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 may-affects-7.1 labels Jul 6, 2023
@qw4990 qw4990 self-assigned this Aug 16, 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
@qw4990 qw4990 removed affects-5.2 This bug affects 5.2.x versions. affects-5.3 This bug affects 5.3.x versions. labels Oct 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-5.4 This bug affects the 5.4.x(LTS) versions. affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. severity/major sig/planner SIG: Planner type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants