Bug #121608 Inconsistent NATURAL JOIN results under JOIN_ORDER hint

Submitted: 26 Oct 9:10 Modified: 27 Oct 6:29
Reporter: Hao Wang Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:9.7.2 OS:Any
Assigned to: CPU Architecture:Any

[26 Oct 9:10] Hao Wang
Description:
The same `NATURAL JOIN` query returns 1 row with `/*+ JOIN_ORDER(t1,t2)*/` but an empty set with `/*+ JOIN_ORDER(t2,t1)*/`. Changing only the join order alters the result set, indicating a result-consistency issue likely related to how the common column (`c1`) is converted/compared between `bit(26)` and `mediumtext` depending on join order.

How to repeat:
mysql> CREATE TABLE `t2` (  `c1` mediumtext NOT NULL,  `c2` bit(1) DEFAULT NULL,  `c3` varchar(11) NOT NULL,  PRIMARY KEY (`c3`)) ;
Query OK, 0 rows affected (0.188 sec)

mysql> CREATE TABLE `t1` (  `c1` bit(26) DEFAULT NULL,  KEY `i1` (`c1`));
Query OK, 0 rows affected (0.224 sec)

mysql> INSERT INTO t2 (c1,c2,c3) VALUES ('8XsaPn7cFD',b'01','7R67GdM0Vz');
Query OK, 1 row affected (0.111 sec)

mysql> INSERT INTO t1 (c1) VALUES (b'1000');
Query OK, 1 row affected (0.035 sec)

mysql> SELECT /*+ JOIN_ORDER(t1,t2)*/ t1.c1 AS ca1, t2.c1 AS ca2, c2 AS ca3 FROM t2 NATURAL JOIN t1;
+------------+------------+------------+
| ca1        | ca2        | ca3        |
+------------+------------+------------+
| 0x00000008 | 8XsaPn7cFD | 0x01       |
+------------+------------+------------+
1 row in set (0.005 sec)

-- Run the same query but with different hint:
mysql> SELECT /*+ JOIN_ORDER(t2,t1)*/ t1.c1 AS ca1, t2.c1 AS ca2, c2 AS ca3 FROM t2 NATURAL JOIN t1;
Empty set (0.004 sec)

Expected Result:Results should be the same regardless of join order (NATURAL JOIN conditions do not depend on join order).
[27 Oct 6:29] Chaithra Marsur Gopala Reddy
Hi Hao Wang,

Thank you for the test case. We do observe the issue as described. However we think this is a duplicate of Bug#114539. Both reports show inconsistent NATURAL JOIN results when the optimizer uses an index on a BIT column joined to a text column. In #114539, NO_INDEX changes the result; in this report, changing the join order does.

I reduced the repro to:

CREATE TABLE t2 (c1 CHAR);
CREATE TABLE t1 (c1 BIT, KEY(c1));
INSERT INTO t2 VALUES ('0');
INSERT INTO t1 VALUES (0);

SELECT /*+ JOIN_ORDER(t1,t2) */ 1 FROM t1 NATURAL JOIN t2;
SELECT /*+ JOIN_ORDER(t2,t1) */ 1 FROM t1 NATURAL JOIN t2;

On MySQL 9.7.4-debug, the first query returns one row and the second returns none. Removing the index makes both return a row. The failing plan uses a lookup on the BIT index, matching the pattern in #114539.

Thanks,
Chaithra

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.038 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.