Skip to content

Commit

Permalink
Fix heuristic for using ref access
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lth authored and facebook-github-bot committed Feb 15, 2017
1 parent 31d5e0e commit c369507
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 73 deletions.
58 changes: 36 additions & 22 deletions mysql-test/r/innodb_explain_json_non_select_all.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 */
Expand All @@ -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
Expand Down
58 changes: 36 additions & 22 deletions mysql-test/r/innodb_explain_json_non_select_none.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 */
Expand All @@ -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
Expand Down
20 changes: 10 additions & 10 deletions mysql-test/r/innodb_explain_non_select_all.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions mysql-test/r/innodb_explain_non_select_none.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions mysql-test/r/subselect_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion sql/sql_planner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c369507

Please sign in to comment.