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

index out of range [0] with length 0 in query #40184

Closed
wjhuang2016 opened this issue Dec 27, 2022 · 4 comments
Closed

index out of range [0] with length 0 in query #40184

wjhuang2016 opened this issue Dec 27, 2022 · 4 comments
Assignees
Labels
affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 fuzz/schrddl may-affects-5.0 This bug maybe affects 5.0.x versions. 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. severity/major type/bug The issue is confirmed as a bug.

Comments

@wjhuang2016
Copy link
Member

wjhuang2016 commented Dec 27, 2022

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `f9cd1880-d4c8-4d95-b519-5b858953b829` (
  `f2bfbdda-9859-44c1-827e-6b6aca095387` int(11) NOT NULL DEFAULT '-1534562528',
  `673b73f3-1f17-4259-b829-d3b45901d6ef` int(11) NOT NULL DEFAULT '2080417292',
  PRIMARY KEY (`f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_chinese_ci COMMENT='3f9190e9-983e-4018-9e06-dd310645d883'
PARTITION BY HASH (`f2bfbdda-9859-44c1-827e-6b6aca095387`) PARTITIONS 3;
insert into `f9cd1880-d4c8-4d95-b519-5b858953b829` values (1248018841, 250053474);
select nth_value( `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` , 4 ) over
w as r0 , sum( distinct  `f9cd1880-d4c8-4d95-b519-5b858953b829`.`673b73f3-1f17-4259-b829-d3b45901d6ef` ) as r1 from `f9cd1880-d4c8-4d95-b519-5b858953b829`  group by `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` window w as ( partition by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef` order by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef`  ) order by r0,r1 limit 32;

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

no error

3. What did you see instead (Required)

index out of range [0] with length 0

4. What is your TiDB version? (Required)

master

@wjhuang2016 wjhuang2016 added the type/bug The issue is confirmed as a bug. label Dec 27, 2022
@ti-chi-bot ti-chi-bot added may-affects-4.0 This bug maybe affects 4.0.x versions. may-affects-5.0 This bug maybe affects 5.0.x versions. 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.0 may-affects-6.1 may-affects-6.2 may-affects-6.3 may-affects-6.4 labels Dec 27, 2022
@seiya-annie seiya-annie removed the may-affects-4.0 This bug maybe affects 4.0.x versions. label Dec 27, 2022
@zanmato1984
Copy link
Contributor

Can't reproduce.

Version:

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v6.6.0-alpha
Edition: Community
Git Commit Hash: 2f6401a094bca4583e20ace3c166239aca9c4ffb
Git Branch: heads/refs/tags/v6.6.0-alpha
UTC Build Time: 2022-12-26 11:49:38
GoVersion: go1.19.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Result:

mysql> select nth_value( `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` , 4 ) over
    -> w as r0 , sum( distinct  `f9cd1880-d4c8-4d95-b519-5b858953b829`.`673b73f3-1f17-4259-b829-d3b45901d6ef` ) as r1 from `f9cd1880-d4c8-4d95-b519-5b858953b829`  group by `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` window w as ( partition by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef` order by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef`  ) order by r0,r1 limit 32;w as r0 , sum( distinct  `f9cd1880-d4c8-4d95-b519-5b858953b829`.`673b73f3-1f17-4259-b829-d3b45901d6ef` ) as r1 from `f9cd1880-d4c8-4d95-b519-5b858953b829`  group by `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` window w as ( partition by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef` order by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef`  ) order by r0,r1 limit 32;
Empty set, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+-----------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                 |
+---------+------+-----------------------------------------------------------------------------------------+
| Warning | 1105 | disable dynamic pruning due to f9cd1880-d4c8-4d95-b519-5b858953b829 has no global stats |
+---------+------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

@zanmato1984 zanmato1984 added sig/sql-infra SIG: SQL Infra and removed sig/execution SIG execution labels Dec 27, 2022
@wjhuang2016
Copy link
Member Author

Can't reproduce.

Version:

+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                                                           |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v6.6.0-alpha
Edition: Community
Git Commit Hash: 2f6401a094bca4583e20ace3c166239aca9c4ffb
Git Branch: heads/refs/tags/v6.6.0-alpha
UTC Build Time: 2022-12-26 11:49:38
GoVersion: go1.19.3
Race Enabled: false
TiKV Min Version: 6.2.0-alpha
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

Result:

mysql> select nth_value( `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` , 4 ) over
    -> w as r0 , sum( distinct  `f9cd1880-d4c8-4d95-b519-5b858953b829`.`673b73f3-1f17-4259-b829-d3b45901d6ef` ) as r1 from `f9cd1880-d4c8-4d95-b519-5b858953b829`  group by `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` window w as ( partition by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef` order by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef`  ) order by r0,r1 limit 32;w as r0 , sum( distinct  `f9cd1880-d4c8-4d95-b519-5b858953b829`.`673b73f3-1f17-4259-b829-d3b45901d6ef` ) as r1 from `f9cd1880-d4c8-4d95-b519-5b858953b829`  group by `f9cd1880-d4c8-4d95-b519-5b858953b829`.`f2bfbdda-9859-44c1-827e-6b6aca095387` window w as ( partition by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef` order by `f2bfbdda-9859-44c1-827e-6b6aca095387`,`673b73f3-1f17-4259-b829-d3b45901d6ef`  ) order by r0,r1 limit 32;
Empty set, 1 warning (0.01 sec)

mysql> show warnings;
+---------+------+-----------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                 |
+---------+------+-----------------------------------------------------------------------------------------+
| Warning | 1105 | disable dynamic pruning due to f9cd1880-d4c8-4d95-b519-5b858953b829 has no global stats |
+---------+------+-----------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

I added a row and please try again,

@mjonss
Copy link
Contributor

mjonss commented Dec 27, 2022

Reproducible unit test:

func TestIssue40184(t *testing.T) {
	store := testkit.CreateMockStore(t)
	tk := testkit.NewTestKit(t, store)
	tk.MustExec("use test")
	tk.MustExec("CREATE TABLE `t` ( `a` int(11) NOT NULL DEFAULT '-1534562528', `b` int(11) NOT NULL DEFAULT '2080417292', PRIMARY KEY (`a`,`b`) /*T![clustered_index] CLUSTERED */) ENGINE=InnoDB DEFAULT CHARSET=gbk COLLATE=gbk_chinese_ci PARTITION BY HASH (`a`) PARTITIONS 3")
	tk.MustExec("insert into `t` values (1248018841, 250053474)")
	tk.MustQuery("select nth_value( `t`.`a` , 4 ) over\nw as r0 , sum( distinct  `t`.`b` ) as r1 from `t`  group by `t`.`a` window w as ( partition by `a`,`b` order by `a`,`b`  ) order by r0,r1 limit 32;\n")
}

Error stack:

runtime error: index out of range [0] with length 0
github.com/pingcap/tidb/executor.recoveryShuffleExec
	pingcap/repos/tidb/executor/shuffle.go:255
github.com/pingcap/tidb/executor.(*ShuffleExec).fetchDataAndSplit.func1
	pingcap/repos/tidb/executor/shuffle.go:269
runtime.gopanic
	/usr/local/go/src/runtime/panic.go:890
runtime.goPanicIndex
	/usr/local/go/src/runtime/panic.go:113
github.com/pingcap/tidb/util/chunk.(*Column).IsNull
	pingcap/repos/tidb/util/chunk/column.go:169
github.com/pingcap/tidb/util/codec.HashGroupKey
	pingcap/repos/tidb/util/codec/codec.go:1235
github.com/pingcap/tidb/executor.getGroupKey
	pingcap/repos/tidb/executor/aggregate.go:598
github.com/pingcap/tidb/executor.(*HashAggExec).execute
	pingcap/repos/tidb/executor/aggregate.go:1023
github.com/pingcap/tidb/executor.(*HashAggExec).unparallelExec
	pingcap/repos/tidb/executor/aggregate.go:966
github.com/pingcap/tidb/executor.(*HashAggExec).Next
	pingcap/repos/tidb/executor/aggregate.go:785
github.com/pingcap/tidb/executor.Next
	pingcap/repos/tidb/executor/executor.go:328
github.com/pingcap/tidb/executor.(*ShuffleExec).fetchDataAndSplit
	pingcap/repos/tidb/executor/shuffle.go:277
runtime.goexit
	/usr/local/go/src/runtime/asm_arm64.s:1172

@mjonss mjonss added sig/planner SIG: Planner and removed sig/sql-infra SIG: SQL Infra labels Dec 30, 2022
@chrysan chrysan assigned winoros and unassigned winoros Jan 4, 2023
@chrysan chrysan added sig/execution SIG execution and removed sig/planner SIG: Planner labels Jan 4, 2023
@wshwsh12 wshwsh12 self-assigned this Jan 12, 2023
@ywqzzy
Copy link
Contributor

ywqzzy commented Jan 30, 2023

Same with #40470

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.0 affects-6.1 This bug affects the 6.1.x(LTS) versions. affects-6.2 affects-6.3 affects-6.4 fuzz/schrddl may-affects-5.0 This bug maybe affects 5.0.x versions. 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. severity/major type/bug The issue is confirmed as a bug.
Projects
None yet
Development

No branches or pull requests