diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 08d698092e24127fa02a78d08b08922243aba589..d3576e24a446f188488657b1a02ae68bb8a3cdd7 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -50,8 +50,8 @@ TABLES TABLE_CONSTRAINTS TABLE_PRIVILEGES TRIGGERS -VIEWS USER_PRIVILEGES +VIEWS columns_priv db func diff --git a/mysql-test/r/information_schema_db.result b/mysql-test/r/information_schema_db.result index d3ff310b812bb869abebb45601304e8f609a4a5a..0229fdef2d5eb089fe02665eae126275b95d6d9b 100644 --- a/mysql-test/r/information_schema_db.result +++ b/mysql-test/r/information_schema_db.result @@ -15,8 +15,8 @@ TABLES TABLE_CONSTRAINTS TABLE_PRIVILEGES TRIGGERS -VIEWS USER_PRIVILEGES +VIEWS show tables from INFORMATION_SCHEMA like 'T%'; Tables_in_information_schema (T%) TABLES diff --git a/mysql-test/r/join_nested.result b/mysql-test/r/join_nested.result index faad969fcd1dc6cd359a88f4179fba95eab7bd3a..dfcfa35d31d1da7a2c15b566cb82a98409cec4b6 100644 --- a/mysql-test/r/join_nested.result +++ b/mysql-test/r/join_nested.result @@ -1481,3 +1481,26 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 ref a a 5 test.t1.a 1 1 SIMPLE t3 ref a a 5 test.t2.a 1 drop table t1, t2, t3; +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, type varchar(10)); +CREATE TABLE t2 (pid int NOT NULL PRIMARY KEY, type varchar(10)); +CREATE TABLE t3 (cid int NOT NULL PRIMARY KEY, +id int NOT NULL, +pid int NOT NULL); +INSERT INTO t1 VALUES (1, 'A'), (3, 'C'); +INSERT INTO t2 VALUES (1, 'A'), (3, 'C'); +INSERT INTO t3 VALUES (1, 1, 1), (3, 3, 3); +SELECT * FROM t1 p LEFT JOIN (t3 JOIN t1) +ON (t1.id=t3.id AND t1.type='B' AND p.id=t3.id) +LEFT JOIN t2 ON (t3.pid=t2.pid) +WHERE p.id=1; +id type cid id pid id type pid type +1 A NULL NULL NULL NULL NULL NULL NULL +CREATE VIEW v1 AS +SELECT t3.* FROM t3 JOIN t1 ON t1.id=t3.id AND t1.type='B'; +SELECT * FROM t1 p LEFT JOIN v1 ON p.id=v1.id +LEFT JOIN t2 ON v1.pid=t2.pid +WHERE p.id=1; +id type cid id pid pid type +1 A NULL NULL NULL NULL NULL +DROP VIEW v1; +DROP TABLE t1,t2,t3; diff --git a/mysql-test/t/join_nested.test b/mysql-test/t/join_nested.test index 145edded486ae7a5f681e040a0ffe5f65f5db3e5..8adcf05be93355e8854eb0c82f4619c6133ff4de 100644 --- a/mysql-test/t/join_nested.test +++ b/mysql-test/t/join_nested.test @@ -914,3 +914,31 @@ explain select * from t1 left join on (t1.a = t2.a); drop table t1, t2, t3; +# +# Bug #16260: single row table in the inner nest of an outer join +# + +CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, type varchar(10)); +CREATE TABLE t2 (pid int NOT NULL PRIMARY KEY, type varchar(10)); +CREATE TABLE t3 (cid int NOT NULL PRIMARY KEY, + id int NOT NULL, + pid int NOT NULL); + +INSERT INTO t1 VALUES (1, 'A'), (3, 'C'); +INSERT INTO t2 VALUES (1, 'A'), (3, 'C'); +INSERT INTO t3 VALUES (1, 1, 1), (3, 3, 3); + +SELECT * FROM t1 p LEFT JOIN (t3 JOIN t1) + ON (t1.id=t3.id AND t1.type='B' AND p.id=t3.id) + LEFT JOIN t2 ON (t3.pid=t2.pid) + WHERE p.id=1; + +CREATE VIEW v1 AS + SELECT t3.* FROM t3 JOIN t1 ON t1.id=t3.id AND t1.type='B'; + +SELECT * FROM t1 p LEFT JOIN v1 ON p.id=v1.id + LEFT JOIN t2 ON v1.pid=t2.pid + WHERE p.id=1; + +DROP VIEW v1; +DROP TABLE t1,t2,t3; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 95da0e6263aa136d3fb4f31158127098d8429aa9..63d46934555d29d53b1954c353fe31400ce759bd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -2172,7 +2172,8 @@ make_join_statistics(JOIN *join, TABLE_LIST *tables, COND *conds, if (eq_part.is_prefix(table->key_info[key].key_parts) && ((table->key_info[key].flags & (HA_NOSAME | HA_END_SPACE_KEY)) == HA_NOSAME) && - !table->fulltext_searched) + !table->fulltext_searched && + !table->pos_in_table_list->embedding) { if (const_ref == eq_part) { // Found everything for ref. diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 1f776d815df0fb524639a1b926d31bd7dbc0cc84..1b854a005ceb12c45be7ae947160218a170844cc 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -4198,12 +4198,12 @@ ST_SCHEMA_TABLE schema_tables[]= fill_schema_table_privileges, 0, 0, -1, -1, 0}, {"TRIGGERS", triggers_fields_info, create_schema_table, get_all_tables, make_old_format, get_schema_triggers_record, 5, 6, 0}, + {"USER_PRIVILEGES", user_privileges_fields_info, create_schema_table, + fill_schema_user_privileges, 0, 0, -1, -1, 0}, {"VARIABLES", variables_fields_info, create_schema_table, fill_variables, make_old_format, 0, -1, -1, 1}, {"VIEWS", view_fields_info, create_schema_table, get_all_tables, 0, get_schema_views_record, 1, 2, 0}, - {"USER_PRIVILEGES", user_privileges_fields_info, create_schema_table, - fill_schema_user_privileges, 0, 0, -1, -1, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0} }; diff --git a/sql/table.h b/sql/table.h index 947316e253f5bd1bfbed56409be066cf887432b6..78a942ef3016c7ca4a108e4e1a71b2f4490a86f8 100644 --- a/sql/table.h +++ b/sql/table.h @@ -309,9 +309,9 @@ enum enum_schema_tables SCH_TABLE_NAMES, SCH_TABLE_PRIVILEGES, SCH_TRIGGERS, + SCH_USER_PRIVILEGES, SCH_VARIABLES, - SCH_VIEWS, - SCH_USER_PRIVILEGES + SCH_VIEWS };