pingcap / tidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.
https://pingcap.com
Apache License 2.0
37.27k stars 5.84k forks source link

nil pointer error #55666

Closed XuHuaiyu closed 2 months ago

XuHuaiyu commented 2 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

drop table if exists table_abc1;
drop table if exists table_abc2;
drop table if exists table_abc3;
drop table if exists table_abc4;

CREATE TABLE `table_abc1` (
  `column_abc1` varchar(10) DEFAULT NULL,
  `column_abc2` varchar(10) DEFAULT NULL,
  `column_abc3` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE `table_abc3` (
  `column_abc5` varchar(10) DEFAULT NULL,
  `column_abc6` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

CREATE TABLE `table_abc4` (
  `column_abc3` varchar(10) DEFAULT NULL,
  `column_abc7` varchar(10) DEFAULT NULL,
  `column_abc5` varchar(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

INSERT INTO `table_abc1` VALUES ('KTL157','KTL157','KTL157');
INSERT INTO `table_abc3` VALUES ('1000','20240819');
INSERT INTO `table_abc4` VALUES ('KTL157','test','1000');

DELETE FROM table_abc3 t_abc3
WHERE t_abc3.column_abc5 IN (
    SELECT a.column_abc5
    FROM (
        WITH tree_cte1 AS (
            WITH RECURSIVE tree_cte AS (
                SELECT t.column_abc1, t.column_abc2, t.column_abc3, 0 AS lv
                FROM table_abc1 t
                WHERE t.column_abc1 IN ('KTL157', 'KTL159')
                UNION ALL
                SELECT t.column_abc1, t.column_abc2, t.column_abc3, tcte.lv + 1
                FROM table_abc1 t
                JOIN tree_cte tcte ON t.column_abc1 = tcte.column_abc2
                WHERE tcte.lv <= 1
            )
            SELECT * FROM tree_cte
        )
        SELECT  e.column_abc5
        FROM (
            SELECT DISTINCT * FROM tree_cte1
        ) aa
        LEFT JOIN table_abc4 e ON e.column_abc3 = aa.column_abc3
    ) a
);

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

no error

3. What did you see instead (Required)

ERROR 1105 (HY000): runtime error: invalid memory address or nil pointer dereference
[2024/08/26 18:36:20.488 +08:00] [INFO] [conn.go:1183] ["command dispatched failed"] [conn=872415234] [session_alias=] [connInfo="id:872415234, addr:127.0.0.1:56448 status:10, collation:utf8mb4_0900_ai_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="DELETE FROM table_abc3 t_abc3 WHERE t_abc3.column_abc5 IN (     SELECT a.column_abc5     FROM (         WITH tree_cte1 AS (             WITH RECURSIVE tree_cte AS (                 SELECT t.column_abc1, t.column_abc2, t.column_abc3, 0 AS lv                 FROM table_abc1 t                 WHERE t.column_abc1 IN ('KTL157', 'KTL159')                 UNION ALL                 SELECT t.column_abc1, t.column_abc2, t.column_abc3, tcte.lv + 1                 FROM table_abc1 t                 JOIN tree_cte tcte ON t.column_abc1 = tcte.column_abc2                 WHERE tcte.lv <= 1             )             SELECT * FROM tree_cte         )         SELECT  e.column_abc5         FROM (             SELECT DISTINCT * FROM tree_cte1         ) aa         LEFT JOIN table_abc4 e ON e.column_abc3 = aa.column_abc3     ) a )"] [txn_mode=PESSIMISTIC] [timestamp=452111520359514125] [err="runtime error: invalid memory address or nil pointer dereference\ngithub.com/pingcap/errors.AddStack\n\t/home/xhy/Development/Golang/GOPATH/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20240318064555-6bd07397691f/errors.go:178\ngithub.com/pingcap/errors.Trace\n\t/home/xhy/Development/Golang/GOPATH/pkg/mod/github.com/pingcap/errors@v0.11.5-0.20240318064555-6bd07397691f/juju_adaptor.go:15\ngithub.com/pingcap/tidb/pkg/util.GetRecoverError\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/util/util.go:288\ngithub.com/pingcap/tidb/pkg/executor/internal/exec.Next.func1\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/internal/exec/executor.go:435\nruntime.gopanic\n\t/home/xhy/.gvm/gos/go1.21.5/src/runtime/panic.go:914\nruntime.panicmem\n\t/home/xhy/.gvm/gos/go1.21.5/src/runtime/panic.go:261\nruntime.sigpanic\n\t/home/xhy/.gvm/gos/go1.21.5/src/runtime/signal_unix.go:861\ngithub.com/pingcap/tidb/pkg/executor.(*DeleteExec).deleteOneRow\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/delete.go:70\ngithub.com/pingcap/tidb/pkg/executor.(*DeleteExec).deleteSingleTableByChunk\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/delete.go:140\ngithub.com/pingcap/tidb/pkg/executor.(*DeleteExec).Next\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/delete.go:62\ngithub.com/pingcap/tidb/pkg/executor/internal/exec.Next\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/internal/exec/executor.go:451\ngithub.com/pingcap/tidb/pkg/executor.(*ExecStmt).next\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/adapter.go:1252\ngithub.com/pingc
ap/tidb/pkg/executor.(*ExecStmt).handleNoDelayExecutor\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/adapter.go:1001\ngithub.com/pingcap/tidb/pkg/executor.(*
ExecStmt).handleNoDelay\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/executor/adapter.go:834\ngithub.com/pingcap/tidb/pkg/executor.(*ExecStmt).Exec\n\t/home/xhy/Deve
lopment/github.com/pingcap/tidb/pkg/executor/adapter.go:598\ngithub.com/pingcap/tidb/pkg/session.runStmt\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/session/session
.go:2284\ngithub.com/pingcap/tidb/pkg/session.(*session).ExecuteStmt\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/session/session.go:2145\ngithub.com/pingcap/tidb/pk
g/server.(*TiDBContext).ExecuteStmt\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/server/driver_tidb.go:291\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleSt
mt\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/server/conn.go:2056\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).handleQuery\n\t/home/xhy/Development/github.com
/pingcap/tidb/pkg/server/conn.go:1810\ngithub.com/pingcap/tidb/pkg/server.(*clientConn).dispatch\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/server/conn.go:1384\ngi
thub.com/pingcap/tidb/pkg/server.(*clientConn).Run\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/server/conn.go:1146\ngithub.com/pingcap/tidb/pkg/server.(*Server).onC
onn\n\t/home/xhy/Development/github.com/pingcap/tidb/pkg/server/server.go:741\nruntime.goexit\n\t/home/xhy/.gvm/gos/go1.21.5/src/runtime/asm_amd64.s:1650"]
[2024/08/26 18:36:37.383 +08:00] [INFO] [domain.go:3156] ["instance plan eviction"] [detail="memory usage is below the soft limit, currentTot: 0, softLimit: 104857600"] [num
_evicted=0] [time_spent=850ns]

4. What is your TiDB version? (Required)

nightly

XuHuaiyu commented 2 months ago

img_v3_02e6_459b1991-32ef-4fbb-a267-b69d2938836g

img_v3_02e6_aadd7e01-2d5a-4281-9018-a4def052248g

XuHuaiyu commented 2 months ago
+-------------------------------------+----------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id                                  | estRows  | task      | access object | operator info                                                                                                                                                                       |
+-------------------------------------+----------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Delete_45                           | N/A      | root      |               | N/A                                                                                                                                                                                 |
| └─HashJoin_66                       | 45.00    | root      |               | inner join, equal:[eq(test.table_abc3.column_abc5, test.table_abc4.column_abc5)]                                                                                                    |
|   ├─HashAgg_71(Build)               | 36.00    | root      |               | group by:test.table_abc4.column_abc5, funcs:firstrow(test.table_abc4.column_abc5)->test.table_abc4.column_abc5                                                                      |
|   │ └─HashJoin_73                   | 36.00    | root      |               | inner join, equal:[eq(test.table_abc1.column_abc3, test.table_abc4.column_abc3)]                                                                                                    |
|   │   ├─HashAgg_74(Build)           | 28.80    | root      |               | group by:Column#69, test.table_abc1.column_abc1, test.table_abc1.column_abc2, test.table_abc1.column_abc3, funcs:firstrow(test.table_abc1.column_abc3)->test.table_abc1.column_abc3 |
|   │   │ └─Selection_75              | 32.00    | root      |               | not(isnull(test.table_abc1.column_abc3))                                                                                                                                            |
|   │   │   └─CTEFullScan_76          | 40.00    | root      | CTE:tree_cte  | data:CTE_2                                                                                                                                                                          |
|   │   └─TableReader_79(Probe)       | 9980.01  | root      |               | data:Selection_78                                                                                                                                                                   |
|   │     └─Selection_78              | 9980.01  | cop[tikv] |               | not(isnull(test.table_abc4.column_abc3)), not(isnull(test.table_abc4.column_abc5))                                                                                                  |
|   │       └─TableFullScan_77        | 10000.00 | cop[tikv] | table:e       | keep order:false, stats:pseudo                                                                                                                                                      |
|   └─TableReader_70(Probe)           | 9990.00  | root      |               | data:Selection_69                                                                                                                                                                   |
|     └─Selection_69                  | 9990.00  | cop[tikv] |               | not(isnull(test.table_abc3.column_abc5))                                                                                                                                            |
|       └─TableFullScan_68            | 10000.00 | cop[tikv] | table:t_abc3  | keep order:false, stats:pseudo                                                                                                                                                      |
| CTE_2                               | 40.00    | root      |               | Recursive CTE                                                                                                                                                                       |
| ├─Projection_47(Seed Part)          | 20.00    | root      |               | test.table_abc1.column_abc1, test.table_abc1.column_abc2, test.table_abc1.column_abc3, 0->Column#52                                                                                 |
| │ └─TableReader_50                  | 20.00    | root      |               | data:Selection_49                                                                                                                                                                   |
| │   └─Selection_49                  | 20.00    | cop[tikv] |               | in(test.table_abc1.column_abc1, "KTL157", "KTL159")                                                                                                                                 |
| │     └─TableFullScan_48            | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                                                                                                                                                      |
| └─Projection_54(Recursive Part)     | 20.00    | root      |               | test.table_abc1.column_abc1, test.table_abc1.column_abc2, test.table_abc1.column_abc3, cast(plus(Column#60, 1), bigint(1) BINARY)->Column#65                                        |
|   └─Projection_55                   | 20.00    | root      |               | test.table_abc1.column_abc1, test.table_abc1.column_abc2, test.table_abc1.column_abc3, Column#60                                                                                    |
|     └─HashJoin_57                   | 20.00    | root      |               | inner join, equal:[eq(test.table_abc1.column_abc2, test.table_abc1.column_abc1)]                                                                                                    |
|       ├─Selection_58(Build)         | 16.00    | root      |               | le(Column#60, 1), not(isnull(test.table_abc1.column_abc2))                                                                                                                          |
|       │ └─CTETable_59               | 20.00    | root      |               | Scan on CTE_2                                                                                                                                                                       |
|       └─TableReader_62(Probe)       | 9990.00  | root      |               | data:Selection_61                                                                                                                                                                   |
|         └─Selection_61              | 9990.00  | cop[tikv] |               | not(isnull(test.table_abc1.column_abc1))                                                                                                                                            |
|           └─TableFullScan_60        | 10000.00 | cop[tikv] | table:t       | keep order:false, stats:pseudo                                                                                                                                                      |
+-------------------------------------+----------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+