-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Join on index has incorrect range and will contain NULL value #7226
Comments
@winoros It seems you are the right person to ping. |
@zhexuany The behavior of MergeJoin is not correct, I think you can take a look and try to fix it. |
I'll fix this as soon as possible. Hope it can be fixed in 2.0.6. |
Seems like both "Index Join" and "Merge Join" have the same problem: TiDB(localhost:4000) > desc select /*+ TIDB_INLJ(t1) */ t1.a from t t1 join t t2 on t1.a=t2.a order by t1.a;
+--------------------------+-------+------+-----------------------------------------------------------------------------+
| id | count | task | operator info |
+--------------------------+-------+------+-----------------------------------------------------------------------------+
| Projection_15 | 3.75 | root | t1.a |
| └─IndexJoin_19 | 3.75 | root | inner join, inner:IndexReader_18, outer key:t1.a, inner key:t2.a |
| ├─IndexReader_22 | 3.00 | root | index:IndexScan_21 |
| │ └─IndexScan_21 | 3.00 | cop | table:t1, index:a, range:[NULL,+inf], keep order:true, stats:pseudo |
| └─IndexReader_18 | 0.00 | root | index:IndexScan_17 |
| └─IndexScan_17 | 0.00 | cop | table:t2, index:a, range: decided by [t1.a], keep order:false, stats:pseudo |
+--------------------------+-------+------+-----------------------------------------------------------------------------+
6 rows in set (0.00 sec)
TiDB(localhost:4000) > select /*+ TIDB_INLJ(t1) */ t1.a from t t1 join t t2 on t1.a=t2.a order by t1.a;
+------+
| a |
+------+
| NULL |
| 1.01 |
| 2.01 |
+------+
3 rows in set (0.00 sec)
TiDB(localhost:4000) > desc select /*+ TIDB_SMJ(t1) */ t1.a from t t1 join t t2 on t1.a=t2.a order by t1.a;
+--------------------------+-------+------+---------------------------------------------------------------------+
| id | count | task | operator info |
+--------------------------+-------+------+---------------------------------------------------------------------+
| Projection_16 | 3.75 | root | t1.a |
| └─MergeJoin_17 | 3.75 | root | inner join, left key:t1.a, right key:t2.a |
| ├─IndexReader_12 | 3.00 | root | index:IndexScan_11 |
| │ └─IndexScan_11 | 3.00 | cop | table:t1, index:a, range:[NULL,+inf], keep order:true, stats:pseudo |
| └─IndexReader_15 | 3.00 | root | index:IndexScan_14 |
| └─IndexScan_14 | 3.00 | cop | table:t2, index:a, range:[NULL,+inf], keep order:true, stats:pseudo |
+--------------------------+-------+------+---------------------------------------------------------------------+
6 rows in set (0.00 sec)
TiDB(localhost:4000) > select /*+ TIDB_SMJ(t1) */ t1.a from t t1 join t t2 on t1.a=t2.a order by t1.a;
+------+
| a |
+------+
| NULL |
| 1.01 |
| 2.01 |
+------+
3 rows in set (0.00 sec)
TiDB(localhost:4000) > desc select /*+ TIDB_HJ(t1) */ t1.a from t t1 join t t2 on t1.a=t2.a order by t1.a;
+----------------------------+-------+------+-------------------------------------------------------------+
| id | count | task | operator info |
+----------------------------+-------+------+-------------------------------------------------------------+
| Sort_6 | 3.75 | root | t1.a:asc |
| └─Projection_8 | 3.75 | root | t1.a |
| └─HashLeftJoin_16 | 3.75 | root | inner join, inner:TableReader_21, equal:[eq(t1.a, t2.a)] |
| ├─TableReader_19 | 3.00 | root | data:TableScan_18 |
| │ └─TableScan_18 | 3.00 | cop | table:t1, range:[-inf,+inf], keep order:false, stats:pseudo |
| └─TableReader_21 | 3.00 | root | data:TableScan_20 |
| └─TableScan_20 | 3.00 | cop | table:t2, range:[-inf,+inf], keep order:false, stats:pseudo |
+----------------------------+-------+------+-------------------------------------------------------------+
7 rows in set (0.00 sec)
TiDB(localhost:4000) > select /*+ TIDB_HJ(t1) */ t1.a from t t1 join t t2 on t1.a=t2.a order by t1.a;
+------+
| a |
+------+
| 1.01 |
| 2.01 |
+------+
2 rows in set (0.01 sec) |
For "Merge Join", the compare function is gained from "util/chunk/compare.go": 108 func cmpMyDecimal(l Row, lCol int, r Row, rCol int) int {
109 lNull, rNull := l.IsNull(lCol), r.IsNull(rCol)
110 if lNull || rNull {
111 return cmpNull(lNull, rNull)
112 }
113 lDec, rDec := l.GetMyDecimal(lCol), r.GetMyDecimal(rCol)
114 return lDec.Compare(rDec)
115 } And the behavior of 58 func cmpNull(lNull, rNull bool) int {
59 if lNull && rNull {
60 return 0
61 }
62 if lNull {
63 return -1
64 }
65 return 1
66 } In a word, these functions have this common behavior: |
fixed by #7255 |
Please answer these questions before submitting your issue. Thanks!
If possible, provide a recipe for reproducing the error.
Make a simple join test which has NULL value with this file. IndexTest.txt
You can see that the range is [NULL, +inf]
tidb-server -V
or runselect tidb_version();
on TiDB)?Latest master build. It also AFFECTS release-2.0 branch
In addition, Hash join is correct. @winoros
The text was updated successfully, but these errors were encountered: