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

Unexpected query result with server error #24045

Closed
hidehalo opened this issue Apr 15, 2021 · 1 comment · Fixed by #24204
Closed

Unexpected query result with server error #24045

hidehalo opened this issue Apr 15, 2021 · 1 comment · Fixed by #24204

Comments

@hidehalo
Copy link
Contributor

hidehalo commented Apr 15, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. build & run tidb server locally.
  2. execute sqls below:
use test;
drop table if EXISTS student;

create table student(
    id int not null auto_increment,
    `name` varchar(128) not null default "",
    age integer not null default 0,
    sex tinyint not null default 0,
    primary key (id)
);

drop table if EXISTS sc;

create table sc(
    id int not null auto_increment,
    student_id int not null default 0,
    course_id int not null default 0,
    score int not null default 0,
    primary key (id)
);

insert into student (`name`, `age`, `sex`) VALUES 
("student_0", 22, 1),
("student_1", 22, 1),
("student_2", 22, 1),
("student_3", 22, 1),
("student_4", 22, 1),
("student_5", 22, 1),
("student_6", 22, 1),
("student_7", 22, 1),
("student_8", 22, 1);

insert into sc (`student_id`, `course_id`, `score`) VALUES 
    (1, 1, 59),
    (1, 2, 98),
    (1, 3, 76),
    (2, 1, 99),
    (2, 2, 100),
    (2, 3, 100),
    (3, 1, 10),
    (3, 2, 100),
    (3, 3, 59),
    (4, 1, 40),
    (4, 2, 25),
    (4, 3, 0),
    (5, 1, 66),
    (5, 2, 70),
    (5, 3, 62),
    (6, 1, 80),
    (6, 2, 68),
    (6, 3, 45),
    (7, 1, 33),
    (7, 2, 100),
    (7, 3, 54),
    (8, 1, 23),
    (8, 2, 0),
    (8, 3, 5);

select `a`.`id`, `a`.`name`, avg(`b`.`score`) as avg_failed_score from student a 
join sc b 
on `a`.`id` = `b`.`student_id`
where `b`.`score` < 60
group by `a`.`id`
having count(distinct `b`.`course_id`) >= 2;

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

id	name	avg_failed_score
3	student_2	34.5000
4	student_3	21.6667
7	student_6	43.5000
8	student_7	9.3333

3. What did you see instead (Required)

runtime error: index out of range [-1]

error trace:

[2021/04/15 15:27:36.823 +08:00] [ERROR] [conn.go:802] ["connection running loop panic"] [conn=13] [lastSQL="select `a`.`id`, `a`.`name`, avg(`b`.`score`) as avg_failed_score from student a 
join sc b 
on `a`.`id` = `b`.`student_id`
where `b`.`score` < 60
group by `a`.`id`
having count(distinct `b`.`course_id`) >= 2"] [err="runtime error: index out of range [-1]"] [stack="goroutine 15360 [running]:
github.com/pingcap/tidb/server.(*clientConn).Run.func1(0x698e780, 0xc010970720, 0xc01083f600)
	/tidb/server/conn.go:800 +0xf5
panic(0x635be60, 0xc01134b120)
	/usr/local/Cellar/go/1.15.5/libexec/src/runtime/panic.go:969 +0x1b9
github.com/pingcap/tidb/planner/core.(*LogicalProjection).TryToGetChildProp(0xc01139c620, 0xc0113ab110, 0x69ac201, 0x4057efebf22c01e6)
	/tidb/planner/core/exhaust_physical_plans.go:1930 +0x38d
github.com/pingcap/tidb/planner/core.(*LogicalProjection).exhaustPhysicalPlans(0xc01139c620, 0xc0113ab110, 0xc011338f80, 0x29, 0x827be00, 0xc01136d301)
	/tidb/planner/core/exhaust_physical_plans.go:1942 +0x50
github.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc01139c640, 0xc0113aab60, 0x7bdd270, 0x0, 0x0, 0x0, 0x0, 0x0)
	/tidb/planner/core/find_best_task.go:310 +0x1d4
github.com/pingcap/tidb/planner/core.(*baseLogicalPlan).enumeratePhysicalPlans4Task(0xc0113a2160, 0xc0113ae5d0, 0x2, 0x3, 0xc0113aa4d0, 0xc01136d300, 0x7bdd270, 0x10, 0x62793c0, 0x9e86108, ...)
	/tidb/planner/core/find_best_task.go:213 +0x71b
github.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc0113a2160, 0xc0113aa460, 0x7bdd270, 0x0, 0x0, 0x0, 0x0, 0x0)
	/tidb/planner/core/find_best_task.go:343 +0x32d
github.com/pingcap/tidb/planner/core.(*baseLogicalPlan).enumeratePhysicalPlans4Task(0xc011345800, 0xc01136d300, 0x1, 0x1, 0xc0113aa3f0, 0xc01136d200, 0x7bdd270, 0x10, 0x62793c0, 0x0, ...)
	/tidb/planner/core/find_best_task.go:213 +0x71b
github.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc011345800, 0xc0113aa380, 0x7bdd270, 0x0, 0x0, 0x0, 0x0, 0x0)
	/tidb/planner/core/find_best_task.go:343 +0x32d
github.com/pingcap/tidb/planner/core.(*baseLogicalPlan).enumeratePhysicalPlans4Task(0xc01139c560, 0xc01136d2e0, 0x1, 0x1, 0xc0113aa310, 0xc0113aa200, 0xc012961de0, 0x68, 0x639dd00, 0xc0109ec390, ...)
	/tidb/planner/core/find_best_task.go:213 +0x71b
github.com/pingcap/tidb/planner/core.(*baseLogicalPlan).findBestTask(0xc01139c560, 0xc0113aa2a0, 0xc012961de0, 0x0, 0x0, 0x0, 0x0, 0x0)
	/tidb/planner/core/find_best_task.go:343 +0x32d
github.com/pingcap/tidb/planner/core.physicalOptimize(0x69cfd20, 0xc01139c540, 0xc012961de0, 0x69cfd20, 0xc01139c540, 0x69cfd20, 0xc01139c540, 0x0)
	/tidb/planner/core/optimizer.go:232 +0x131
github.com/pingcap/tidb/planner/core.DoOptimize(0x698e780, 0xc01138f560, 0x69d1520, 0xc010993cc0, 0x1cf6, 0x69cfd20, 0xc01139c540, 0x0, 0x0, 0x0, ...)
	/tidb/planner/core/optimizer.go:151 +0x145
github.com/pingcap/tidb/planner.optimize(0x698e780, 0xc01138f560, 0x69d1520, 0xc010993cc0, 0x69a55a0, 0xc01133ec00, 0x69c9140, 0xc0111d0be0, 0x0, 0x0, ...)
	/tidb/planner/optimize.go:289 +0x77f
github.com/pingcap/tidb/planner.Optimize(0x698e780, 0xc01138f560, 0x69d1520, 0xc010993cc0, 0x69a55a0, 0xc01133ec00, 0x69c9140, 0xc0111d0be0, 0x0, 0x0, ...)
	/tidb/planner/optimize.go:125 +0x4a9
github.com/pingcap/tidb/executor.(*Compiler).Compile(0xc0109ecda8, 0x698e780, 0xc01138f560, 0x69ab9c0, 0xc01133ec00, 0x0, 0x0, 0x0)
	/tidb/executor/compiler.go:62 +0x305
github.com/pingcap/tidb/session.(*session).ExecuteStmt(0xc010993cc0, 0x698e780, 0xc01138f560, 0x69ab9c0, 0xc01133ec00, 0x0, 0x0, 0x0, 0x0)
	/tidb/session/session.go:1409 +0x3d2
github.com/pingcap/tidb/server.(*TiDBContext).ExecuteStmt(0xc010970b40, 0x698e780, 0xc01138f560, 0x69ab9c0, 0xc01133ec00, 0xc01134ade0, 0x698e780, 0xc01138f560, 0x0)
	/Use"]

4. What is your TiDB version? (Required)

Release Version: v4.0.0-beta.2-2634-ga53cf4207
Edition: Community
Git Commit Hash: a53cf42
Git Branch: HEAD
UTC Build Time: 2021-04-15 07:17:00
GoVersion: go1.15.5
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

@hidehalo hidehalo added the type/bug This issue is a bug. label Apr 15, 2021
@XuHuaiyu XuHuaiyu added the sig/planner SIG: Planner label Apr 15, 2021
@github-actions github-actions bot added this to Issue Backlog: Need Triage in SIG Planner Kanban Apr 15, 2021
@eurekaka eurekaka self-assigned this Apr 21, 2021
SIG Planner Kanban automation moved this from Issue Backlog: Need Triage to Coding Finished (This Week) Apr 28, 2021
@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SIG Planner Kanban
  
Coding Finished (This Week)
Development

Successfully merging a pull request may close this issue.

5 participants