Skip to content

Commit e57bb1f

Browse files
committed
MDEV-19258 RIGHT JOIN hangs in MariaDB
This patch corrects the patch for the bug 10006. The latter incorrectly calculates the attribute TABLE_LIST::dep_tables for inner tables of outer joins that are to be converted into inner joins. As a result after the patch some valid join orders were not evaluated and the optimizer could choose an execution plan that was far from being optimal.
1 parent aad4e56 commit e57bb1f

File tree

4 files changed

+416
-5
lines changed

4 files changed

+416
-5
lines changed

mysql-test/r/join_outer.result

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ t1.b1+'0' t2.b2 + '0'
24472447
0 0
24482448
1 1
24492449
DROP TABLE t1, t2;
2450-
set @join_cache_level= @save_join_cache_level;
2450+
set @@join_cache_level= @save_join_cache_level;
24512451
#
24522452
# MDEV-14779: using left join causes incorrect results with materialization and derived tables
24532453
#
@@ -2513,4 +2513,141 @@ ORDER BY tb1.i1;
25132513
v2
25142514
DROP TABLE t1,t2;
25152515
# end of 5.5 tests
2516+
#
2517+
# MDEV-19258: chained right joins all converted to inner joins
2518+
#
2519+
CREATE TABLE t1 (
2520+
id int NOT NULL AUTO_INCREMENT,
2521+
timestamp bigint NOT NULL,
2522+
modifiedBy varchar(255) DEFAULT NULL,
2523+
PRIMARY KEY (id)
2524+
);
2525+
CREATE TABLE t2 (
2526+
id int NOT NULL,
2527+
REV int NOT NULL,
2528+
REVTYPE tinyint DEFAULT NULL,
2529+
profile_id int DEFAULT NULL,
2530+
PRIMARY KEY (id,REV)
2531+
);
2532+
CREATE TABLE t3 (
2533+
id int NOT NULL,
2534+
REV int NOT NULL,
2535+
person_id int DEFAULT NULL,
2536+
PRIMARY KEY (id,REV)
2537+
);
2538+
CREATE TABLE t4 (
2539+
id int NOT NULL,
2540+
REV int NOT NULL,
2541+
PRIMARY KEY (id,REV)
2542+
);
2543+
INSERT INTO t1 VALUES
2544+
(1,1294391193890,'Cxqy$*9.kKeE'),(2,1294643906883,'rE4wqGV0gif@'),
2545+
(3,1294643927456,'L?3yt(%dY$Br'),(4,1294644343525,'WH&ObiZ$#2S4'),
2546+
(5,1294644616416,'YXnCbt?olUZ0'),(6,1294644954537,'8Npe4!(#lU@k'),
2547+
(7,1294645046659,'knc0GhXB1#ib'),(8,1294645183829,'w*oPpVfuS8^m'),
2548+
(9,1294645386701,'hwXR@3qVzrbU'),(10,1294645525982,'BeLW*Y9ndP0l'),
2549+
(11,1294645627723,'nTegib^)qZ$I'),(12,1294650860266,'u62C^Kzx3wH8'),
2550+
(13,1294657613745,'4&BkFjGa!qLg'),(14,1294660627161,')anpt312SCoh'),
2551+
(15,1294661023336,'LtJ2PX?*kTmx'),(16,1294662838066,'POGRr@?#ofpl'),
2552+
(17,1294663020989,'o.)1EOT2jnF7'),(18,1294663308065,'&TZ0F0LHE6.h'),
2553+
(19,1294664900039,'j)kSC%^In$9d'),(20,1294668904556,'97glN50)cAo.'),
2554+
(21,1294728056853,'lrKZxmw?I.Ek'),(22,1294728157174,'@P*SRg!pT.q?'),
2555+
(23,1294728327099,'W9gPrptF.)8n'),(24,1294728418481,'$q*c^sM&URd#'),
2556+
(25,1294728729620,'9*f4&bTPRtHo'),(26,1294728906014,')4VtTEnS7$oI'),
2557+
(27,1294732190003,'8dkNSPq2u3AQ'),(28,1294733205065,'SV2N6IoEf438'),
2558+
(29,1294741984927,'rBKj.0S^Ey%*'),(30,1294751748352,'j$2DvlBqk)Fw'),
2559+
(31,1294753902212,'C$N6OrEw8elz'),(32,1294758120598,'DCSVZw!rnxXq'),
2560+
(33,1294761769556,'OTS@QU8a6s5c'),(34,1294816845305,'IUE2stG0D3L5'),
2561+
(35,1294816966909,'Xd16yka.9nHe'),(36,1294817116302,'lOQHZpm%!8qb'),
2562+
(37,1294817374775,'^&pE3IhNf7ey'),(38,1294817538907,'oEn4#7C0Vhfp'),
2563+
(39,1294818482950,'bx54J*O0Va&?'),(40,1294819047024,'J%@a&1.qgdb?'),
2564+
(41,1294821826077,'C9kojr$L3Phz'),(42,1294825454458,'gG#BOnM80ZPi'),
2565+
(43,1294904129918,'F^!TrjM#zdvc'),(44,1294904254166,'Va&Tb)k0RvlM'),
2566+
(45,1294904414964,'dJjq0M6HvhR#'),(46,1294904505784,'nJmxg)ELqY(b'),
2567+
(47,1294904602835,'dhF#or$Vge!7'),(48,1294904684728,'?bIh5E3l!0em'),
2568+
(49,1294904877898,'Y*WflOdcxnk.'),(50,1294905002390,'*?H!lUgez5A.'),
2569+
(51,1294905096043,'wlEIY3n9uz!p'),(52,1294905404621,'T?qv3H6&hlQD'),
2570+
(53,1294905603922,'S@Bhys^Ti7bt'),(54,1294905788416,'KR?a5NVukz#l'),
2571+
(55,1294905993190,'A*&q4kWhED!o'),(56,1294906205254,'fT0%7z0DF6h*'),
2572+
(57,1294906319680,'LhzdW4?ivjR0'),(58,1294906424296,'h0KDlns%U*6T'),
2573+
(59,1294906623844,'b$CfB1noI6Ax'),(60,1294911258896,'#T1*LP!3$Oys');
2574+
INSERT INTO t2 VALUES
2575+
(1,1,0,10209),(1,42480,1,10209),(1,61612,1,10209),(1,257545,1,10209),
2576+
(1,385332,1,10209),(1,1687999,1,10209),(3,1,0,10210),(3,617411,2,10210),
2577+
(4,11,0,14),(4,95149,1,10211),(4,607890,2,10211),(5,1,0,10212),
2578+
(6,1,0,10213),(6,93344,1,10213),(6,295578,1,10213),(6,295579,1,10213),
2579+
(6,295644,1,10213),(7,1,0,10214),(7,12,1,7),(7,688796,1,10214),
2580+
(7,1140433,1,10214),(7,1715227,1,10214),(8,1,0,10215),(8,74253,1,10215),
2581+
(8,93345,1,10215),(8,12,2,2),(9,1,0,10216),(9,93342,1,10216),
2582+
(9,122354,1,10216),(9,301499,2,10216),(10,11,0,5),(10,93343,1,10217),
2583+
(10,122355,1,10217),(10,123050,1,10217),(10,301500,2,10217),(11,1,0,10218),
2584+
(11,87852,1,10218),(11,605499,2,10218),(12,1,0,10219),(12,88024,1,10219),
2585+
(12,605892,2,10219),(13,1,0,10220);
2586+
INSERT INTO t3 VALUES
2587+
(1,1,300003),(1,117548,NULL),(2,1,300003),(2,117548,300006),
2588+
(3,1,300153),(3,117548,NULL),(4,1,300153),(4,117548,NULL),
2589+
(5,1,300153),(5,117548,NULL),(6,1,300182),(6,117548,NULL),
2590+
(7,1,300205),(7,117548,NULL),(8,1,300217),(8,117548,NULL),
2591+
(9,1,300290),(9,117548,NULL),(10,1,300290),(10,117548,NULL),
2592+
(11,1,300405),(11,117548,NULL),(12,1,300670),(12,117548,NULL),
2593+
(13,1,300670),(13,117548,NULL),(14,1,300006),(14,117548,NULL),
2594+
(15,1,300671),(15,117548,NULL),(16,1,300732),(16,117548,NULL);
2595+
INSERT INTO t4 VALUES
2596+
(300000,1),(300001,1),(300003,1),(300004,1),
2597+
(300005,1),(300005,688796),(300006,1),(300006,97697),
2598+
(300009,1),(300010,1),(300011,1),(300012,1),(300013,1),
2599+
(300014,1),(300015,1),(300016,1),(300017,1),(300018,1),
2600+
(300019,1),(300020,1),(300021,1),(300022,1),(300023,1),
2601+
(300024,1),(300025,1),(300026,1),(300027,1),(300028,1);
2602+
# This should have join order of t2,t3,t4,t1
2603+
EXPLAIN EXTENDED SELECT *
2604+
FROM t1 INNER JOIN t2 ON t2.REV=t1.id
2605+
INNER JOIN t3 ON t3.id=t2.profile_id
2606+
INNER JOIN t4 ON t4.id=t3.person_id
2607+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND
2608+
t2.REVTYPE=2;
2609+
id select_type table type possible_keys key key_len ref rows filtered Extra
2610+
1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where
2611+
1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where
2612+
1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index
2613+
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where
2614+
Warnings:
2615+
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416))
2616+
SELECT *
2617+
FROM t1 INNER JOIN t2 ON t2.REV=t1.id
2618+
INNER JOIN t3 ON t3.id=t2.profile_id
2619+
INNER JOIN t4 ON t4.id=t3.person_id
2620+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND
2621+
t2.REVTYPE=2;
2622+
id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV
2623+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1
2624+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1
2625+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697
2626+
# This should have join order of t2,t3,t4,t1 with the same plan as above
2627+
# because all RIGHT JOIN operations are converted into INNER JOIN
2628+
EXPLAIN EXTENDED SELECT *
2629+
FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id
2630+
RIGHT JOIN t3 ON t3.id=t2.profile_id
2631+
RIGHT JOIN t4 ON t4.id=t3.person_id
2632+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416
2633+
AND t2.REVTYPE=2;
2634+
id select_type table type possible_keys key key_len ref rows filtered Extra
2635+
1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where
2636+
1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where
2637+
1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index
2638+
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where
2639+
Warnings:
2640+
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t4` join `test`.`t3` join `test`.`t2` join `test`.`t1` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416))
2641+
SELECT *
2642+
FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id
2643+
RIGHT JOIN t3 ON t3.id=t2.profile_id
2644+
RIGHT JOIN t4 ON t4.id=t3.person_id
2645+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416
2646+
AND t2.REVTYPE=2;
2647+
id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV
2648+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1
2649+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1
2650+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697
2651+
DROP TABLE t1,t2,t3,t4;
2652+
# end of 10.1 tests
25162653
SET optimizer_switch=@save_optimizer_switch;

mysql-test/r/join_outer_jcl6.result

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,7 @@ t1.b1+'0' t2.b2 + '0'
24582458
0 0
24592459
1 1
24602460
DROP TABLE t1, t2;
2461-
set @join_cache_level= @save_join_cache_level;
2461+
set @@join_cache_level= @save_join_cache_level;
24622462
#
24632463
# MDEV-14779: using left join causes incorrect results with materialization and derived tables
24642464
#
@@ -2524,6 +2524,143 @@ ORDER BY tb1.i1;
25242524
v2
25252525
DROP TABLE t1,t2;
25262526
# end of 5.5 tests
2527+
#
2528+
# MDEV-19258: chained right joins all converted to inner joins
2529+
#
2530+
CREATE TABLE t1 (
2531+
id int NOT NULL AUTO_INCREMENT,
2532+
timestamp bigint NOT NULL,
2533+
modifiedBy varchar(255) DEFAULT NULL,
2534+
PRIMARY KEY (id)
2535+
);
2536+
CREATE TABLE t2 (
2537+
id int NOT NULL,
2538+
REV int NOT NULL,
2539+
REVTYPE tinyint DEFAULT NULL,
2540+
profile_id int DEFAULT NULL,
2541+
PRIMARY KEY (id,REV)
2542+
);
2543+
CREATE TABLE t3 (
2544+
id int NOT NULL,
2545+
REV int NOT NULL,
2546+
person_id int DEFAULT NULL,
2547+
PRIMARY KEY (id,REV)
2548+
);
2549+
CREATE TABLE t4 (
2550+
id int NOT NULL,
2551+
REV int NOT NULL,
2552+
PRIMARY KEY (id,REV)
2553+
);
2554+
INSERT INTO t1 VALUES
2555+
(1,1294391193890,'Cxqy$*9.kKeE'),(2,1294643906883,'rE4wqGV0gif@'),
2556+
(3,1294643927456,'L?3yt(%dY$Br'),(4,1294644343525,'WH&ObiZ$#2S4'),
2557+
(5,1294644616416,'YXnCbt?olUZ0'),(6,1294644954537,'8Npe4!(#lU@k'),
2558+
(7,1294645046659,'knc0GhXB1#ib'),(8,1294645183829,'w*oPpVfuS8^m'),
2559+
(9,1294645386701,'hwXR@3qVzrbU'),(10,1294645525982,'BeLW*Y9ndP0l'),
2560+
(11,1294645627723,'nTegib^)qZ$I'),(12,1294650860266,'u62C^Kzx3wH8'),
2561+
(13,1294657613745,'4&BkFjGa!qLg'),(14,1294660627161,')anpt312SCoh'),
2562+
(15,1294661023336,'LtJ2PX?*kTmx'),(16,1294662838066,'POGRr@?#ofpl'),
2563+
(17,1294663020989,'o.)1EOT2jnF7'),(18,1294663308065,'&TZ0F0LHE6.h'),
2564+
(19,1294664900039,'j)kSC%^In$9d'),(20,1294668904556,'97glN50)cAo.'),
2565+
(21,1294728056853,'lrKZxmw?I.Ek'),(22,1294728157174,'@P*SRg!pT.q?'),
2566+
(23,1294728327099,'W9gPrptF.)8n'),(24,1294728418481,'$q*c^sM&URd#'),
2567+
(25,1294728729620,'9*f4&bTPRtHo'),(26,1294728906014,')4VtTEnS7$oI'),
2568+
(27,1294732190003,'8dkNSPq2u3AQ'),(28,1294733205065,'SV2N6IoEf438'),
2569+
(29,1294741984927,'rBKj.0S^Ey%*'),(30,1294751748352,'j$2DvlBqk)Fw'),
2570+
(31,1294753902212,'C$N6OrEw8elz'),(32,1294758120598,'DCSVZw!rnxXq'),
2571+
(33,1294761769556,'OTS@QU8a6s5c'),(34,1294816845305,'IUE2stG0D3L5'),
2572+
(35,1294816966909,'Xd16yka.9nHe'),(36,1294817116302,'lOQHZpm%!8qb'),
2573+
(37,1294817374775,'^&pE3IhNf7ey'),(38,1294817538907,'oEn4#7C0Vhfp'),
2574+
(39,1294818482950,'bx54J*O0Va&?'),(40,1294819047024,'J%@a&1.qgdb?'),
2575+
(41,1294821826077,'C9kojr$L3Phz'),(42,1294825454458,'gG#BOnM80ZPi'),
2576+
(43,1294904129918,'F^!TrjM#zdvc'),(44,1294904254166,'Va&Tb)k0RvlM'),
2577+
(45,1294904414964,'dJjq0M6HvhR#'),(46,1294904505784,'nJmxg)ELqY(b'),
2578+
(47,1294904602835,'dhF#or$Vge!7'),(48,1294904684728,'?bIh5E3l!0em'),
2579+
(49,1294904877898,'Y*WflOdcxnk.'),(50,1294905002390,'*?H!lUgez5A.'),
2580+
(51,1294905096043,'wlEIY3n9uz!p'),(52,1294905404621,'T?qv3H6&hlQD'),
2581+
(53,1294905603922,'S@Bhys^Ti7bt'),(54,1294905788416,'KR?a5NVukz#l'),
2582+
(55,1294905993190,'A*&q4kWhED!o'),(56,1294906205254,'fT0%7z0DF6h*'),
2583+
(57,1294906319680,'LhzdW4?ivjR0'),(58,1294906424296,'h0KDlns%U*6T'),
2584+
(59,1294906623844,'b$CfB1noI6Ax'),(60,1294911258896,'#T1*LP!3$Oys');
2585+
INSERT INTO t2 VALUES
2586+
(1,1,0,10209),(1,42480,1,10209),(1,61612,1,10209),(1,257545,1,10209),
2587+
(1,385332,1,10209),(1,1687999,1,10209),(3,1,0,10210),(3,617411,2,10210),
2588+
(4,11,0,14),(4,95149,1,10211),(4,607890,2,10211),(5,1,0,10212),
2589+
(6,1,0,10213),(6,93344,1,10213),(6,295578,1,10213),(6,295579,1,10213),
2590+
(6,295644,1,10213),(7,1,0,10214),(7,12,1,7),(7,688796,1,10214),
2591+
(7,1140433,1,10214),(7,1715227,1,10214),(8,1,0,10215),(8,74253,1,10215),
2592+
(8,93345,1,10215),(8,12,2,2),(9,1,0,10216),(9,93342,1,10216),
2593+
(9,122354,1,10216),(9,301499,2,10216),(10,11,0,5),(10,93343,1,10217),
2594+
(10,122355,1,10217),(10,123050,1,10217),(10,301500,2,10217),(11,1,0,10218),
2595+
(11,87852,1,10218),(11,605499,2,10218),(12,1,0,10219),(12,88024,1,10219),
2596+
(12,605892,2,10219),(13,1,0,10220);
2597+
INSERT INTO t3 VALUES
2598+
(1,1,300003),(1,117548,NULL),(2,1,300003),(2,117548,300006),
2599+
(3,1,300153),(3,117548,NULL),(4,1,300153),(4,117548,NULL),
2600+
(5,1,300153),(5,117548,NULL),(6,1,300182),(6,117548,NULL),
2601+
(7,1,300205),(7,117548,NULL),(8,1,300217),(8,117548,NULL),
2602+
(9,1,300290),(9,117548,NULL),(10,1,300290),(10,117548,NULL),
2603+
(11,1,300405),(11,117548,NULL),(12,1,300670),(12,117548,NULL),
2604+
(13,1,300670),(13,117548,NULL),(14,1,300006),(14,117548,NULL),
2605+
(15,1,300671),(15,117548,NULL),(16,1,300732),(16,117548,NULL);
2606+
INSERT INTO t4 VALUES
2607+
(300000,1),(300001,1),(300003,1),(300004,1),
2608+
(300005,1),(300005,688796),(300006,1),(300006,97697),
2609+
(300009,1),(300010,1),(300011,1),(300012,1),(300013,1),
2610+
(300014,1),(300015,1),(300016,1),(300017,1),(300018,1),
2611+
(300019,1),(300020,1),(300021,1),(300022,1),(300023,1),
2612+
(300024,1),(300025,1),(300026,1),(300027,1),(300028,1);
2613+
# This should have join order of t2,t3,t4,t1
2614+
EXPLAIN EXTENDED SELECT *
2615+
FROM t1 INNER JOIN t2 ON t2.REV=t1.id
2616+
INNER JOIN t3 ON t3.id=t2.profile_id
2617+
INNER JOIN t4 ON t4.id=t3.person_id
2618+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND
2619+
t2.REVTYPE=2;
2620+
id select_type table type possible_keys key key_len ref rows filtered Extra
2621+
1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where
2622+
1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where
2623+
1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index
2624+
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where
2625+
Warnings:
2626+
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t1` join `test`.`t2` join `test`.`t3` join `test`.`t4` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416))
2627+
SELECT *
2628+
FROM t1 INNER JOIN t2 ON t2.REV=t1.id
2629+
INNER JOIN t3 ON t3.id=t2.profile_id
2630+
INNER JOIN t4 ON t4.id=t3.person_id
2631+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416 AND
2632+
t2.REVTYPE=2;
2633+
id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV
2634+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1
2635+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1
2636+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697
2637+
# This should have join order of t2,t3,t4,t1 with the same plan as above
2638+
# because all RIGHT JOIN operations are converted into INNER JOIN
2639+
EXPLAIN EXTENDED SELECT *
2640+
FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id
2641+
RIGHT JOIN t3 ON t3.id=t2.profile_id
2642+
RIGHT JOIN t4 ON t4.id=t3.person_id
2643+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416
2644+
AND t2.REVTYPE=2;
2645+
id select_type table type possible_keys key key_len ref rows filtered Extra
2646+
1 SIMPLE t2 ALL NULL NULL NULL NULL 42 100.00 Using where
2647+
1 SIMPLE t3 ref PRIMARY PRIMARY 4 test.t2.profile_id 1 100.00 Using where
2648+
1 SIMPLE t4 ref PRIMARY PRIMARY 4 test.t3.person_id 1 100.00 Using index
2649+
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.REV 1 100.00 Using where
2650+
Warnings:
2651+
Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`timestamp` AS `timestamp`,`test`.`t1`.`modifiedBy` AS `modifiedBy`,`test`.`t2`.`id` AS `id`,`test`.`t2`.`REV` AS `REV`,`test`.`t2`.`REVTYPE` AS `REVTYPE`,`test`.`t2`.`profile_id` AS `profile_id`,`test`.`t3`.`id` AS `id`,`test`.`t3`.`REV` AS `REV`,`test`.`t3`.`person_id` AS `person_id`,`test`.`t4`.`id` AS `id`,`test`.`t4`.`REV` AS `REV` from `test`.`t4` join `test`.`t3` join `test`.`t2` join `test`.`t1` where ((`test`.`t2`.`REVTYPE` = 2) and (`test`.`t1`.`id` = `test`.`t2`.`REV`) and (`test`.`t3`.`id` = `test`.`t2`.`profile_id`) and (`test`.`t4`.`id` = `test`.`t3`.`person_id`) and (`test`.`t1`.`timestamp` < 1294664900039) and (`test`.`t1`.`timestamp` > 1294644616416))
2652+
SELECT *
2653+
FROM t1 RIGHT JOIN t2 ON t2.REV=t1.id
2654+
RIGHT JOIN t3 ON t3.id=t2.profile_id
2655+
RIGHT JOIN t4 ON t4.id=t3.person_id
2656+
WHERE t1.timestamp < 1294664900039 AND t1.timestamp > 1294644616416
2657+
AND t2.REVTYPE=2;
2658+
id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV
2659+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 1 300003 300003 1
2660+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 1
2661+
12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697
2662+
DROP TABLE t1,t2,t3,t4;
2663+
# end of 10.1 tests
25272664
SET optimizer_switch=@save_optimizer_switch;
25282665
set join_cache_level=default;
25292666
show variables like 'join_cache_level';

0 commit comments

Comments
 (0)