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

Aggregation distinct function panic when distinct_agg_push_down and enable_cascades_planner #24449

Open
lilinghai opened this issue May 7, 2021 · 4 comments · May be fixed by #26386
Open

Aggregation distinct function panic when distinct_agg_push_down and enable_cascades_planner #24449

lilinghai opened this issue May 7, 2021 · 4 comments · May be fixed by #26386
Assignees
Labels
severity/minor sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@lilinghai
Copy link
Contributor

lilinghai commented May 7, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

create table t(a int);
insert into t values(-1);
set @@tidb_opt_distinct_agg_push_down=on;
set @@tidb_enable_cascades_planner=on;
select count(*) from t group by a having avg(distinct a)>1;

The query plan is

+--------------------------------+---------+-----------+---------------+----------------------------------------------------------------------------------------+
| id                             | estRows | task      | access object | operator info                                                                          |
+--------------------------------+---------+-----------+---------------+----------------------------------------------------------------------------------------+
| Projection_12                  | 0.80    | root      |               | Column#3                                                                               |
| └─Selection_13                 | 0.80    | root      |               | gt(Column#4, 1)                                                                        |
|   └─HashAgg_18                 | 1.00    | root      |               | group by:rs.t.a, funcs:count(Column#6)->Column#3, funcs:avg(distinct rs.t.a)->Column#4 |
|     └─TableReader_19           | 1.00    | root      |               | data:HashAgg_20                                                                        |
|       └─HashAgg_20             | 1.00    | cop[tikv] |               | group by:rs.t.a, funcs:count(1)->Column#6                                              |
|         └─TableFullScan_17     | 1.00    | cop[tikv] | table:t       | keep order:false, stats:pseudo                                                         |
+--------------------------------+---------+-----------+---------------+----------------------------------------------------------------------------------------+

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

successfully

3. What did you see instead (Required)

ERROR 1105 (HY000): runtime error: index out of range [-1]
Panic log

err="runtime error: index out of range [-1]
github.com/pingcap/tidb/executor.(*recordSet).Next.func1
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/adapter.go:138
runtime.gopanic
\t/usr/local/go/src/runtime/panic.go:679
runtime.goPanicIndex
\t/usr/local/go/src/runtime/panic.go:75
github.com/pingcap/tidb/types.(*MyDecimal).WriteBin
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/types/mydecimal.go:1197
github.com/pingcap/tidb/types.(*MyDecimal).ToBin
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/types/mydecimal.go:1174
github.com/pingcap/tidb/types.(*MyDecimal).ToHashKey
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/types/mydecimal.go:1306
github.com/pingcap/tidb/executor/aggfuncs.(*avgOriginal4DistinctDecimal).UpdatePartialResult
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/aggfuncs/func_avg.go:228
github.com/pingcap/tidb/executor.(*HashAggExec).execute
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/aggregate.go:930
github.com/pingcap/tidb/executor.(*HashAggExec).unparallelExec
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/aggregate.go:858
github.com/pingcap/tidb/executor.(*HashAggExec).Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/aggregate.go:711
github.com/pingcap/tidb/executor.Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/executor.go:280
github.com/pingcap/tidb/executor.(*SelectionExec).Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/executor.go:1272
github.com/pingcap/tidb/executor.Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/executor.go:280
github.com/pingcap/tidb/executor.(*ProjectionExec).unParallelExecute
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/projection.go:193
github.com/pingcap/tidb/executor.(*ProjectionExec).Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/projection.go:179
github.com/pingcap/tidb/executor.Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/executor.go:280
github.com/pingcap/tidb/executor.(*recordSet).Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/executor/adapter.go:142
github.com/pingcap/tidb/server.(*tidbResultSet).Next
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/driver_tidb.go:304
github.com/pingcap/tidb/server.(*clientConn).writeChunks
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/conn.go:1881
github.com/pingcap/tidb/server.(*clientConn).writeResultset
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/conn.go:1829
github.com/pingcap/tidb/server.(*clientConn).handleStmt
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/conn.go:1723
github.com/pingcap/tidb/server.(*clientConn).handleQuery
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/conn.go:1569
github.com/pingcap/tidb/server.(*clientConn).dispatch
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/conn.go:1103
github.com/pingcap/tidb/server.(*clientConn).Run
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/conn.go:861
github.com/pingcap/tidb/server.(*Server).onConn
\t/home/jenkins/agent/workspace/tidb_master/go/src/github.com/pingcap/tidb/server/server.go:481
runtime.goexit
\t/usr/local/go/src/runtime/asm_amd64.s:1357

4. What is your TiDB version? (Required)

Release Version: v4.0.0-beta.2-2807-g289dcfefd-dirty
Edition: Community
Git Commit Hash: 289dcfe
Git Branch: master
UTC Build Time: 2021-05-06 15:11:16
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

@lilinghai lilinghai added the type/bug The issue is confirmed as a bug. label May 7, 2021
@ichn-hu
Copy link
Contributor

ichn-hu commented May 10, 2021

@aytrack this should be a planner's bug, and note also cascades_planner is not GAed yet, so I doubt if this bug should be a major bug.

@aytrack
Copy link
Contributor

aytrack commented May 10, 2021

I will change the sig label to planner, but I think it's a major bug because the TiDB was panic.

@aytrack aytrack added sig/planner SIG: Planner and removed sig/execution SIG execution labels May 10, 2021
@blacktear23
Copy link
Contributor

Seems planner missing a Projection between HashAgg_18 and TableReader_19

@zoomxi
Copy link
Contributor

zoomxi commented May 25, 2021

/assign

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment