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

executor: unexpected result for hash join on enum and set columns #18850

Closed
bb7133 opened this issue Jul 29, 2020 · 0 comments · Fixed by #18855
Closed

executor: unexpected result for hash join on enum and set columns #18850

bb7133 opened this issue Jul 29, 2020 · 0 comments · Fixed by #18855
Labels
severity/critical sig/execution SIG execution type/bug The issue is confirmed as a bug.
Milestone

Comments

@bb7133
Copy link
Member

bb7133 commented Jul 29, 2020

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

tidb> create table t(a int, b enum('A', 'B'));
Query OK, 0 rows affected (0.01 sec)

tidb> create table t1(a1 int, b1 enum('B', 'A'));
Query OK, 0 rows affected (0.01 sec)

tidb> insert into t values (1, 'A');
Query OK, 1 row affected (0.01 sec)

tidb> insert into t1 values (1, 'A');
Query OK, 1 row affected (0.00 sec)

tidb> select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;

Step 2 and 3 followed below behaves exact the same if enum is replaced with set for the step above.

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

mysql> select * from t join t1 on t.b = t1.b1;
+------+------+------+------+
| a    | b    | a1   | b1   |
+------+------+------+------+
|    1 | A    |    1 | A    |
+------+------+------+------+
1 row in set (0.00 sec)

3. What did you see instead (Required)

tidb> select /*+ HASH_JOIN(t, t1) */ * from t join t1 on t.b = t1.b1;
Empty set (0.01 sec)

4. Affected version (Required)

v4.0.x

5. Root Cause Analysis

It looks that when building the HashTable used by HashJoin, the hash key is built from the offset of enum/set value:

https://github.com/pingcap/tidb/blob/master/util/codec/codec.go#L571

When the values of enum/set have different offsets by their definitions, the join result would be wrong.

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

Successfully merging a pull request may close this issue.

2 participants