From 2ebfb836ab62ccf3cb45d2e527c0635b9bb64094 Mon Sep 17 00:00:00 2001 From: "Sinisa@sinisa.nasamreza.org" <> Date: Mon, 17 Mar 2003 15:16:26 +0200 Subject: [PATCH 1/4] A fix for a bug reported by Per Erik Martin, partaining to usage of expressions whose result are to be saved into user vars. --- sql/item.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/sql/item.cc b/sql/item.cc index 3c6b85e933b..becda6751bc 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1192,7 +1192,16 @@ bool Item_ref::fix_fields(THD *thd,TABLE_LIST *tables, Item **reference) } } - if (((*ref)->with_sum_func && +/* + * The following conditional is changed as to correctly identify + * incorrect references in group functions or forward references + * with sub-select's / derived tables, while it prevents this + * check when Item_ref is created in an expression involving + * summing function, which is to be placed in the user variable. + * + */ + + if (((*ref)->with_sum_func && name && (depended_from || !(thd->lex.current_select->linkage != GLOBAL_OPTIONS_TYPE && thd->lex.current_select->select_lex()->having_fix_field))) || From 07c96e1ea74cf6ed6e046512d449e5663ee39ecf Mon Sep 17 00:00:00 2001 From: "Sinisa@sinisa.nasamreza.org" <> Date: Thu, 20 Mar 2003 20:44:56 +0200 Subject: [PATCH 2/4] A test case for the bug fix as per PEM's reported bug #118. Patch is already commited and approved by Sanja ..;o) --- mysql-test/r/variables.result | 1 + mysql-test/t/variables.test | 1 + 2 files changed, 2 insertions(+) diff --git a/mysql-test/r/variables.result b/mysql-test/r/variables.result index 822fab5ae47..4b3046770dc 100644 --- a/mysql-test/r/variables.result +++ b/mysql-test/r/variables.result @@ -333,4 +333,5 @@ check table t1,t2; Table Op Msg_type Msg_text test.t1 check status OK test.t2 check status OK +select max(a) +1, max(a) +2 into @xx,@yy from t1; drop table t1,t2; diff --git a/mysql-test/t/variables.test b/mysql-test/t/variables.test index 4bde54f868a..7671b663738 100644 --- a/mysql-test/t/variables.test +++ b/mysql-test/t/variables.test @@ -241,5 +241,6 @@ select @@key_buffer_size; select * from t1 where a=2; select * from t2 where a=3; check table t1,t2; +select max(a) +1, max(a) +2 into @xx,@yy from t1; drop table t1,t2; From 85fb265c3c39b8fe737ad54bff798386fa4352b4 Mon Sep 17 00:00:00 2001 From: "Sinisa@sinisa.nasamreza.org" <> Date: Thu, 27 Mar 2003 16:11:01 +0200 Subject: [PATCH 3/4] Fixing a bug #195 Fixing UNION's popping up in slow query log --- mysql-test/r/cast.result | 3 +++ mysql-test/t/cast.test | 1 + sql/item_timefunc.h | 3 ++- sql/sql_union.cc | 8 ++++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index db28038526b..87615b4537e 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -37,3 +37,6 @@ cast("2001-1-1" as datetime) = "2001-01-01 00:00:00" select cast("1:2:3" as TIME) = "1:02:03"; cast("1:2:3" as TIME) = "1:02:03" 0 +select cast(NULL as DATE); +cast(NULL as DATE) +NULL diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 7a120ef5005..402adf276c5 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -20,3 +20,4 @@ select cast("1:2:3" as TIME); select cast("2001-1-1" as date) = "2001-01-01"; select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"; select cast("1:2:3" as TIME) = "1:02:03"; +select cast(NULL as DATE); diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 2ed126b58e5..87563cf9f47 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -527,7 +527,8 @@ public: { String *tmp=args[0]->val_str(a); null_value=args[0]->null_value; - tmp->set_charset(charset()); + if (tmp) + tmp->set_charset(charset()); return tmp; } void fix_length_and_dec() diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 5f7a1e44bde..2be8268e432 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -248,6 +248,7 @@ int st_select_lex_unit::exec() SELECT_LEX_NODE *lex_select_save= thd->lex.current_select; SELECT_LEX *select_cursor=first_select_in_union(), *last_select; LINT_INIT(last_select); + bool do_print_slow=0; if (executed && !(dependent || uncacheable)) DBUG_RETURN(0); @@ -313,6 +314,7 @@ int st_select_lex_unit::exec() thd->lex.current_select= lex_select_save; DBUG_RETURN(res); } + do_print_slow = do_print_slow || (select_cursor->options & (QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED)); } } optimized= 1; @@ -325,7 +327,6 @@ int st_select_lex_unit::exec() { List empty_list; empty_list.empty(); - thd->lex.select_lex.ftfunc_list= &empty_list; if (!thd->is_fatal_error) // Check if EOM { @@ -338,6 +339,8 @@ int st_select_lex_unit::exec() select_limit_cnt= HA_POS_ERROR; // no limit if (select_limit_cnt == HA_POS_ERROR) thd->options&= ~OPTION_FOUND_ROWS; + fake_select->ftfunc_list= &empty_list; + res= mysql_select(thd, &ref_pointer_array, &result_table_list, 0, item_list, NULL, global_parameters->order_list.elements, @@ -348,9 +351,10 @@ int st_select_lex_unit::exec() thd->limit_found_rows = (ulonglong)table->file->records; fake_select->exclude(); delete fake_select; + if (select_cursor == &thd->lex.select_lex && !do_print_slow) + select_cursor->options &= ~(QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED); } } - thd->lex.select_lex.ftfunc_list= &thd->lex.select_lex.ftfunc_list_alloc; thd->lex.current_select= lex_select_save; DBUG_RETURN(res); } From 165b3960beb00ef942a6a7bb10a071690b5b001a Mon Sep 17 00:00:00 2001 From: "Sinisa@sinisa.nasamreza.org" <> Date: Fri, 28 Mar 2003 16:57:03 +0200 Subject: [PATCH 4/4] Fixing crashing bugs as reported in bugs database #195 --- mysql-test/r/cast.result | 3 +++ mysql-test/t/cast.test | 1 + sql/item_cmpfunc.cc | 3 ++- sql/item_strfunc.h | 3 ++- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/cast.result b/mysql-test/r/cast.result index 87615b4537e..7909fabc971 100644 --- a/mysql-test/r/cast.result +++ b/mysql-test/r/cast.result @@ -40,3 +40,6 @@ cast("1:2:3" as TIME) = "1:02:03" select cast(NULL as DATE); cast(NULL as DATE) NULL +select cast(NULL as BINARY); +cast(NULL as BINARY) +NULL diff --git a/mysql-test/t/cast.test b/mysql-test/t/cast.test index 402adf276c5..8703a6b739d 100644 --- a/mysql-test/t/cast.test +++ b/mysql-test/t/cast.test @@ -21,3 +21,4 @@ select cast("2001-1-1" as date) = "2001-01-01"; select cast("2001-1-1" as datetime) = "2001-01-01 00:00:00"; select cast("1:2:3" as TIME) = "1:02:03"; select cast(NULL as DATE); +select cast(NULL as BINARY); diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index 4d2aaf5a0f2..09f0aeefb09 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -769,7 +769,8 @@ Item_func_if::val_str(String *str) { Item *arg= args[0]->val_int() ? args[1] : args[2]; String *res=arg->val_str(str); - res->set_charset(charset()); + if (res) + res->set_charset(charset()); null_value=arg->null_value; return res; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 07b7eb2d165..e403b970fe1 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -512,7 +512,8 @@ public: { String *tmp=args[0]->val_str(a); null_value=args[0]->null_value; - tmp->set_charset(&my_charset_bin); + if (tmp) + tmp->set_charset(&my_charset_bin); return tmp; } void fix_length_and_dec()