Skip to content

Commit 2d44cc3

Browse files
committed
Bug#35201901: Server failure of MySQL #3
Some minor refactoring of function find_item_in_list() before the fix. - Code is generally aligned with coding standard. - Error handling is separated out, now is is false for success and true for error. - The found item is now an output argument, and a null pointer means the item was not found (along with the other two out arguments). - The report_error argument is removed since it was always used as REPORT_EXCEPT_NOT_FOUND. - A local variable "find_ident" is introduced, since it better represents that we are searching for a column reference than having separate field_name, table_name and db_name variables. Item_field::replace_with_derived_expr_ref() - Redundant tests were removed. Function resolve_ref_in_select_and_group() has also been changed so that success/error is now returned as false/true, and the found item is an out argument. Function Item_field::fix_fields() - The value of thd->lex->current_query_block() is cached in a local variable. - Since single resolving was introduced, a test for "field" equal to nullptr was redundant and could be eliminated, along with the indented code block that followed. - A code block for checking bitmaps if the above test was false could also be removed. Change-Id: I3cd4bd6a23dd07faff773bdf11940bcfd847c903
1 parent 952f330 commit 2d44cc3

File tree

5 files changed

+311
-371
lines changed

5 files changed

+311
-371
lines changed

sql/aggregate_check.cc

+13-13
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ bool Distinct_check::check_query(THD *thd) {
116116
assert((*order->item)->fixed);
117117
uint counter;
118118
enum_resolution_type resolution;
119+
Item **res;
119120
/*
120121
Search if this expression is equal to one in the SELECT
121122
list. setup_order()/find_order_in_list() has already done so, but not
@@ -145,12 +146,11 @@ bool Distinct_check::check_query(THD *thd) {
145146
differ due to white space....).
146147
Subqueries in ORDER BY are non-standard anyway.
147148
*/
148-
Item **const res =
149-
find_item_in_list(thd, *order->item, &select->fields, &counter,
150-
REPORT_EXCEPT_NOT_FOUND, &resolution);
151-
if (res == nullptr) // Other error than "not found", my_error() was called
152-
return true; /* purecov: inspected */
153-
if (res != not_found_item) // is in SELECT list
149+
if (find_item_in_list(thd, *order->item, &select->fields, &res, &counter,
150+
&resolution)) {
151+
return true; /* purecov: inspected */
152+
}
153+
if (res != nullptr) // is in SELECT list
154154
continue;
155155
/*
156156
[numbers refer to the function's comment]
@@ -269,13 +269,13 @@ bool Group_check::check_expression(THD *thd, Item *expr, bool in_select_list) {
269269
if (!in_select_list) {
270270
uint counter;
271271
enum_resolution_type resolution;
272-
// Search if this expression is equal to one in the SELECT list.
273-
Item **const res = find_item_in_list(thd, expr, &select->fields, &counter,
274-
REPORT_EXCEPT_NOT_FOUND, &resolution);
275-
if (res == nullptr) // Other error than "not found", my_error() was called
276-
return true; /* purecov: inspected */
277-
if (res != not_found_item) {
278-
// is in SELECT list, which has already been validated.
272+
Item **res;
273+
// Check if this expression is equal to one in the SELECT list.
274+
if (find_item_in_list(thd, expr, &select->fields, &res, &counter,
275+
&resolution)) {
276+
return true; /* purecov: inspected */
277+
}
278+
if (res != nullptr) { // in SELECT list, which has already been validated.
279279
return false;
280280
}
281281
}

0 commit comments

Comments
 (0)