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

Partition table couldn't generate IndexReader with UnionScan #52244

Closed
Defined2014 opened this issue Mar 29, 2024 · 0 comments · Fixed by #52337
Closed

Partition table couldn't generate IndexReader with UnionScan #52244

Defined2014 opened this issue Mar 29, 2024 · 0 comments · Fixed by #52337
Assignees
Labels
component/tablepartition This issue is related to Table Partition of TiDB. severity/moderate sig/sql-infra SIG: SQL Infra type/bug This issue is a bug.

Comments

@Defined2014
Copy link
Contributor

Defined2014 commented Mar 29, 2024

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE `t` (
  `a` int(11) NOT NULL,
  `b` int(11) DEFAULT NULL,
  PRIMARY KEY (`a`) /*T![clustered_index] CLUSTERED */,
  KEY `idx1` (`b`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
PARTITION BY HASH (`a`) PARTITIONS 5;
begin;
insert into t values (1, 2);
explain select b from t use index(idx1) where b > 1;

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

mysql> explain  select b from t use index(idx1) where b > 1;
+----------------------------+---------+-----------+------------------------+------------------------------------------------+
| id                         | estRows | task      | access object          | operator info                                  |
+----------------------------+---------+-----------+------------------------+------------------------------------------------+
| Projection_5               | 3333.33 | root      |                        | test.t.b                                       |
| └─UnionScan_6              | 3333.33 | root      |                        | gt(test.t.b, 1)                                |
|   └─IndexReader_8          | 3333.33 | root      | partition:all          | index:IndexRangeScan_7                         |
|     └─IndexRangeScan_7     | 3333.33 | cop[tikv] | table:t, index:idx1(b) | range:(1,+inf], keep order:false, stats:pseudo |
+----------------------------+---------+-----------+------------------------+------------------------------------------------+
4 rows in set (0.01 sec)

3. What did you see instead (Required)

mysql> explain  select b from t use index(idx1) where b > 1;
+-----------------------------------+---------+-----------+------------------------+------------------------------------------------+
| id                                | estRows | task      | access object          | operator info                                  |
+-----------------------------------+---------+-----------+------------------------+------------------------------------------------+
| Projection_5                      | 3333.33 | root      |                        | test.t.b                                       |
| └─UnionScan_6                     | 3333.33 | root      |                        | gt(test.t.b, 1)                                |
|   └─IndexLookUp_9                 | 3333.33 | root      | partition:all          |                                                |
|     ├─IndexRangeScan_7(Build)     | 3333.33 | cop[tikv] | table:t, index:idx1(b) | range:(1,+inf], keep order:false, stats:pseudo |
|     └─TableRowIDScan_8(Probe)     | 3333.33 | cop[tikv] | table:t                | keep order:false, stats:pseudo                 |
+-----------------------------------+---------+-----------+------------------------+------------------------------------------------+
5 rows in set (25.71 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                           |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.0.0-alpha-672-g693ed4e889
Edition: Community
Git Commit Hash: 693ed4e889e64bcaf741cd001cb90fb498775e39
Git Branch: master
UTC Build Time: 2024-03-29 09:17:29
GoVersion: go1.21.5
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

The problem is that we added one more column to the dataSource. It works fine when this line is commented.

_ = ds.AddExtraPhysTblIDColumn()

@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. sig/sql-infra SIG: SQL Infra and removed sig/planner SIG: Planner labels Mar 29, 2024
@Defined2014 Defined2014 self-assigned this Apr 3, 2024
@ti-chi-bot ti-chi-bot bot closed this as completed in 0ddbbc8 Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/tablepartition This issue is related to Table Partition of TiDB. severity/moderate sig/sql-infra SIG: SQL Infra type/bug This issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant