Adding STRAIGHT_JOIN to certain queries results in a large number of duplicate rows
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Drizzle |
Fix Released
|
Medium
|
PrafullaT | ||
Dexter |
Fix Released
|
Medium
|
PrafullaT |
Bug Description
Adding STRAIGHT_JOIN to certain queries can add a large number of duplicate rows to the result set.
This appears to be related to MySQL bug - http://
From the test case:
SELECT COUNT(table1 .`pk`)
FROM m table1 RIGHT JOIN o JOIN o table3 ON table3 .`col_int_key` ON table1 .`col_int` = table3 .`col_int_key` ;
COUNT(table1 .`pk`)
187
SELECT STRAIGHT_JOIN COUNT(table1 .`pk`)
FROM m table1 RIGHT JOIN o JOIN o table3 ON table3 .`col_int_key` ON table1 .`col_int` = table3 .`col_int_key` /* TRANSFORM_
COUNT(table1 .`pk`)
5083
Query plan for regular query:
# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# */
Query plan for query with STRAIGHT_JOIN:
=# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# */
Related branches
Changed in drizzle: | |
importance: | Undecided → Medium |
status: | New → Confirmed |
Changed in drizzle: | |
assignee: | nobody → Prafulla Tekawade (prafulla-tekawade) |
Test suite test case:
#/* Server0: Drizzle 2010.05.1561 */
--disable_warnings
DROP TABLE IF EXISTS `m`;
CREATE TABLE `m` (
`col_int` int DEFAULT NULL,
`pk` int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`pk`)
) ENGINE=InnoDB;
ALTER TABLE `m` DISABLE KEYS; NULL,2) ,(NULL, 3),(-207224832, 4),(714801152, 5),(-1265106944 ,6),(2023948288 ,7),(865599488, 8),(1,9) ,(-1895301120, 10),(3, 11),(9, 12),(5, 13),(NULL, 14),(NULL, 15),(1, 16),(-224657408 ,17),(2, 18),(-121949388 8,19),( 7,20),( 1,21),( NULL,22) ,(NULL, 23);
INSERT INTO `m` VALUES (1,1),(
ALTER TABLE `m` ENABLE KEYS;
DROP TABLE IF EXISTS `o`;
CREATE TABLE `o` (
`col_int_key` int DEFAULT NULL,
`pk` int NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`pk`),
KEY `col_int_key` (`col_int_key`)
) ENGINE=InnoDB;
ALTER TABLE `o` DISABLE KEYS; -867368960, 2),(655032320, 3),(1,4) ,(NULL, 5),(-118751232, 6),(7,7) ,(1,8), (3,9),( -518324224, 10),(7, 11),(1129709568 ,12),(- 2081357824, 13),(6, 14),(NULL, 15),(NULL, 16),(NULL, 17);
INSERT INTO `o` VALUES (4,1),(
ALTER TABLE `o` ENABLE KEYS;
#/* Begin test case for query 0 */
SELECT COUNT(table1 .`pk`)
FROM m table1 RIGHT JOIN o JOIN o table3 ON table3 .`col_int_key` ON table1 .`col_int` = table3 .`col_int_key` ;
#/* Query plan Server 0: o|index| |PRIMARY| 4||25|Using index| table3| index|| PRIMARY| 4||25|Using where; Using join buffer| table1| ALL|||| |23||
# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# */
#/* End of test case for query 0 */
#/* Begin test case for query 1 */
SELECT STRAIGHT_JOIN COUNT(table1 .`pk`) OUTCOME_ UNORDERED_ MATCH */;
FROM m table1 RIGHT JOIN o JOIN o table3 ON table3 .`col_int_key` ON table1 .`col_int` = table3 .`col_int_key` /* TRANSFORM_
#/* Query plan Server 0: table1| ALL|||| |23|| o|index| |PRIMARY| 4||25|Using index; Using join buffer| table3| index|| PRIMARY| 4||25|Using where; Using join buffer|
# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# */
#/* End of test case for query 1 */
DROP TABLE m;
DROP TABLE o;