pingcap / pingcap/tidb

Query too many column is much slower than MySQL

Open
#34,886 4 comments 2 reactions 1 assignee Claimed by @winoros View on GitHub
sig/planner type/enhancement
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)

The following code is a test case from https://github.com/go-sql-driver/mysql, which test name is: `TestPreparedManyCols`:

```sql
func main() {
dbDSN := fmt.Sprintf("root:%s@tcp(%s)/test", "", "127.0.0.1:4000")
db, err := sql.Open("mysql", dbDSN)
if err != nil {
panic(err)
}

t0 := time.Now()
numParams := 65535
query := "SELECT ?" + strings.Repeat(",?", numParams-1)
stmt, err := db.Prepare(query)
if err != nil {
panic(err)
}
defer stmt.Close()
fmt.Printf("prepare cost %v\n", time.Since(t0).String())

t1 := time.Now()
params := make([]interface{}, numParams)
for i := 0; i < numParams; i++ {
params[i] = ""
}
rows, err := stmt.Query(params...)
if err != nil {
panic(err)
}
rows.Close()
fmt.Printf("query cost %v\n", time.Since(t1).String())
}
```

The TiDB execution result is:

```sql
prepare cost 155.885316ms
query cost 5.747799521s
```

The MySQL 8.0 execution result is:

```sql
prepare cost 50.676375ms
query cost 64.057397ms
```

As you can see, TiDB execute much slower than MySQL.

The related TiDB cup profile is:

image

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

TiDB execute as fast as MySQL.

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

### 4. What is your TiDB version? (Required)

```sql
***************************[ 1. row ]***************************
tidb_version() | Release Version: v6.1.0-alpha-432-gd75b06ec97
Edition: Community
Git Commit Hash: d75b06ec97e54ef9f5a15630e7dfee30d22f047e
Git Branch: master
UTC Build Time: 2022-05-17 07:29:42
GoVersion: go1.18
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
```

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.