executor panicked for "runtime error: invalid memory address or nil pointer dereference"
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
drop table if exists t1;
drop table if exists t2;
create table t1(a bigint, b bigint);
create table t2(a bigint, b bigint);
insert into t1 values(1, 1);
mysql> select t1.a+t1.b as result from t1 left join t2 on 1 = 0 order by result;
+--------+
| result |
+--------+
| 2 |
+--------+
1 row in set (0.00 sec)
mysql> select t1.a+t1.b as result from t1 left join t2 on 1 = 0 order by result limit 1;
ERROR 1105 (HY000): runtime error: invalid memory address or nil pointer dereference
mysql> explain select t1.a+t1.b as result from t1 left join t2 on 1 = 0 order by result limit 1;
+------------------------------------------+---------+-----------+---------------+------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+------------------------------------------+---------+-----------+---------------+------------------------------------------------------------+
| Projection_9 | 1.00 | root | | plus(test.t1.a, test.t1.b)->Column#7 |
| └─Projection_25 | 1.00 | root | | test.t1.a, test.t1.b |
| └─TopN_12 | 1.00 | root | | Column#9, offset:0, count:1 |
| └─Projection_26 | 1.00 | root | | test.t1.a, test.t1.b, plus(test.t1.a, test.t1.b)->Column#9 |
| └─HashJoin_14 | 1.00 | root | | CARTESIAN left outer join |
| ├─TableDual_22(Build) | 0.00 | root | | rows:0 |
| └─Projection_23(Probe) | 1.00 | root | | test.t1.a, test.t1.b |
| └─TopN_16 | 1.00 | root | | Column#8, offset:0, count:1 |
| └─Projection_24 | 1.00 | root | | test.t1.a, test.t1.b, plus(test.t1.a, test.t1.b)->Column#8 |
| └─TableReader_21 | 1.00 | root | | data:TopN_20 |
| └─TopN_20 | 1.00 | cop[tikv] | | plus(test.t1.a, test.t1.b), offset:0, count:1 |
| └─TableFullScan_19 | 1.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo |
+------------------------------------------+---------+-----------+---------------+------------------------------------------------------------+
12 rows in set (0.01 sec)
mysql>
2. What did you expect to see? (Required)
3. What did you see instead (Required)
2024-06-25 18:48:52 (UTC+08:00)TiDB 127.0.0.1:4000[sort_util.go:52] ["executor panicked"] [error="runtime error: invalid memory address or nil pointer dereference"] [stack="github.com/pingcap/tidb/pkg/executor/sortexec.processPanicAndLog\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-xfhw7-build-binaries/source/tidb/pkg/executor/sortexec/sort_util.go:52\ngithub.com/pingcap/tidb/pkg/executor/sortexec.(*TopNExec).executeTopN.func1\n\t/Users/pingcap/workspace/bp-tidb-release-darwin-arm64-xfhw7-build-binaries/source/tidb/pkg/executor/sortexec/topn.go:443\nruntime.gopanic\n\t/usr/local/go1.21/src/runtime/panic.go:914\nruntime.panicmem\n\t/usr/local/go1.21/src/runtime/panic.go:261\nruntime.sigpanic\n\t/usr/local/go1.21/src/runtime/signal_unix.go:861\ngithub.com/pingcap/tidb/pkg/executor/sortexec.
4. What is your TiDB version? (Required)
01cc0274bd22a4ab0090a56a6dd8d01b871c484d
no error report on : Git Commit Hash: 1368bf75f11d5406d0f447b3eed1cd625fd826a8 Git Branch: heads/refs/tags/v8.2.0-alpha UTC Build Time: 2024-06-24 11:46:26
Hi, i can't reproduce this. Can you try to reproduce it again and provide more detail?
/remove-label may-affects-5.4
/remove-label may-affects-6.1
/remove-label may-affects-6.5
/remove-label may-affects-7.1
/remove-label may-affects-7.5
/remove-label may-affects-8.1
/assign