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

runtime error: index out of range [1] with length 1 on SELECT #43256

Open
DerZc opened this issue Apr 20, 2023 · 2 comments
Open

runtime error: index out of range [1] with length 1 on SELECT #43256

DerZc opened this issue Apr 20, 2023 · 2 comments
Labels
fuzz/sqlancer 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 may-affects-7.1 severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@DerZc
Copy link

DerZc commented Apr 20, 2023

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

The following program triggers a runtime error in CLI:

USE test;
DROP DATABASE IF EXISTS database41;
CREATE DATABASE database41;
USE database41;
CREATE TABLE t0(c0 DECIMAL );
REPLACE INTO t0 VALUES (0.4117160754744159);
CREATE VIEW v0(c0) AS SELECT NULL FROM t0 WHERE t0.c0;

SELECT v0.c0, t0.c0 FROM  v0 RIGHT  OUTER JOIN t0 ON ((v0.c0)LIKE(v0.c0)) WHERE ((v0.c0)OR( NOT EXISTS(SELECT v0.c0 AS c0 FROM v0, t0)));

This is the error message:

ERROR 1105 (HY000) at line 24: runtime error: index out of range [1] with length 1

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

No error.

3. What did you see instead (Required)

A runtime error.

4. What is your TiDB version? (Required)

Release Version: v7.1.0-alpha-298-g9fcf6b962\nEdition: Community\nGit Commit Hash: 9fcf6b9629a140c3beb37928a2012eaa310973ce\nGit Branch: master\nUTC Build Time: 2023-04-20 12:25:51\nGoVersion: go1.20.3\nRace Enabled: false\nTiKV Min Version: 6.2.0-alpha\nCheck Table Before Drop: false\nStore: unistore
@DerZc DerZc added the type/bug The issue is confirmed as a bug. label Apr 20, 2023
@ti-chi-bot ti-chi-bot bot added 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 may-affects-7.1 labels Apr 23, 2023
@zanmato1984
Copy link
Contributor

Error in log:

[2023/04/23 06:49:14.064 +00:00] [INFO] [conn.go:1151] ["command dispatched failed"] [conn=6224324329723658647] [connInfo="id:6224324329723658647, addr:172.18.0.1:56346 status:10, collation:utf8mb4_general_ci, user:root"] [command=Query] [status="inTxn:0, autocommit:1"] [sql="SELECT v0.c0, t0.c0 FROM v0 RIGHT OUTER JOIN t0 ON ((v0.c0)LIKE(v0.c0)) WHERE ((v0.c0)OR( NOT EXISTS(SELECT v0.c0 AS c0 FROM v0, t0)))"] [txn_mode=PESSIMISTIC] [timestamp=440987170642591746] [err="runtime error: index out of range [1] with length 1\ngithub.com/pingcap/tidb/executor.(*recordSet).Next.func1\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:146\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:884\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:113\ngithub.com/pingcap/tidb/util/chunk.appendCellByCell\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/chunk.go:421\ngithub.com/pingcap/tidb/util/chunk.(*Chunk).AppendPartialRow\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/chunk.go:381\ngithub.com/pingcap/tidb/util/chunk.(*Chunk).AppendRow\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/util/chunk/chunk.go:372\ngithub.com/pingcap/tidb/executor.(*SelectionExec).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/executor.go:1663\ngithub.com/pingcap/tidb/executor.Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/executor.go:326\ngithub.com/pingcap/tidb/executor.(*ExecStmt).next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:1194\ngithub.com/pingcap/tidb/executor.(*recordSet).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/executor/adapter.go:150\ngithub.com/pingcap/tidb/server.(*tidbResultSet).Next\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/driver_tidb.go:428\ngithub.com/pingcap/tidb/server.(*clientConn).writeChunks\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2275\ngithub.com/pingcap/tidb/server.(*clientConn).writeResultSet\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2218\ngithub.com/pingcap/tidb/server.(*clientConn).handleStmt\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:2091\ngithub.com/pingcap/tidb/server.(*clientConn).handleQuery\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1852\ngithub.com/pingcap/tidb/server.(*clientConn).dispatch\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1339\ngithub.com/pingcap/tidb/server.(*clientConn).Run\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/conn.go:1120\ngithub.com/pingcap/tidb/server.(*Server).onConn\n\t/home/jenkins/agent/workspace/build-common/go/src/github.com/pingcap/tidb/server/server.go:677\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_arm64.s:1172"]

Seems like the chunk to filter lacks the tailing offset element (offset array is one more element than data array).

Downgrading to moderate.

@guo-shaoge
Copy link
Collaborator

guo-shaoge commented Jul 2, 2023

The plan:

+-------------------------------+---------+-----------+---------------+--------------------------------------------------------+
| id                            | estRows | task      | access object | operator info                                          |
+-------------------------------+---------+-----------+---------------+--------------------------------------------------------+
| Selection_28                  | 0.80    | root      |               | or(istrue_with_null(cast(Column#3, double BINARY)), 1) |
| └─HashJoin_29                 | 1.00    | root      |               | CARTESIAN right outer join                             |
|   ├─Projection_31(Build)      | 0.80    | root      |               | <nil>->Column#3                                        |
|   │ └─TableDual_32            | 0.80    | root      |               | rows:0                                                 |
|   └─TableReader_34(Probe)     | 1.00    | root      |               | data:TableFullScan_33                                  |
|     └─TableFullScan_33        | 1.00    | cop[tikv] | table:t0      | keep order:false                                       |
+-------------------------------+---------+-----------+---------------+--------------------------------------------------------+
6 rows in set (0.005 sec)

output chunk of HashJoin_29 is as following: the first datum is error, because it's a NULL datum, so it should be a fixed datum, but its elemBuf is nil, so the chunk append logic assume it's variable length. So we got panic in chunk append logic which is called by Selection_28(code)

(dlv) p e.childResult.columns
[]*github.com/pingcap/tidb/util/chunk.Column len: 2, cap: 2, [
	*{
		length: 1,
		nullBitmap: []uint8 len: 1, cap: 4, [0],
		offsets: []int64 len: 1, cap: 33, [0],
		data: []uint8 len: 8, cap: 256, [0,0,0,0,0,0,0,0],
		elemBuf: []uint8 len: 0, cap: 0, nil,
		avoidReusing: false,},
	*{
		length: 1,
		nullBitmap: []uint8 len: 1, cap: 4, [1],
		offsets: []int64 len: 0, cap: 0, nil,
		data: []uint8 len: 40, cap: 1280, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
		elemBuf: []uint8 len: 40, cap: 40, [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],
		avoidReusing: false,},

This happens when we copy default null datum to the join row, chunk.elemBuf is missed.

Before copy, the default null datum(j.defaultInner):

	*{
		length: 1,
		nullBitmap: []uint8 len: 1, cap: 1, [0],
		offsets: []int64 len: 0, cap: 0, nil,
		data: []uint8 len: 8, cap: 8, [0,0,0,0,0,0,0,0],
		elemBuf: []uint8 len: 8, cap: 8, [0,0,0,0,0,0,0,0],
		avoidReusing: false,},

After copy:

	*{
		length: 1,
		nullBitmap: []uint8 len: 1, cap: 4, [0],
		offsets: []int64 len: 1, cap: 33, [0],
		data: []uint8 len: 8, cap: 256, [0,0,0,0,0,0,0,0],
		elemBuf: []uint8 len: 0, cap: 0, nil,
		avoidReusing: false,},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzz/sqlancer 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 may-affects-7.1 severity/moderate sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

5 participants