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

Query with distinct got wrong result #25320

Closed
pcqz opened this issue Jun 10, 2021 · 3 comments · Fixed by #25477
Closed

Query with distinct got wrong result #25320

pcqz opened this issue Jun 10, 2021 · 3 comments · Fixed by #25477
Labels
severity/critical sig/planner SIG: Planner type/bug The issue is confirmed as a bug.

Comments

@pcqz
Copy link

pcqz commented Jun 10, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

https://asktug.com/t/topic/93576

CREATE TABLE test_distinct (
id bigint(18) NOT NULL COMMENT '主键',
b bigint(18) NOT NULL COMMENT '用户ID',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
insert into test_distinct values
(123456789101112131,223456789101112131),(123456789101112132,223456789101112131);

select distinct b from test_distinct where id in (123456789101112131,123456789101112132);

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

+--------------------+
| b                  |
+--------------------+
| 223456789101112131 |
+--------------------+
1 row in set (0.01 sec)

3. What did you see instead (Required)

+--------------------+
| b                  |
+--------------------+
| 223456789101112131 |
| 223456789101112131 |
+--------------------+
2 rows in set (0.01 sec)

4. What is your TiDB version? (Required)

v5.0.1

@pcqz pcqz added the type/bug The issue is confirmed as a bug. label Jun 10, 2021
@xiongjiwei
Copy link
Contributor

mysql> desc select distinct b from test_distinct where id in (123456789101112131,123456789101112132);
+-------------------+---------+------+----------------------------------------+------------------------------+
| id                | estRows | task | access object                          | operator info                |
+-------------------+---------+------+----------------------------------------+------------------------------+
| Batch_Point_Get_1 | 2.00    | root | table:test_distinct, index:PRIMARY(id) | keep order:false, desc:false |
+-------------------+---------+------+----------------------------------------+------------------------------+
1 row in set (0.00 sec)

mysql> desc select distinct b from test_distinct;
+--------------------------+----------+-----------+---------------------+-------------------------------------------------------------------------------------------+
| id                       | estRows  | task      | access object       | operator info                                                                             |
+--------------------------+----------+-----------+---------------------+-------------------------------------------------------------------------------------------+
| HashAgg_6                | 8000.00  | root      |                     | group by:test.test_distinct.b, funcs:firstrow(test.test_distinct.b)->test.test_distinct.b |
| └─TableReader_11         | 10000.00 | root      |                     | data:TableFullScan_10                                                                     |
|   └─TableFullScan_10     | 10000.00 | cop[tikv] | table:test_distinct | keep order:false, stats:pseudo                                                            |
+--------------------------+----------+-----------+---------------------+-------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

it's about point_get

@winoros
Copy link
Member

winoros commented Jun 10, 2021

Emm, distinct should not be converted to point get in the fast path.

@ti-srebot
Copy link
Contributor

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

6. Fixed versions

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

Successfully merging a pull request may close this issue.

5 participants