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

P1-[4.0 bug hunting]-[SQL Plan Management]-Incorrect result or run-time error after changing column type #17812

Closed
sre-bot opened this issue Jun 5, 2020 · 4 comments
Assignees
Labels
priority/P1 The issue has P1 priority. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@sre-bot
Copy link
Contributor

sre-bot commented Jun 5, 2020

Bug Hunter issue tidb-challenge-program/bug-hunting-issue#10


Consider the following statements:

CREATE TABLE t0(c0 INT, c1 DECIMAL UNIQUE);
CREATE TABLE t1(c0 INT);
INSERT INTO t0(c1) VALUES (0), (1);
INSERT INTO t1(c0) VALUES (0);
ALTER TABLE t0 MODIFY c1 INT;
SELECT t1.c0 FROM t1, t0 WHERE t0.c1; -- expected: {0}, actual: {0, 0}

Unexpectedly, the SELECT fetches two rows. I would expect only a single one to be fetched. Furthermore, when dropping the UNIQUE constraint, the query fails with an error:

mysql> CREATE TABLE t0(c0 INT, c1 DECIMAL);
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE t1(c0 INT);
Query OK, 0 rows affected (0.00 sec)

mysql> INSERT INTO t0(c1) VALUES (0), (1);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> INSERT INTO t1(c0) VALUES (0);
Query OK, 1 row affected (0.00 sec)

mysql> ALTER TABLE t0 MODIFY c1 INT;
Query OK, 0 rows affected (0.01 sec)

mysql> SELECT t1.c0 FROM t1, t0 WHERE t0.c1; -- expected: {0}, actual: {1}
ERROR 1105 (HY000): runtime error: index out of range [7] with length 7

Environment:

| Release Version: v4.0.0-beta.2-231-gc66320c46
Git Commit Hash: c66320c46456c0d5b23b3b0403be6b9f8227d6d8
Git Branch: master
UTC Build Time: 2020-04-14 11:12:29
GoVersion: go1.13.4
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false |

An incorrect query result seems to qualify as a P0 bug, according to https://github.com/pingcap/community/blob/master/bug-hunting-programs/bug-hunting-program.md.

@sre-bot sre-bot added the type/bug The issue is confirmed as a bug. label Jun 5, 2020
@djshow832 djshow832 added the sig/planner SIG: Planner label Jun 5, 2020
@qw4990 qw4990 added component/executor severity/critical help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Aug 26, 2020
@fzhedu fzhedu added the priority/P1 The issue has P1 priority. label Aug 27, 2020
@eurekaka eurekaka self-assigned this Aug 28, 2020
@eurekaka
Copy link
Contributor

Looks like we cannot support converting a decimal type column to int type without modifying the underlying data, otherwise the decoder would not work as expected.

runtime.goPanicIndex
	/usr/local/go/src/runtime/panic.go:75
encoding/binary.littleEndian.Uint64
	/usr/local/go/src/encoding/binary/binary.go:76
github.com/pingcap/tidb/util/rowcodec.decodeInt
	/root/go/src/github.com/pingcap/tidb/util/rowcodec/common.go:119
github.com/pingcap/tidb/util/rowcodec.(*ChunkDecoder).decodeColToChunk
	/root/go/src/github.com/pingcap/tidb/util/rowcodec/decoder.go:274
github.com/pingcap/tidb/util/rowcodec.(*ChunkDecoder).DecodeToChunk
	/root/go/src/github.com/pingcap/tidb/util/rowcodec/decoder.go:218
github.com/pingcap/tidb/store/mockstore/unistore/cophandler.(*closureExecutor).tableScanProcessCore
	/root/go/src/github.com/pingcap/tidb/store/mockstore/unistore/cophandler/closure_exec.go:590
github.com/pingcap/tidb/store/mockstore/unistore/cophandler.(*tableScanProcessor).Process
	/root/go/src/github.com/pingcap/tidb/store/mockstore/unistore/cophandler/closure_exec.go:511
github.com/ngaut/unistore/tikv/dbreader.(*DBReader).Scan
	/root/go/pkg/mod/github.com/ngaut/unistore@v0.0.0-20200826054345-a70ab8a1f698/tikv/dbreader/db_reader.go:209
github.com/pingcap/tidb/store/mockstore/unistore/cophandler.(*closureExecutor).execute
	/root/go/src/github.com/pingcap/tidb/store/mockstore/unistore/cophandler/closure_exec.go:385
github.com/pingcap/tidb/store/mockstore/unistore/cophandler.handleCopDAGRequest
	/root/go/src/github.com/pingcap/tidb/store/mockstore/unistore/cophandler/cop_handler.go:79
github.com/pingcap/tidb/store/mockstore/unistore/cophandler.HandleCopRequest
	/root/go/src/github.com/pingcap/tidb/store/mockstore/unistore/cophandler/cop_handler.go:47

@zimulala PTAL

@eurekaka
Copy link
Contributor

eurekaka commented Aug 28, 2020

A minimal repro:

CREATE TABLE t0(c0 INT, c1 DECIMAL);
INSERT INTO t0(c1) VALUES (0), (1);
ALTER TABLE t0 MODIFY c1 INT;
select c1 from t0;

@eurekaka eurekaka added sig/sql-infra SIG: SQL Infra and removed component/executor sig/planner SIG: Planner help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. labels Aug 28, 2020
@eurekaka eurekaka assigned zimulala and unassigned eurekaka Aug 28, 2020
@bb7133
Copy link
Member

bb7133 commented Aug 29, 2020

Changing DECIMAL to INT is actually not supported. The bug is about a missing error check.

@bb7133
Copy link
Member

bb7133 commented Sep 2, 2020

It is closed by #19645

@bb7133 bb7133 closed this as completed Sep 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/P1 The issue has P1 priority. severity/critical sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests

7 participants