pingcap / pingcap/tidb

TPC-DS query9 Compile takes a long time

Open
#35,006 5 comments 0 reactions 1 assignee Claimed by @AilinKid View on GitHub
severity/moderate sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

explain `tpc-ds` benchmark `query9`

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

get results soon

### 3. What did you see instead (Required)

Takes 24s
```sql
+----------------------------+---------+--------------+---------------+----------------------------------------------------------------------------------------------------------------------------+
| id | estRows | task | access object | operator info |
+----------------------------+---------+--------------+---------------+----------------------------------------------------------------------------------------------------------------------------+
| Projection_424 | 1.00 | root | | 388.198299->Column#449, 1127.705490->Column#535, 1867.273089->Column#621, 2606.560667->Column#707, 3346.710097->Column#793 |
| └─TableReader_426 | 1.00 | root | | data:TableRangeScan_425 |
| └─TableRangeScan_425 | 1.00 | cop[tiflash] | table:reason | range:[1,1], keep order:false |
+----------------------------+---------+--------------+---------------+----------------------------------------------------------------------------------------------------------------------------+
3 rows in set (23.94 sec)
```
trace
```sql
+---------------------------------------------------------------------------------------+-----------------+---------------+
| operation | startTS | duration |
+---------------------------------------------------------------------------------------+-----------------+---------------+
| trace | 17:16:07.089398 | 23.858040959s |
| ├─session.ExecuteStmt | 17:16:07.089407 | 23.844350227s |
| │ ├─executor.Compile | 17:16:07.089491 | 23.844016928s |
| │ │ ├─executor.EvalSubQuery | 17:16:07.091026 | 1.221753294s |
```
It took 24 s to execute sql
```sql
| │ └─regionRequest.SendReqCtx | 17:16:30.934529 | 12.183613ms |
| │ └─rpcClient.SendRequest, region ID: 34591, type: Get | 17:16:30.934547 | 12.108663ms |
| └─*executor.ProjectionExec.Next | 17:16:30.946838 | 17.682µs |
| └─*executor.PointGetExecutor.Next | 17:16:30.946843 | 1.154µs |
+---------------------------------------------------------------------------------------+-----------------+---------------+
1902 rows in set (24.28 sec)
```
query
```sql
select case when (select count(*)
from store_sales
where ss_quantity between 1 and 20) > 409437
then (select avg(ss_ext_sales_price)
from store_sales
where ss_quantity between 1 and 20)
else (select avg(ss_net_paid)
from store_sales
where ss_quantity between 1 and 20) end bucket1 ,
case when (select count(*)
from store_sales
where ss_quantity between 21 and 40) > 2136630
then (select avg(ss_ext_sales_price)
from store_sales
where ss_quantity between 21 and 40)
else (select avg(ss_net_paid)
from store_sales
where ss_quantity between 21 and 40) end bucket2,
case when (select count(*)
from store_sales
where ss_quantity between 41 and 60) > 1333710
then (select avg(ss_ext_sales_price)
from store_sales
where ss_quantity between 41 and 60)
else (select avg(ss_net_paid)
from store_sales
where ss_quantity between 41 and 60) end bucket3,
case when (select count(*)
from store_sales
where ss_quantity between 61 and 80) > 2271483
then (select avg(ss_ext_sales_price)
from store_sales
where ss_quantity between 61 and 80)
else (select avg(ss_net_paid)
from store_sales
where ss_quantity between 61 and 80) end bucket4,
case when (select count(*)
from store_sales
where ss_quantity between 81 and 100) > 518132
then (select avg(ss_ext_sales_price)
from store_sales
where ss_quantity between 81 and 100)
else (select avg(ss_net_paid)
from store_sales
where ss_quantity between 81 and 100) end bucket5
from reason
where r_reason_sk = 1
;
```
### 4. What is your TiDB version? (Required)

v5.4.1

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.