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

prefixed column inside clustered index's TableScan only read prefix data #22811

Closed
lysu opened this issue Feb 19, 2021 · 2 comments · Fixed by tikv/tikv#9670
Closed

prefixed column inside clustered index's TableScan only read prefix data #22811

lysu opened this issue Feb 19, 2021 · 2 comments · Fixed by tikv/tikv#9670
Assignees
Labels
severity/critical sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.

Comments

@lysu
Copy link
Contributor

lysu commented Feb 19, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

start a cluster with tikv(not unistore)

set @@tidb_enable_clustered_index=1;
CREATE TABLE `t1` (
  `cb` varchar(12) NOT NULL,
  `ci` int(11) DEFAULT NULL,
  `v` int(11) DEFAULT NULL,
  PRIMARY KEY (`cb`(1)) /*T![clustered_index] CLUSTERED */,
  KEY `idx_1` (`cb`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
insert into t1 values('PvtYW2', 1, 1);

run queries:

select * from t1;
select cb from t1;

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

MySQL [test]> select * from t1;
+--------+------+------+
| cb     | ci   | v    |
+--------+------+------+
| PvtYW2 |    1 |    1 |
+--------+------+------+
1 row in set (0.004 sec)

MySQL [test]> select cb from t1;
+----+
| cb |
+----+
| PvtYW2  |
+----+
1 row in set (0.003 sec)

3. What did you see instead (Required)

MySQL [test]> select * from t1;
+--------+------+------+
| cb     | ci   | v    |
+--------+------+------+
| PvtYW2 |    1 |    1 |
+--------+------+------+
1 row in set (0.004 sec)

MySQL [test]> select cb from t1;
+----+
| cb |
+----+
| P  |
+----+
1 row in set (0.003 sec)

4. What is your TiDB version? (Required)

Release Version: v4.0.0-beta.2-2136-gc9af43099-dirty
Edition: Community
Git Commit Hash: c9af430996323e81a7919ba0e3f30db934cf4aee
Git Branch: master
UTC Build Time: 2021-02-17 13:08:36
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
@lysu lysu added the type/bug The issue is confirmed as a bug. label Feb 19, 2021
@lysu lysu changed the title prefix column clustered index's IndexScan and TableScan got different result prefixed column inside clustered index's IndexScan and TableScan got different result Feb 19, 2021
@lysu lysu self-assigned this Feb 20, 2021
@jebter jebter added the sig/sql-infra SIG: SQL Infra label Feb 20, 2021
@sticnarf
Copy link
Contributor

To my understanding, the IndexScan here means TableScan using the key only mode, and actually we cannot use the key only mode here?

@jebter jebter added sig/transaction SIG:Transaction and removed sig/sql-infra SIG: SQL Infra labels Feb 22, 2021
@lysu lysu changed the title prefixed column inside clustered index's IndexScan and TableScan got different result prefixed column inside clustered index's TableScan only read prefix data Feb 22, 2021
ti-chi-bot pushed a commit to tikv/tikv that referenced this issue Mar 1, 2021
Signed-off-by: lysu <sulifx@gmail.com>

<!--
Thank you for contributing to TiKV!

If you haven't already, please read TiKV's [CONTRIBUTING](https://github.com/tikv/tikv/blob/master/CONTRIBUTING.md) document.

If you're unsure about anything, just ask; somebody should be along to answer within a day or two.

PR Title Format:
1. module [, module2, module3]: what's changed
2. *: what's changed

If you want to open the **Challenge Program** pull request, please use the following template:
https://raw.githubusercontent.com/tikv/.github/master/.github/PULL_REQUEST_TEMPLATE/challenge-program.md
You can use it with query parameters: https://github.com/tikv/tikv/compare/master...${you branch}?template=challenge-program.md
-->

### What problem does this PR solve?

Issue Number: close pingcap/tidb#22811

Problem Summary:

tikv will avoid read value when required column in common handle

but common handle's columns maybe not contain full columns value (like `primary key(c(1))`)

### What is changed and how it works?

What's Changed:

read kv's value when required column in common handle is the prefix of column

need merge pingcap/tidb#22829 first

### Related changes

- n/a

### Check List <!--REMOVE the items that are not applicable-->

Tests <!-- At least one of them must be included. -->

- Integration test(WIP)

Side effects

- n/a

### Release note <!-- bugfixes or new feature need a release note -->

- no release note

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/tikv/tikv/9670)
<!-- Reviewable:end -->
@ti-srebot
Copy link
Contributor

ti-srebot commented Mar 1, 2021

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

master

6. Fixed versions

master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
severity/critical sig/transaction SIG:Transaction type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants