MDEV-3818: Query against view over IS tables worse than equivalent query without view
Analysis: The reason for the suboptimal plan when querying IS tables through a view was that the view columns that participate in an equality are wrapped by an Item_direct_view_ref and were not recognized as being direct column references. Solution: Use the original Item_field objects via the real_item() method.
This commit is contained in:
parent
a334e87d65
commit
d7a0148758
@ -1934,6 +1934,26 @@ event_object_table trigger_name
|
|||||||
# Switching to connection 'default'.
|
# 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.
|
# Clean-up.
|
||||||
drop database mysqltest;
|
drop database mysqltest;
|
||||||
#
|
#
|
||||||
|
@ -1789,6 +1789,24 @@ disconnect con12828477_1;
|
|||||||
disconnect con12828477_2;
|
disconnect con12828477_2;
|
||||||
disconnect con12828477_3;
|
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 #
|
||||||
--echo # Clean-up.
|
--echo # Clean-up.
|
||||||
drop database mysqltest;
|
drop database mysqltest;
|
||||||
|
@ -3184,13 +3184,13 @@ bool get_lookup_value(THD *thd, Item_func *item_func,
|
|||||||
Item_field *item_field;
|
Item_field *item_field;
|
||||||
CHARSET_INFO *cs= system_charset_info;
|
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())
|
item_func->arguments()[1]->const_item())
|
||||||
{
|
{
|
||||||
idx_field= 0;
|
idx_field= 0;
|
||||||
idx_val= 1;
|
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())
|
item_func->arguments()[0]->const_item())
|
||||||
{
|
{
|
||||||
idx_field= 1;
|
idx_field= 1;
|
||||||
@ -3199,7 +3199,7 @@ bool get_lookup_value(THD *thd, Item_func *item_func,
|
|||||||
else
|
else
|
||||||
return 0;
|
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)
|
if (table->table != item_field->field->table)
|
||||||
return 0;
|
return 0;
|
||||||
tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);
|
tmp_str= item_func->arguments()[idx_val]->val_str(&str_buff);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user