diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 9d993e723c2..437c2aa0f84 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1934,6 +1934,26 @@ event_object_table trigger_name # Switching to connection 'default'. # # +# MDEV-3818: Query against view over IS tables worse than equivalent query without view +# +CREATE VIEW v1 AS SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS; +explain extended +SELECT column_name FROM v1 +WHERE (TABLE_SCHEMA = "osm") AND (TABLE_NAME = "test"); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE COLUMNS ALL NULL TABLE_SCHEMA,TABLE_NAME NULL NULL NULL NULL Using where; Open_frm_only; Scanned 0 databases +Warnings: +Note 1003 select `information_schema`.`COLUMNS`.`COLUMN_NAME` AS `COLUMN_NAME` from `INFORMATION_SCHEMA`.`COLUMNS` where ((`information_schema`.`COLUMNS`.`TABLE_SCHEMA` = 'osm') and (`information_schema`.`COLUMNS`.`TABLE_NAME` = 'test')) +explain extended +SELECT INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME AS COLUMN_NAME +FROM INFORMATION_SCHEMA.COLUMNS +WHERE (information_schema.COLUMNS.TABLE_SCHEMA = 'osm') and (information_schema.COLUMNS.TABLE_NAME = 'test'); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE COLUMNS ALL NULL TABLE_SCHEMA,TABLE_NAME NULL NULL NULL NULL Using where; Open_frm_only; Scanned 0 databases +Warnings: +Note 1003 select `information_schema`.`COLUMNS`.`COLUMN_NAME` AS `COLUMN_NAME` from `INFORMATION_SCHEMA`.`COLUMNS` where ((`information_schema`.`COLUMNS`.`TABLE_SCHEMA` = 'osm') and (`information_schema`.`COLUMNS`.`TABLE_NAME` = 'test')) +drop view v1; +# # Clean-up. drop database mysqltest; # diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index e95f41f6c8d..9ed61a90be2 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1789,6 +1789,24 @@ disconnect con12828477_1; disconnect con12828477_2; disconnect con12828477_3; + +--echo # +--echo # MDEV-3818: Query against view over IS tables worse than equivalent query without view +--echo # + +CREATE VIEW v1 AS SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS; + +explain extended +SELECT column_name FROM v1 +WHERE (TABLE_SCHEMA = "osm") AND (TABLE_NAME = "test"); + +explain extended +SELECT INFORMATION_SCHEMA.COLUMNS.COLUMN_NAME AS COLUMN_NAME +FROM INFORMATION_SCHEMA.COLUMNS +WHERE (information_schema.COLUMNS.TABLE_SCHEMA = 'osm') and (information_schema.COLUMNS.TABLE_NAME = 'test'); + +drop view v1; + --echo # --echo # Clean-up. drop database mysqltest; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 08a08aa1eb6..6977b84524f 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -3184,13 +3184,13 @@ bool get_lookup_value(THD *thd, Item_func *item_func, Item_field *item_field; CHARSET_INFO *cs= system_charset_info; - if (item_func->arguments()[0]->type() == Item::FIELD_ITEM && + if (item_func->arguments()[0]->real_item()->type() == Item::FIELD_ITEM && item_func->arguments()[1]->const_item()) { idx_field= 0; idx_val= 1; } - else if (item_func->arguments()[1]->type() == Item::FIELD_ITEM && + else if (item_func->arguments()[1]->real_item()->type() == Item::FIELD_ITEM && item_func->arguments()[0]->const_item()) { idx_field= 1; @@ -3199,7 +3199,7 @@ bool get_lookup_value(THD *thd, Item_func *item_func, else return 0; - item_field= (Item_field*) item_func->arguments()[idx_field]; + item_field= (Item_field*) item_func->arguments()[idx_field]->real_item(); if (table->table != item_field->field->table) return 0; tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);