Hi Alexander!
I was looking through this patch as I am rather familiar with this code. I didn't take time to test this out, but maybe you can explain if this is a possible concern or not:
index 4a95189..7d1532c 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -404,7 +404,7 @@ bool Item_sum::register_sum_func(THD *thd, Item **ref)
for (sl= thd->lex->current_select;
sl && sl != aggr_sel && sl->master_unit()->item;
sl= sl->master_unit()->outer_select() )
- sl->master_unit()->item->with_sum_func= 1;
+ sl->master_unit()->item->get_with_sum_func_cache()->set_with_sum_func();
}
thd->lex->current_select->mark_as_dependent(thd, aggr_sel, NULL);
@@ -484,7 +484,6 @@ void Item_sum::mark_as_sum_func()
cur_select->n_sum_items++;
cur_select->with_sum_func= 1;
const_item_cache= false;
- with_sum_func= 1;
with_field= 0;
window_func_sum_expr_flag= false;
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 96f1153..37f3fe0 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -582,6 +582,8 @@ class Item_sum :public Item_func_or_sum
void mark_as_window_func_sum_expr() { window_func_sum_expr_flag= true; }
bool is_window_func_sum_expr() { return window_func_sum_expr_flag; }
virtual void setup_caches(THD *thd) {};
+
+ bool with_sum_func() const { return true; }
};
For Item_sum::register_sum_func, if sl->master_unit()->item is an Item_sum_sum for example, an Item_sum won't have get_with_sum_func_cache() overwritten so it will be the base Item::get_with_sum_func_cache(), which returns null and you will crash. Am I missing something?
Is it impossible for sl->master_unit()->item to be an Item_sum_... subclass?
I am not a very big fan of the get_with_sum_func_cache() indirection required and would prefer, if possible to call set_with_sum_func() directly. Perhaps behind the scenes the set function can do that and throw an assert if the call is illegal? (Just an opinion, not something I have a very very strong opinion on.
Also, I have a feeling that it's sufficient to keep just join_with_sum_func. I can't really think of a place where that was not the intent anyway, but those few cases where copy_with_sum_func is used need to be analysed throughly to make sure.
Regards,
Vicențiu
PS: Yes, the review assigned to me is coming :)