From 750a2a0b862ba6a02c341a6120a96a081a83ac4f Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Oct 2006 13:10:25 +0300 Subject: BUG#14019 : group by converts literal string to column name When resolving unqualified name references MySQL was not checking what is the item type for the reference. Thus e.g a string literal item that has by convention a name equal to its string value will also work as a reference to a SELECT list item or a table field. Fixed by allowing only Item_ref or Item_field to referenced by (unqualified) name. mysql-test/r/func_gconcat.result: Bug #14019: group by converts literal string to column name - removed undeterministic testcase : order by a constant means no order. mysql-test/r/group_by.result: Bug #14019: group by converts literal string to column name - test case mysql-test/t/func_gconcat.test: Bug #14019: group by converts literal string to column name - removed undeterministic testcase : order by a constant means no order. mysql-test/t/group_by.test: Bug #14019: group by converts literal string to column name - test case sql/sql_base.cc: Bug #14019: group by converts literal string to column name - resolve unqualified by name refs only for real references --- sql/sql_base.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sql/sql_base.cc') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 0a9529d6067..40adf5e1f15 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2284,12 +2284,19 @@ find_item_in_list(Item *find, List &items, uint *counter, const char *field_name=0; const char *table_name=0; bool found_unaliased_non_uniq= 0; + /* + true if the item that we search for is a valid name reference + (and not an item that happens to have a name). + */ + bool is_ref_by_name= 0; uint unaliased_counter; LINT_INIT(unaliased_counter); *unaliased= FALSE; - if (find->type() == Item::FIELD_ITEM || find->type() == Item::REF_ITEM) + is_ref_by_name= (find->type() == Item::FIELD_ITEM || + find->type() == Item::REF_ITEM); + if (is_ref_by_name) { field_name= ((Item_ident*) find)->field_name; table_name= ((Item_ident*) find)->table_name; @@ -2401,7 +2408,7 @@ find_item_in_list(Item *find, List &items, uint *counter, } } else if (!table_name && (item->eq(find,0) || - find->name && item->name && + is_ref_by_name && find->name && item->name && !my_strcasecmp(system_charset_info, item->name,find->name))) { -- cgit v1.2.1 From 6101fd25d0cafcdd785ca701ed9988cb3db61249 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 16 Oct 2006 14:25:28 -0700 Subject: Fixed bug #19579: at range analysis optimizer did not take into account predicates that become sargable after reading const tables. In some cases this resulted in choosing non-optimal execution plans. Now info of such potentially saragable predicates is saved in an array and after reading const tables we check whether this predicates has become saragable. mysql-test/r/select.result: Added a test case for bug #19579. mysql-test/t/select.test: Added a test case for bug #19579. sql/item_cmpfunc.cc: Fixed bug #19579: at range analysis optimizer did not take into account predicates that become sargable after reading const tables. Added a counter of between predicates. sql/sql_base.cc: Fixed bug #19579: at range analysis optimizer did not take into account predicates that become sargable after reading const tables. Added a counter of between predicates. sql/sql_lex.cc: Fixed bug #19579: at range analysis optimizer did not take into account predicates that become sargable after reading const tables. Added a counter of between predicates. sql/sql_lex.h: Fixed bug #19579: at range analysis optimizer did not take into account predicates that become sargable after reading const tables. Added a counter of between predicates. sql/sql_select.cc: Fixed bug #19579: at range analysis optimizer did not take into account predicates that become sargable after reading const tables. Now info of such potentially saragable predicates is saved in an array and after reading const tables we check whether this predicates has become saragable. --- sql/sql_base.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/sql_base.cc') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 047fb8f3cff..0939fb3a47e 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4906,6 +4906,7 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves, thd->set_query_id=1; select_lex->cond_count= 0; + select_lex->between_count= 0; for (table= tables; table; table= table->next_local) { -- cgit v1.2.1