diff options
author | unknown <evgen@moonbone.local> | 2006-08-15 21:02:55 +0400 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2006-08-15 21:02:55 +0400 |
commit | c2ef98ad4c81a84bba7f36405f5d6f2384213aa9 (patch) | |
tree | c98c3c3173a3f84b33e283f6b4d1f13f84ba7bb6 /sql | |
parent | 22485f4a5923c08c62a23b8f09770a90164dedae (diff) | |
download | mariadb-git-c2ef98ad4c81a84bba7f36405f5d6f2384213aa9.tar.gz |
Fixed bug#15950: NOW() optimized away in VIEWs
This bug is a side-effect of bug fix #16377. NOW() is optimized in
BETWEEN to integer constants to speed up query execution. When view is being
created it saves already modified query and thus becomes wrong.
The agg_cmp_type() function now substitutes constant result DATE/TIME functions
for their results only if the current query isn't CREATE VIEW or SHOW CREATE
VIEW.
mysql-test/t/view.test:
Added a test case for bug#15950: NOW() optimized away in VIEWs
mysql-test/r/view.result:
Added a test case for bug#15950: NOW() optimized away in VIEWs
sql/item_cmpfunc.cc:
Fixed bug#15950: NOW() optimized away in VIEWs
The agg_cmp_type() function now substitutes constant result DATE/TIME functions
for their results only if the current query isn't CREATE VIEW or SHOW CREATE
VIEW.
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_cmpfunc.cc | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 34170124cd7..e840cdbdd13 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -125,31 +125,39 @@ static void agg_cmp_type(THD *thd, Item_result *type, Item **items, uint nitems) uchar null_byte; Field *field= NULL; - /* Search for date/time fields/functions */ - for (i= 0; i < nitems; i++) + /* + Do not convert items while creating a or showing a view in order + to store/display the original query in these cases. + */ + if (thd->lex->sql_command != SQLCOM_CREATE_VIEW && + thd->lex->sql_command != SQLCOM_SHOW_CREATE) { - if (!items[i]->result_as_longlong()) + /* Search for date/time fields/functions */ + for (i= 0; i < nitems; i++) { - /* Do not convert anything if a string field/function is present */ - if (!items[i]->const_item() && items[i]->result_type() == STRING_RESULT) + if (!items[i]->result_as_longlong()) + { + /* Do not convert anything if a string field/function is present */ + if (!items[i]->const_item() && items[i]->result_type() == STRING_RESULT) + { + i= nitems; + break; + } + continue; + } + if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM && + items[i]->result_type() != INT_RESULT) { - i= nitems; + field= ((Item_field *)items[i]->real_item())->field; + break; + } + else if (res == Item::FUNC_ITEM) + { + field= items[i]->tmp_table_field_from_field_type(0); + if (field) + field->move_field(buff, &null_byte, 0); break; } - continue; - } - if ((res= items[i]->real_item()->type()) == Item::FIELD_ITEM && - items[i]->result_type() != INT_RESULT) - { - field= ((Item_field *)items[i]->real_item())->field; - break; - } - else if (res == Item::FUNC_ITEM) - { - field= items[i]->tmp_table_field_from_field_type(0); - if (field) - field->move_field(buff, &null_byte, 0); - break; } } if (field) |