diff options
author | Igor Babaev <igor@askmonty.org> | 2012-03-08 22:33:01 -0800 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2012-03-08 22:33:01 -0800 |
commit | af7213d5d483afce7256b646cb943a9973be2a53 (patch) | |
tree | 9feff2eda83e9cb8b2aa32262b504dcbe211069e /sql/opt_sum.cc | |
parent | 026161370feeefd0bdeb37de8d9a4497ab572f55 (diff) | |
download | mariadb-git-af7213d5d483afce7256b646cb943a9973be2a53.tar.gz |
Fixed LP bug #884175.
If in the where clause of the a query some comparison conditions on the
field under a MIN/MAX aggregate function contained constants whose sizes
exceeded the size of the field then the query could return a wrong result
when the optimizer had chosen to apply the MIN/MAX optimization.
With such conditions the MIN/MAX optimization still could be applied, yet
it would require a more thorough analysis of the keys built to find
the value of MIN/MAX aggregate functions with index look-ups.
The current patch just prohibits using the MIN/MAX optimization in this
situation.
Diffstat (limited to 'sql/opt_sum.cc')
-rw-r--r-- | sql/opt_sum.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index cd6e7a4ffaa..92a286a3b1c 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -469,8 +469,8 @@ int opt_sum_query(THD *thd, 'const op field' @retval - 0 func_item is a simple predicate: a field is compared with - constants + 0 func_item is a simple predicate: a field is compared with a constant + whose length does not exceed the max length of the field values @retval 1 Otherwise */ @@ -490,6 +490,8 @@ bool simple_pred(Item_func *func_item, Item **args, bool *inv_order) return 0; if (!(args[1]= item_equal->get_const())) return 0; + if (args[0]->max_length < args[1]->max_length) + return 0; } break; case 1: @@ -521,6 +523,8 @@ bool simple_pred(Item_func *func_item, Item **args, bool *inv_order) } else return 0; + if (args[0]->max_length < args[1]->max_length) + return 0; break; case 3: /* field BETWEEN const AND const */ @@ -534,6 +538,8 @@ bool simple_pred(Item_func *func_item, Item **args, bool *inv_order) if (!item->const_item()) return 0; args[i]= item; + if (args[0]->max_length < args[i]->max_length) + return 0; } } else |