From c36950742dc2a25220c48cb5abbc03672501c35f Mon Sep 17 00:00:00 2001 From: Manuel Ung Date: Tue, 14 Feb 2017 14:01:55 -0800 Subject: [PATCH] Fix heuristic for using ref access Summary: In MySQL, a heuristic exists that enforces using an index ref access being used over full table scan, when the query is considered covering. The check for covering keys does not work for clustered primary keys though, because MySQL assumes that accessing any column not in the key definition will be inefficient. Reviewed By: tianx Differential Revision: D4561446 fbshipit-source-id: e4a9d63 --- .../innodb_explain_json_non_select_all.result | 58 ++++++++++++------- ...innodb_explain_json_non_select_none.result | 58 ++++++++++++------- .../r/innodb_explain_non_select_all.result | 20 +++---- .../r/innodb_explain_non_select_none.result | 20 +++---- mysql-test/r/subselect_innodb.result | 16 ++--- sql/sql_planner.cc | 5 +- 6 files changed, 104 insertions(+), 73 deletions(-) diff --git a/mysql-test/r/innodb_explain_json_non_select_all.result b/mysql-test/r/innodb_explain_json_non_select_all.result index f5b4b9472d92..6729e40dd9a2 100644 --- a/mysql-test/r/innodb_explain_json_non_select_all.result +++ b/mysql-test/r/innodb_explain_json_non_select_all.result @@ -5668,8 +5668,8 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution @@ -5685,20 +5685,27 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 4, - "filtered": 100 + "filtered": 100, + "attached_condition": "(`test`.`t2`.`x` is not null)" } /* table */ }, { "table": { "table_name": "t1", - "access_type": "ALL", + "access_type": "eq_ref", "possible_keys": [ "PRIMARY" ] /* possible_keys */, - "rows": 5, - "filtered": 80, - "using_join_buffer": "Block Nested Loop", - "attached_condition": "(`test`.`t1`.`a` = `test`.`t2`.`x`)" + "key": "PRIMARY", + "used_key_parts": [ + "a" + ] /* used_key_parts */, + "key_length": "4", + "ref": [ + "test.t2.x" + ] /* ref */, + "rows": 1, + "filtered": 100 } /* table */ } ] /* nested_loop */ @@ -5708,9 +5715,9 @@ Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 @@ -5785,8 +5792,8 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution @@ -5802,20 +5809,27 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 4, - "filtered": 100 + "filtered": 100, + "attached_condition": "(`test`.`t2`.`x` is not null)" } /* table */ }, { "table": { "table_name": "t1", - "access_type": "ALL", + "access_type": "eq_ref", "possible_keys": [ "PRIMARY" ] /* possible_keys */, - "rows": 5, - "filtered": 80, - "using_join_buffer": "Block Nested Loop", - "attached_condition": "(`test`.`t1`.`a` = `test`.`t2`.`x`)" + "key": "PRIMARY", + "used_key_parts": [ + "a" + ] /* used_key_parts */, + "key_length": "4", + "ref": [ + "test.t2.x" + ] /* ref */, + "rows": 1, + "filtered": 100 } /* table */ } ] /* nested_loop */ @@ -5825,9 +5839,9 @@ Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 diff --git a/mysql-test/r/innodb_explain_json_non_select_none.result b/mysql-test/r/innodb_explain_json_non_select_none.result index 1cf4e3cb7bec..c11dc1f1645a 100644 --- a/mysql-test/r/innodb_explain_json_non_select_none.result +++ b/mysql-test/r/innodb_explain_json_non_select_none.result @@ -5685,8 +5685,8 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution @@ -5702,20 +5702,27 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 4, - "filtered": 100 + "filtered": 100, + "attached_condition": "(`test`.`t2`.`x` is not null)" } /* table */ }, { "table": { "table_name": "t1", - "access_type": "ALL", + "access_type": "eq_ref", "possible_keys": [ "PRIMARY" ] /* possible_keys */, - "rows": 5, - "filtered": 80, - "using_join_buffer": "Block Nested Loop", - "attached_condition": "(`test`.`t1`.`a` = `test`.`t2`.`x`)" + "key": "PRIMARY", + "used_key_parts": [ + "a" + ] /* used_key_parts */, + "key_length": "4", + "ref": [ + "test.t2.x" + ] /* ref */, + "rows": 1, + "filtered": 100 } /* table */ } ] /* nested_loop */ @@ -5725,9 +5732,9 @@ Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 @@ -5802,8 +5809,8 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution @@ -5819,20 +5826,27 @@ EXPLAIN "table_name": "t2", "access_type": "ALL", "rows": 4, - "filtered": 100 + "filtered": 100, + "attached_condition": "(`test`.`t2`.`x` is not null)" } /* table */ }, { "table": { "table_name": "t1", - "access_type": "ALL", + "access_type": "eq_ref", "possible_keys": [ "PRIMARY" ] /* possible_keys */, - "rows": 5, - "filtered": 80, - "using_join_buffer": "Block Nested Loop", - "attached_condition": "(`test`.`t1`.`a` = `test`.`t2`.`x`)" + "key": "PRIMARY", + "used_key_parts": [ + "a" + ] /* used_key_parts */, + "key_length": "4", + "ref": [ + "test.t2.x" + ] /* ref */, + "rows": 1, + "filtered": 100 } /* table */ } ] /* nested_loop */ @@ -5842,9 +5856,9 @@ Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 diff --git a/mysql-test/r/innodb_explain_non_select_all.result b/mysql-test/r/innodb_explain_non_select_all.result index acd4bdd5649c..9b80213dd120 100644 --- a/mysql-test/r/innodb_explain_non_select_all.result +++ b/mysql-test/r/innodb_explain_non_select_all.result @@ -2618,17 +2618,17 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 @@ -2665,17 +2665,17 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 diff --git a/mysql-test/r/innodb_explain_non_select_none.result b/mysql-test/r/innodb_explain_non_select_none.result index 61a005f698d0..d89f23fde85f 100644 --- a/mysql-test/r/innodb_explain_non_select_none.result +++ b/mysql-test/r/innodb_explain_non_select_none.result @@ -2620,17 +2620,17 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 @@ -2667,17 +2667,17 @@ FLUSH STATUS; FLUSH TABLES; EXPLAIN EXTENDED SELECT * FROM t2, v1 WHERE t2.x = v1.a; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 NULL -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 5 80.00 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t2 ALL NULL NULL NULL NULL 4 100.00 Using where +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t2.x 1 100.00 NULL Warnings: Note 1003 /* select#1 */ select `test`.`t2`.`x` AS `x`,`test`.`t1`.`a` AS `a`,(`test`.`t1`.`b` + 1) AS `c` from `test`.`t2` join `test`.`t1` where (`test`.`t1`.`a` = `test`.`t2`.`x`) # Status of EXPLAIN EXTENDED "equivalent" SELECT query execution Variable_name Value # Status of "equivalent" SELECT query execution: Variable_name Value -Handler_read_first 2 -Handler_read_key 2 -Handler_read_rnd_next 11 +Handler_read_first 1 +Handler_read_key 5 +Handler_read_rnd_next 5 # Status of testing query execution: Variable_name Value Handler_delete 4 diff --git a/mysql-test/r/subselect_innodb.result b/mysql-test/r/subselect_innodb.result index 581ff5aa8b2e..7f64857100d3 100644 --- a/mysql-test/r/subselect_innodb.result +++ b/mysql-test/r/subselect_innodb.result @@ -288,16 +288,16 @@ DOCID DOCNAME DOCTYPEID FOLDERID AUTHOR CREATED TITLE SUBTITLE DOCABSTRACT PUBLI c373e9f5ad07993f3859444553544200 Last Discussion c373e9f5ad079174ff17444553544200 c373e9f5ad0796c0eca4444553544200 Goldilocks 2003-06-09 11:21:06 Title: Last Discussion NULL Setting new abstract and keeping doc checked out 2003-06-09 10:51:26 2003-06-09 10:51:26 NULL NULL NULL 03eea05112b845949f3fd03278b5fe43 2003-06-09 11:21:06 admin 0 NULL Discussion NULL NULL EXPLAIN EXTENDED SELECT t2.*, t4.DOCTYPENAME, t1.CONTENTSIZE,t1.MIMETYPE FROM t2 INNER JOIN t4 ON t2.DOCTYPEID = t4.DOCTYPEID LEFT OUTER JOIN t1 ON t2.DOCID = t1.DOCID WHERE t2.FOLDERID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID IN(SELECT t3.FOLDERID FROM t3 WHERE t3.PARENTID='2f6161e879db43c1a5b82c21ddc49089' AND t3.FOLDERNAME = 'Level1') AND t3.FOLDERNAME = 'Level2') AND t3.FOLDERNAME = 'Level3') AND t3.FOLDERNAME = 'CopiedFolder') AND t3.FOLDERNAME = 'Movie Reviews') AND t2.DOCNAME = 'Last Discussion'; id select_type table type possible_keys key key_len ref rows filtered Extra -1 SIMPLE t2 ALL DDOCTYPEID_IDX,DFOLDERID_IDX NULL NULL NULL 9 100.00 Using where +1 SIMPLE t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 const 6 100.00 Using index condition; Using where +1 SIMPLE t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 100.00 Using where +1 SIMPLE t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 100.00 Using where +1 SIMPLE t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 100.00 Using where +1 SIMPLE t3 ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX CMFLDRPARNT_IDX 35 test.t3.FOLDERID 1 100.00 Using where +1 SIMPLE t2 ALL DDOCTYPEID_IDX,DFOLDERID_IDX NULL NULL NULL 9 77.78 Using where; Using join buffer (Block Nested Loop) +1 SIMPLE t1 eq_ref PRIMARY PRIMARY 34 test.t2.DOCID 1 100.00 NULL 1 SIMPLE t4 eq_ref PRIMARY PRIMARY 34 test.t2.DOCTYPEID 1 100.00 NULL -1 SIMPLE t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t2.FOLDERID 1 100.00 Using where -1 SIMPLE t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 100.00 Using where -1 SIMPLE t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 100.00 Using where -1 SIMPLE t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 100.00 Using where -1 SIMPLE t3 eq_ref PRIMARY,FFOLDERID_IDX,CMFLDRPARNT_IDX PRIMARY 34 test.t3.PARENTID 1 100.00 Using where -1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 2 100.00 Using where; Using join buffer (Block Nested Loop) Warnings: -Note 1003 /* select#1 */ select `test`.`t2`.`DOCID` AS `DOCID`,`test`.`t2`.`DOCNAME` AS `DOCNAME`,`test`.`t2`.`DOCTYPEID` AS `DOCTYPEID`,`test`.`t2`.`FOLDERID` AS `FOLDERID`,`test`.`t2`.`AUTHOR` AS `AUTHOR`,`test`.`t2`.`CREATED` AS `CREATED`,`test`.`t2`.`TITLE` AS `TITLE`,`test`.`t2`.`SUBTITLE` AS `SUBTITLE`,`test`.`t2`.`DOCABSTRACT` AS `DOCABSTRACT`,`test`.`t2`.`PUBLISHDATE` AS `PUBLISHDATE`,`test`.`t2`.`EXPIRATIONDATE` AS `EXPIRATIONDATE`,`test`.`t2`.`LOCKEDBY` AS `LOCKEDBY`,`test`.`t2`.`STATUS` AS `STATUS`,`test`.`t2`.`PARENTDOCID` AS `PARENTDOCID`,`test`.`t2`.`REPID` AS `REPID`,`test`.`t2`.`MODIFIED` AS `MODIFIED`,`test`.`t2`.`MODIFIER` AS `MODIFIER`,`test`.`t2`.`PUBLISHSTATUS` AS `PUBLISHSTATUS`,`test`.`t2`.`ORIGINATOR` AS `ORIGINATOR`,`test`.`t4`.`DOCTYPENAME` AS `DOCTYPENAME`,`test`.`t1`.`CONTENTSIZE` AS `CONTENTSIZE`,`test`.`t1`.`MIMETYPE` AS `MIMETYPE` from `test`.`t3` join `test`.`t3` join `test`.`t3` join `test`.`t3` join `test`.`t3` join `test`.`t2` join `test`.`t4` left join `test`.`t1` on((`test`.`t1`.`DOCID` = `test`.`t2`.`DOCID`)) where ((`test`.`t4`.`DOCTYPEID` = `test`.`t2`.`DOCTYPEID`) and (`test`.`t3`.`FOLDERID` = `test`.`t2`.`FOLDERID`) and (`test`.`t3`.`FOLDERID` = `test`.`t3`.`PARENTID`) and (`test`.`t3`.`FOLDERID` = `test`.`t3`.`PARENTID`) and (`test`.`t3`.`FOLDERID` = `test`.`t3`.`PARENTID`) and (`test`.`t3`.`FOLDERID` = `test`.`t3`.`PARENTID`) and (`test`.`t3`.`FOLDERNAME` = 'Level1') and (`test`.`t3`.`PARENTID` = '2f6161e879db43c1a5b82c21ddc49089') and (`test`.`t3`.`FOLDERNAME` = 'Level2') and (`test`.`t3`.`FOLDERNAME` = 'Level3') and (`test`.`t3`.`FOLDERNAME` = 'CopiedFolder') and (`test`.`t3`.`FOLDERNAME` = 'Movie Reviews') and (`test`.`t2`.`DOCNAME` = 'Last Discussion')) +Note 1003 /* select#1 */ select `test`.`t2`.`DOCID` AS `DOCID`,`test`.`t2`.`DOCNAME` AS `DOCNAME`,`test`.`t2`.`DOCTYPEID` AS `DOCTYPEID`,`test`.`t2`.`FOLDERID` AS `FOLDERID`,`test`.`t2`.`AUTHOR` AS `AUTHOR`,`test`.`t2`.`CREATED` AS `CREATED`,`test`.`t2`.`TITLE` AS `TITLE`,`test`.`t2`.`SUBTITLE` AS `SUBTITLE`,`test`.`t2`.`DOCABSTRACT` AS `DOCABSTRACT`,`test`.`t2`.`PUBLISHDATE` AS `PUBLISHDATE`,`test`.`t2`.`EXPIRATIONDATE` AS `EXPIRATIONDATE`,`test`.`t2`.`LOCKEDBY` AS `LOCKEDBY`,`test`.`t2`.`STATUS` AS `STATUS`,`test`.`t2`.`PARENTDOCID` AS `PARENTDOCID`,`test`.`t2`.`REPID` AS `REPID`,`test`.`t2`.`MODIFIED` AS `MODIFIED`,`test`.`t2`.`MODIFIER` AS `MODIFIER`,`test`.`t2`.`PUBLISHSTATUS` AS `PUBLISHSTATUS`,`test`.`t2`.`ORIGINATOR` AS `ORIGINATOR`,`test`.`t4`.`DOCTYPENAME` AS `DOCTYPENAME`,`test`.`t1`.`CONTENTSIZE` AS `CONTENTSIZE`,`test`.`t1`.`MIMETYPE` AS `MIMETYPE` from `test`.`t3` join `test`.`t3` join `test`.`t3` join `test`.`t3` join `test`.`t3` join `test`.`t2` join `test`.`t4` left join `test`.`t1` on((`test`.`t1`.`DOCID` = `test`.`t2`.`DOCID`)) where ((`test`.`t4`.`DOCTYPEID` = `test`.`t2`.`DOCTYPEID`) and (`test`.`t2`.`FOLDERID` = `test`.`t3`.`FOLDERID`) and (`test`.`t3`.`PARENTID` = `test`.`t3`.`FOLDERID`) and (`test`.`t3`.`PARENTID` = `test`.`t3`.`FOLDERID`) and (`test`.`t3`.`PARENTID` = `test`.`t3`.`FOLDERID`) and (`test`.`t3`.`PARENTID` = `test`.`t3`.`FOLDERID`) and (`test`.`t3`.`FOLDERNAME` = 'Level1') and (`test`.`t3`.`PARENTID` = '2f6161e879db43c1a5b82c21ddc49089') and (`test`.`t3`.`FOLDERNAME` = 'Level2') and (`test`.`t3`.`FOLDERNAME` = 'Level3') and (`test`.`t3`.`FOLDERNAME` = 'CopiedFolder') and (`test`.`t3`.`FOLDERNAME` = 'Movie Reviews') and (`test`.`t2`.`DOCNAME` = 'Last Discussion')) drop table t1, t2, t3, t4; CREATE TABLE t1 ( school_name varchar(45) NOT NULL, diff --git a/sql/sql_planner.cc b/sql/sql_planner.cc index 1845d6241d6b..9b3e320d7779 100644 --- a/sql/sql_planner.cc +++ b/sql/sql_planner.cc @@ -924,7 +924,10 @@ void Optimize_table_order::best_access_path( } if ((s->table->file->ha_table_flags() & HA_TABLE_SCAN_ON_INDEX) && //(3) - !s->table->covering_keys.is_clear_all() && best_key && //(3) + best_key && //(3) + (!s->table->covering_keys.is_clear_all() || + (s->table->file->primary_key_is_clustered() && + s->table->s->primary_key == best_key->key)) && //(3) (!s->quick || //(3) (s->quick->get_type() == QUICK_SELECT_I::QS_TYPE_ROR_INTERSECT &&//(3) best < s->quick->read_time))) //(3)