Commit 7a903784 authored by Sergei Golubchik's avatar Sergei Golubchik

cleanup: Item_func_case

reorder items in args[] array. Instead of

  when1,then1,when2,then2,...[,case][,else]

sort them as

  [case,]when1,when2,...,then1,then2,...[,else]

in this case all items used for comparison take a continuous part
of the array and can be aggregated directly. and all items that
can be returned take a continuous part of the array and can be
aggregated directly. Old code had to copy them to a temporary
array before aggreation, and then copy back (thd->change_item_tree)
everything that was changed.

this is a 10.3 version of bf1ca14f
parent 4c77ef36
......@@ -1630,7 +1630,7 @@ c
NULL
Warnings:
Note 1105 DBUG: [0] arg=1 handler=0 (bigint)
Note 1105 DBUG: [1] arg=3 handler=1 (decimal)
Note 1105 DBUG: [1] arg=2 handler=1 (decimal)
DROP TABLE t1;
#
# MDEV-11555 CASE with a mixture of TIME and DATETIME returns a wrong result
......@@ -1649,9 +1649,9 @@ good was_bad_now_good
one one
Warnings:
Note 1105 DBUG: [0] arg=1 handler=0 (time)
Note 1105 DBUG: [1] arg=3 handler=0 (time)
Note 1105 DBUG: [1] arg=2 handler=0 (time)
Note 1105 DBUG: [0] arg=1 handler=0 (time)
Note 1105 DBUG: [1] arg=3 handler=0 (time)
Note 1105 DBUG: [2] arg=5 handler=2 (datetime)
Note 1105 DBUG: [1] arg=2 handler=0 (time)
Note 1105 DBUG: [2] arg=3 handler=2 (datetime)
SET SESSION debug_dbug="-d,Predicant_to_list_comparator";
SET SESSION debug_dbug="-d,Item_func_in";
This diff is collapsed.
......@@ -2104,15 +2104,13 @@ class Item_func_case :public Item_func_case_expression
protected:
String tmp_value;
DTCollation cmp_collation;
Item **arg_buffer;
bool aggregate_then_and_else_arguments(THD *thd,
Item **items, uint count,
Item **else_expr);
bool aggregate_then_and_else_arguments(THD *thd, uint count);
virtual Item **else_expr_addr() const= 0;
virtual Item *find_item()= 0;
void print_when_then_arguments(String *str, enum_query_type query_type,
Item **items, uint count);
void print_else_argument(String *str, enum_query_type query_type, Item *item);
void reorder_args(uint start);
public:
Item_func_case(THD *thd, List<Item> &list)
:Item_func_case_expression(thd, list)
......@@ -2129,13 +2127,6 @@ class Item_func_case :public Item_func_case_expression
enum precedence precedence() const { return BETWEEN_PRECEDENCE; }
CHARSET_INFO *compare_collation() const { return cmp_collation.collation; }
bool need_parentheses_in_default() { return true; }
Item *build_clone(THD *thd)
{
Item_func_case *clone= (Item_func_case *) Item_func::build_clone(thd);
if (clone)
clone->arg_buffer= 0;
return clone;
}
};
......@@ -2156,6 +2147,7 @@ class Item_func_case_searched: public Item_func_case
:Item_func_case(thd, list)
{
DBUG_ASSERT(arg_count >= 2);
reorder_args(0);
}
void print(String *str, enum_query_type query_type);
void fix_length_and_dec();
......@@ -2200,6 +2192,7 @@ class Item_func_case_simple: public Item_func_case,
m_found_types(0)
{
DBUG_ASSERT(arg_count >= 3);
reorder_args(1);
}
void cleanup()
{
......@@ -2233,8 +2226,7 @@ class Item_func_decode_oracle: public Item_func_case_simple
:Item_func_case_simple(thd, list)
{ }
const char *func_name() const { return "decode_oracle"; }
void print(String *str, enum_query_type query_type)
{ Item_func::print(str, query_type); }
void print(String *str, enum_query_type query_type);
void fix_length_and_dec();
Item *find_item();
Item *get_copy(THD *thd)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment