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

Statistics cannot be generated correctly for a global index that has an expression index #54233

Open
Defined2014 opened this issue Jun 26, 2024 · 2 comments · May be fixed by #54420
Open

Statistics cannot be generated correctly for a global index that has an expression index #54233

Defined2014 opened this issue Jun 26, 2024 · 2 comments · May be fixed by #54420
Assignees
Labels
component/statistics component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner type/enhancement

Comments

@Defined2014
Copy link
Contributor

Defined2014 commented Jun 26, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

set tidb_enable_global_index=true;
drop table if exists t;
CREATE TABLE `t` (
  `a` int(11) DEFAULT NULL,
  `b` int(11) DEFAULT NULL,
  `c` int(11) DEFAULT NULL,
  UNIQUE KEY `idx` ((`c` + 1)),
  UNIQUE KEY `idx1` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`b`) PARTITIONS 2;
insert into t values (1,1,1),(2,2,2),(3,3,3),(4,4,4),(5,5,5);
analyze table t;
explain select c+1 from t where (c+1)>3;

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

mysql> explain select c+1 from t where (c+1)>3;
+------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------------+
| id                     | estRows | task      | access object                | operator info                                                            |
+------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------------+
| IndexReader_6          | 3.00    | root      |                              | index:IndexRangeScan_5                                                   |
| └─IndexRangeScan_5     | 3.00    | cop[tikv] | table:t, index:idx(`c` + 1) | range:(3,+inf], keep order:false, stats:partial[_v$_idx_0:unInitialized] |
+------------------------+---------+-----------+------------------------------+--------------------------------------------------------------------------+
2 rows in set (0.01 sec)

3. What did you see instead (Required)

mysql> explain select c+1 from t where (c+1)>3;
+------------------------+---------+-----------+-----------------------------+--------------------------------------------------------------------------+
| id                     | estRows | task      | access object               | operator info                                                            |
+------------------------+---------+-----------+-----------------------------+--------------------------------------------------------------------------+
| IndexReader_7          | 2.08    | root      | partition:all               | index:IndexRangeScan_5                                                   |
| └─IndexRangeScan_5     | 2.08    | cop[tikv] | table:t, index:idx(`c` + 1) | range:(3,+inf], keep order:false, stats:partial[_v$_idx_0:unInitialized] |
+------------------------+---------+-----------+-----------------------------+--------------------------------------------------------------------------+
2 rows in set (0.01 sec)

The estRows are never changed, no matter what conditions are used to query, e.g. explain select c+1 from t where (c+1)>0;

4. What is your TiDB version? (Required)

@Defined2014 Defined2014 added type/bug This issue is a bug. sig/planner SIG: Planner severity/moderate component/tablepartition This issue is related to Table Partition of TiDB. labels Jun 26, 2024
@elsa0520
Copy link
Contributor

Now, we don't have ability for global index

@Defined2014
Copy link
Contributor Author

Now, we don't have ability for global index

Only affects expression index, it works well with normal global index.

@Defined2014 Defined2014 self-assigned this Jul 3, 2024
@Defined2014 Defined2014 linked a pull request Jul 3, 2024 that will close this issue
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/statistics component/tablepartition This issue is related to Table Partition of TiDB. sig/planner SIG: Planner type/enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants