pingcap / pingcap/tidb

Unexpected Estimated Rows by GROUP BY

Open
#51,525 2 comments 0 reactions 0 assignees View on GitHub
fuzz/sqlancer severity/minor sig/planner type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

### 1. Minimal reproduce step (Required)

```sql
CREATE TABLE t0(c0 BLOB);
INSERT INTO t0(c0) VALUES (NULL), (NULL);
ANALYZE TABLE t0;

EXPLAIN SELECT t0.c0 FROM t0 WHERE ((t0.c0)LIKE(0.1)); -- estRows=0.00
EXPLAIN SELECT t0.c0 FROM t0 WHERE ((t0.c0)LIKE(0.1)) GROUP BY t0.c0; -- estRows=1.00
```

### 2. What did you expect to see? (Required)
The second query has one more `GROUP BY` clause, so I think it should not return more rows than the first query.

Attach both query plans:
```
id estRows task access object operator info
TableReader_7 0.00 root data:Selection_6
└─Selection_6 0.00 cop[tikv] like(database9.t0.c0, "0.1", 92)
└─TableFullScan_5 2.00 cop[tikv] table:t0 keep order:false, stats:pseudo
```
```
id estRows task access object operator info
HashAgg_8 1.00 root group by:database9.t0.c0, funcs:firstrow(database9.t0.c0)->database9.t0.c0
└─TableReader_15 0.00 root data:Selection_14
└─Selection_14 0.00 cop[tikv] like(database9.t0.c0, "0.1", 92)
└─TableFullScan_13 2.00 cop[tikv] table:t0 keep order:false, stats:pseudo
```

### 3. What did you see instead (Required)
The second query returns less or same estimated rows than the first query.

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

```
| Release Version: v7.6.0-alpha-347-g598ccada40
Edition: Community
Git Commit Hash: 598ccada4065e4871bc5bce53a039cbb598a6d82
Git Branch: master
UTC Build Time: 2024-03-04 06:43:19
GoVersion: go1.21.0
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
```

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.