Adding STRAIGHT_JOIN to certain queries results in loss of returned 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 will result in a change (loss of rows) in the returned results.
I'm still doing research on this, but am documenting it now. Will update this bug with more information as it is discovered.
Results from the test case below:
SELECT COUNT(table1 .`col_int`)
FROM g table1 RIGHT JOIN e table2 LEFT JOIN m table3 LEFT JOIN a table5 ON table5 .`col_int_key` ON table2 .`col_int_key` = table3 .`col_int` ON table2 .`pk` ;
COUNT(table1 .`col_int`)
27
SELECT STRAIGHT_JOIN COUNT(table1 .`col_int`)
FROM g table1 RIGHT JOIN e table2 LEFT JOIN m table3 LEFT JOIN a table5 ON table5 .`col_int_key` ON table2 .`col_int_key` = table3 .`col_int` ON table2 .`pk` /* TRANSFORM_
COUNT(table1 .`col_int`)
15
Test_suite test case:
#/* Server0: Drizzle 2010.05.1561 */
--disable_warnings
DROP TABLE IF EXISTS `g`;
CREATE TABLE `g` (
`pk` int NOT NULL AUTO_INCREMENT,
`col_int` int DEFAULT NULL,
PRIMARY KEY (`pk`)
) ENGINE=InnoDB;
ALTER TABLE `g` DISABLE KEYS;
INSERT INTO `g` VALUES (1,NULL)
ALTER TABLE `g` ENABLE KEYS;
DROP TABLE IF EXISTS `e`;
CREATE TABLE `e` (
`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 `e` DISABLE KEYS;
INSERT INTO `e` VALUES (NULL,1)
ALTER TABLE `e` ENABLE KEYS;
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;
INSERT INTO `m` VALUES (1,1),(
ALTER TABLE `m` ENABLE KEYS;
DROP TABLE IF EXISTS `a`;
CREATE TABLE `a` (
`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 `a` DISABLE KEYS;
ALTER TABLE `a` ENABLE KEYS;
--enable_warnings
#/* Begin test case for query 0 */
SELECT COUNT(table1 .`col_int`)
FROM g table1 RIGHT JOIN e table2 LEFT JOIN m table3 LEFT JOIN a table5 ON table5 .`col_int_key` ON table2 .`col_int_key` = table3 .`col_int` ON table2 .`pk` ;
#/* Query plan Server 0:
# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# */
#/* End of test case for query 0 */
#/* Begin test case for query 1 */
SELECT STRAIGHT_JOIN COUNT(table1 .`col_int`)
FROM g table1 RIGHT JOIN e table2 LEFT JOIN m table3 LEFT JOIN a table5 ON table5 .`col_int_key` ON table2 .`col_int_key` = table3 .`col_int` ON table2 .`pk` /* TRANSFORM_
#/* Query plan Server 0:
# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# |1|SIMPLE|
# */
#/* End of test case for query 1 */
DROP TABLE g;
DROP TABLE e;
DROP TABLE m;
DROP TABLE a;
Related branches
Changed in drizzle: | |
importance: | Undecided → Medium |
status: | New → Confirmed |
Changed in drizzle: | |
assignee: | nobody → Prafulla Tekawade (prafulla-tekawade) |
TODO:
* Determine correct result set - I have also seen cases where STRAIGHT_JOIN had the reverse effect - it adds a LOT of duplicate rows (This isn't written up yet, still researching that one as well, will link to this bug once it's logged)
* Code research - I will try to offer up where the buggy code might be when time permits.