From a400e7feb97945db310a6a31ecb0e882bc01b1a5 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 31 Jan 2006 21:48:32 -0800 Subject: FIxed bug #14927. A query with a group by and having clauses could return a wrong result set if the having condition contained a constant conjunct evaluated to FALSE. It happened because the pushdown condition for table with grouping columns lost its constant conjuncts. Pushdown conditions are always built by the function make_cond_for_table that ignores constant conjuncts. This is apparently not correct when constant false conjuncts are present. mysql-test/r/having.result: Added A test case for bug #14927. mysql-test/t/having.test: Added A test case for bug #14927. sql/sql_lex.cc: Fixed bug #14927. Initialized fields for having conditions in st_select_lex::init_query(). sql/sql_lex.h: Fixed bug #14927. Added a field to restore having condititions for execution in SP and PS. sql/sql_prepare.cc: Fixed bug #14927. Added code to restore havinf conditions for execution in SP and PS. sql/sql_select.cc: Fixed bug #14927. Performed evaluation of constant expressions in having clauses. If the having condition contains a constant conjunct that is always false an empty result set is returned after the optimization phase. In this case the corresponding EXPLAIN command now returns "Impossible HAVING" in the last column. --- sql/sql_select.cc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'sql/sql_select.cc') diff --git a/sql/sql_select.cc b/sql/sql_select.cc index ec62e80ba13..27c8ac126fa 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -501,12 +501,18 @@ JOIN::optimize() DBUG_RETURN(1); } - if (cond_value == Item::COND_FALSE || - (!unit->select_limit_cnt && !(select_options & OPTION_FOUND_ROWS))) - { /* Impossible cond */ - zero_result_cause= "Impossible WHERE"; - error= 0; - DBUG_RETURN(0); + { + Item::cond_result having_value; + having= optimize_cond(thd, having, &having_value); + + if (cond_value == Item::COND_FALSE || having_value == Item::COND_FALSE || + (!unit->select_limit_cnt && !(select_options & OPTION_FOUND_ROWS))) + { /* Impossible cond */ + zero_result_cause= having_value == Item::COND_FALSE ? + "Impossible HAVING" : "Impossible WHERE"; + error= 0; + DBUG_RETURN(0); + } } /* Optimize count(*), min() and max() */ @@ -4611,10 +4617,8 @@ optimize_cond(THD *thd, COND *conds, Item::cond_result *cond_value) DBUG_EXECUTE("info", print_where(conds, "after remove");); } else - { *cond_value= Item::COND_TRUE; - select->prep_where= 0; - } + DBUG_RETURN(conds); } -- cgit v1.2.1 From 7ea60ae91e0f0067976d21240ab07df7afdb177f Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 1 Feb 2006 20:43:43 -0800 Subject: Fixed bug #16382. When an ambiguous field name is used in a group by clause a warning is issued in the find_order_in_list function by a call to push_warning_printf. An expression that was not always valid was passed to this call as the field name parameter. mysql-test/r/view.result: Added a test case for bug #16382. mysql-test/t/view.test: Added a test case for bug #16382. --- sql/sql_select.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sql/sql_select.cc') diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 63d46934555..f23260e6bf8 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12381,7 +12381,8 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, overshadows the column reference from the SELECT list. */ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR, - ER(ER_NON_UNIQ_ERROR), from_field->field_name, + ER(ER_NON_UNIQ_ERROR), + ((Item_ident*) order_item)->field_name, current_thd->where); } } -- cgit v1.2.1 From 6757503847039fa8758dffc7263a38a792848685 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Feb 2006 20:37:58 -0800 Subject: Post-review fix for bug #14927. --- sql/sql_select.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'sql/sql_select.cc') diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 27c8ac126fa..f996ca82970 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -504,6 +504,12 @@ JOIN::optimize() { Item::cond_result having_value; having= optimize_cond(thd, having, &having_value); + if (thd->net.report_error) + { + error= 1; + DBUG_PRINT("error",("Error from optimize_cond")); + DBUG_RETURN(1); + } if (cond_value == Item::COND_FALSE || having_value == Item::COND_FALSE || (!unit->select_limit_cnt && !(select_options & OPTION_FOUND_ROWS))) -- cgit v1.2.1 From ac21d0294dfd6a61a042c9fc6afa5eef2f7afa6a Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Feb 2006 23:56:08 -0800 Subject: Fixes after manual merge --- sql/sql_select.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/sql_select.cc') diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 6d3c32b1239..9160c023576 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -628,7 +628,7 @@ JOIN::optimize() { Item::cond_result having_value; - having= optimize_cond(thd, having, &having_value); + having= optimize_cond(this, having, join_list, &having_value); if (thd->net.report_error) { error= 1; @@ -641,7 +641,7 @@ JOIN::optimize() { /* Impossible cond */ DBUG_PRINT("info", (having_value == Item::COND_FALSE ? "Impossible HAVING" : "Impossible WHERE")); - zero_result_cause= ? + zero_result_cause= having_value == Item::COND_FALSE ? "Impossible HAVING" : "Impossible WHERE"; error= 0; DBUG_RETURN(0); -- cgit v1.2.1