Skip to content

Commit

Permalink
Bug#35201901: Server failure of MySQL #3
Browse files Browse the repository at this point in the history
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
  • Loading branch information
roylyseng committed Apr 25, 2023
1 parent 952f330 commit 2d44cc3
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 371 deletions.
26 changes: 13 additions & 13 deletions sql/aggregate_check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ bool Distinct_check::check_query(THD *thd) {
assert((*order->item)->fixed);
uint counter;
enum_resolution_type resolution;
Item **res;
/*
Search if this expression is equal to one in the SELECT
list. setup_order()/find_order_in_list() has already done so, but not
Expand Down Expand Up @@ -145,12 +146,11 @@ bool Distinct_check::check_query(THD *thd) {
differ due to white space....).
Subqueries in ORDER BY are non-standard anyway.
*/
Item **const res =
find_item_in_list(thd, *order->item, &select->fields, &counter,
REPORT_EXCEPT_NOT_FOUND, &resolution);
if (res == nullptr) // Other error than "not found", my_error() was called
return true; /* purecov: inspected */
if (res != not_found_item) // is in SELECT list
if (find_item_in_list(thd, *order->item, &select->fields, &res, &counter,
&resolution)) {
return true; /* purecov: inspected */
}
if (res != nullptr) // is in SELECT list
continue;
/*
[numbers refer to the function's comment]
Expand Down Expand Up @@ -269,13 +269,13 @@ bool Group_check::check_expression(THD *thd, Item *expr, bool in_select_list) {
if (!in_select_list) {
uint counter;
enum_resolution_type resolution;
// Search if this expression is equal to one in the SELECT list.
Item **const res = find_item_in_list(thd, expr, &select->fields, &counter,
REPORT_EXCEPT_NOT_FOUND, &resolution);
if (res == nullptr) // Other error than "not found", my_error() was called
return true; /* purecov: inspected */
if (res != not_found_item) {
// is in SELECT list, which has already been validated.
Item **res;
// Check if this expression is equal to one in the SELECT list.
if (find_item_in_list(thd, expr, &select->fields, &res, &counter,
&resolution)) {
return true; /* purecov: inspected */
}
if (res != nullptr) { // in SELECT list, which has already been validated.
return false;
}
}
Expand Down
Loading

0 comments on commit 2d44cc3

Please sign in to comment.