mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Revert MDEV-16592 "Change Item::with_sum_func to a virtual method"
Added back variable 'with_sum_func' to Item class as a bit field. This made the code shorter, faster (removed some virtual methods, less code to create an initialized item etc) and made many Item's 7 bytes smaller. The code is also easier to understand as 'with_sum_func' is threated as any other Item variable when creating or copying items.
This commit is contained in:
committed by
Sergei Golubchik
parent
963e5e406d
commit
ae39f4f6d6
19
sql/item.cc
19
sql/item.cc
@@ -414,7 +414,7 @@ Item::Item(THD *thd):
|
||||
{
|
||||
DBUG_ASSERT(thd);
|
||||
maybe_null= with_window_func= with_field= in_rollup= with_param= 0;
|
||||
is_in_with_cycle= 0;
|
||||
is_in_with_cycle= with_sum_func= 0;
|
||||
fixed= 1; // Simple Item's doesn't have to be fixed
|
||||
is_autogenerated_name= 1;
|
||||
null_value= 0;
|
||||
@@ -486,6 +486,7 @@ Item::Item(THD *thd, Item *item):
|
||||
with_field(item->with_field),
|
||||
is_autogenerated_name(item->is_autogenerated_name),
|
||||
is_in_with_cycle(item->is_in_with_cycle),
|
||||
with_sum_func(item->with_sum_func),
|
||||
marker(item->marker),
|
||||
null_value(item->null_value),
|
||||
is_expensive_cache(-1),
|
||||
@@ -2248,7 +2249,7 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
else
|
||||
{
|
||||
/* Not a SUM() function */
|
||||
if (unlikely((!with_sum_func() && !(split_flags & SPLIT_SUM_SELECT))))
|
||||
if (unlikely((!with_sum_func && !(split_flags & SPLIT_SUM_SELECT))))
|
||||
{
|
||||
/*
|
||||
This is not a SUM function and there are no SUM functions inside.
|
||||
@@ -2256,7 +2257,7 @@ void Item::split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
*/
|
||||
return;
|
||||
}
|
||||
if (likely(with_sum_func() ||
|
||||
if (likely(with_sum_func ||
|
||||
(type() == FUNC_ITEM &&
|
||||
(((Item_func *) this)->functype() ==
|
||||
Item_func::ISNOTNULLTEST_FUNC ||
|
||||
@@ -5361,7 +5362,7 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
|
||||
ref->alias_name_used= TRUE;
|
||||
|
||||
/* If this is a non-aggregated field inside HAVING, search in GROUP BY. */
|
||||
if (select->having_fix_field && !ref->with_sum_func() && group_list)
|
||||
if (select->having_fix_field && !ref->with_sum_func && group_list)
|
||||
{
|
||||
group_by_ref= find_field_in_group_list(ref, group_list);
|
||||
|
||||
@@ -8052,13 +8053,13 @@ bool Item_ref::fix_fields(THD *thd, Item **reference)
|
||||
*/
|
||||
if (!((*ref)->type() == REF_ITEM &&
|
||||
((Item_ref *)(*ref))->ref_type() == OUTER_REF) &&
|
||||
(((*ref)->with_sum_func() && name.str &&
|
||||
(((*ref)->with_sum_func && name.str &&
|
||||
!(current_sel->get_linkage() != GLOBAL_OPTIONS_TYPE &&
|
||||
current_sel->having_fix_field)) ||
|
||||
!(*ref)->is_fixed()))
|
||||
{
|
||||
my_error(ER_ILLEGAL_REFERENCE, MYF(0),
|
||||
name.str, ((*ref)->with_sum_func() ?
|
||||
name.str, ((*ref)->with_sum_func ?
|
||||
"reference to group function":
|
||||
"forward reference in item list"));
|
||||
goto error;
|
||||
@@ -8084,7 +8085,7 @@ void Item_ref::set_properties()
|
||||
We have to remember if we refer to a sum function, to ensure that
|
||||
split_sum_func() doesn't try to change the reference.
|
||||
*/
|
||||
copy_with_sum_func(*ref);
|
||||
with_sum_func= (*ref)->with_sum_func;
|
||||
with_param= (*ref)->with_param;
|
||||
with_window_func= (*ref)->with_window_func;
|
||||
with_field= (*ref)->with_field;
|
||||
@@ -8566,7 +8567,7 @@ Item_cache_wrapper::Item_cache_wrapper(THD *thd, Item *item_arg):
|
||||
DBUG_ASSERT(orig_item->is_fixed());
|
||||
Type_std_attributes::set(orig_item);
|
||||
maybe_null= orig_item->maybe_null;
|
||||
copy_with_sum_func(orig_item);
|
||||
with_sum_func= orig_item->with_sum_func;
|
||||
with_param= orig_item->with_param;
|
||||
with_field= orig_item->with_field;
|
||||
name= item_arg->name;
|
||||
@@ -8978,7 +8979,7 @@ int Item_cache_wrapper::save_in_field(Field *to, bool no_conversions)
|
||||
|
||||
Item* Item_cache_wrapper::get_tmp_table_item(THD *thd)
|
||||
{
|
||||
if (!orig_item->with_sum_func() && !orig_item->const_item())
|
||||
if (!orig_item->with_sum_func && !orig_item->const_item())
|
||||
return new (thd->mem_root) Item_temptable_field(thd, result_field);
|
||||
return copy_or_same(thd);
|
||||
}
|
||||
|
||||
67
sql/item.h
67
sql/item.h
@@ -111,7 +111,6 @@ struct KEY_FIELD;
|
||||
struct SARGABLE_PARAM;
|
||||
class RANGE_OPT_PARAM;
|
||||
class SEL_TREE;
|
||||
class With_sum_func_cache;
|
||||
|
||||
enum precedence {
|
||||
LOWEST_PRECEDENCE,
|
||||
@@ -928,7 +927,8 @@ public:
|
||||
/* Indicates that name of this Item autogenerated or set by user */
|
||||
is_autogenerated_name:1,
|
||||
/* Indicates that this item is in CYCLE clause of WITH */
|
||||
is_in_with_cycle:1;
|
||||
is_in_with_cycle:1,
|
||||
with_sum_func:1; /* True if item contains a sum func */
|
||||
|
||||
int16 marker;
|
||||
|
||||
@@ -2413,9 +2413,6 @@ public:
|
||||
*/
|
||||
virtual bool with_subquery() const { DBUG_ASSERT(is_fixed()); return false; }
|
||||
|
||||
virtual bool with_sum_func() const { return false; }
|
||||
virtual With_sum_func_cache* get_with_sum_func_cache() { return NULL; }
|
||||
|
||||
Item* set_expr_cache(THD *thd);
|
||||
|
||||
virtual Item_equal *get_item_equal() { return NULL; }
|
||||
@@ -2542,47 +2539,6 @@ public:
|
||||
};
|
||||
#endif
|
||||
|
||||
class With_sum_func_cache
|
||||
{
|
||||
protected:
|
||||
bool m_with_sum_func; // True if the owner item contains a sum func
|
||||
public:
|
||||
With_sum_func_cache()
|
||||
:m_with_sum_func(false)
|
||||
{ }
|
||||
With_sum_func_cache(const Item *a)
|
||||
:m_with_sum_func(a->with_sum_func())
|
||||
{ }
|
||||
With_sum_func_cache(const Item *a, const Item *b)
|
||||
:m_with_sum_func(a->with_sum_func() || b->with_sum_func())
|
||||
{ }
|
||||
With_sum_func_cache(const Item *a, const Item *b, const Item *c)
|
||||
:m_with_sum_func(a->with_sum_func() || b->with_sum_func() ||
|
||||
c->with_sum_func())
|
||||
{ }
|
||||
With_sum_func_cache(const Item *a, const Item *b, const Item *c,
|
||||
const Item *d)
|
||||
:m_with_sum_func(a->with_sum_func() || b->with_sum_func() ||
|
||||
c->with_sum_func() || d->with_sum_func())
|
||||
{ }
|
||||
With_sum_func_cache(const Item *a, const Item *b, const Item *c,
|
||||
const Item *d, const Item *e)
|
||||
:m_with_sum_func(a->with_sum_func() || b->with_sum_func() ||
|
||||
c->with_sum_func() || d->with_sum_func() ||
|
||||
e->with_sum_func())
|
||||
{ }
|
||||
void set_with_sum_func() { m_with_sum_func= true; }
|
||||
void reset_with_sum_func() { m_with_sum_func= false; }
|
||||
void copy_with_sum_func(const Item *item)
|
||||
{
|
||||
m_with_sum_func= item->with_sum_func();
|
||||
}
|
||||
void join_with_sum_func(const Item *item)
|
||||
{
|
||||
m_with_sum_func|= item->with_sum_func();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
This class is a replacement for the former member Item::with_subselect.
|
||||
@@ -5385,8 +5341,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class Item_ref :public Item_ident,
|
||||
protected With_sum_func_cache
|
||||
class Item_ref :public Item_ident
|
||||
{
|
||||
protected:
|
||||
void set_properties();
|
||||
@@ -5426,12 +5381,11 @@ public:
|
||||
|
||||
/* Constructor need to process subselect with temporary tables (see Item) */
|
||||
Item_ref(THD *thd, Item_ref *item)
|
||||
:Item_ident(thd, item), With_sum_func_cache(*item),
|
||||
set_properties_only(0), ref(item->ref) {}
|
||||
Type type() const override { return REF_ITEM; }
|
||||
Type real_type() const override
|
||||
:Item_ident(thd, item), set_properties_only(0), ref(item->ref) {}
|
||||
enum Type type() const override { return REF_ITEM; }
|
||||
enum Type real_type() const override
|
||||
{ return ref ? (*ref)->type() : REF_ITEM; }
|
||||
bool eq(const Item *item, bool binary_cmp) const override
|
||||
bool eq(const Item *item, bool binary_cmp) const
|
||||
{
|
||||
Item *it= ((Item *) item)->real_item();
|
||||
return ref && (*ref)->eq(it, binary_cmp);
|
||||
@@ -5623,8 +5577,6 @@ public:
|
||||
return 0;
|
||||
return cleanup_processor(arg);
|
||||
}
|
||||
bool with_sum_func() const override { return m_with_sum_func; }
|
||||
With_sum_func_cache* get_with_sum_func_cache() override { return this; }
|
||||
Item *field_transformer_for_having_pushdown(THD *thd, uchar *arg) override
|
||||
{ return (*ref)->field_transformer_for_having_pushdown(thd, arg); }
|
||||
Item *remove_item_direct_ref() override
|
||||
@@ -5725,8 +5677,7 @@ class Expression_cache_tracker;
|
||||
*/
|
||||
|
||||
class Item_cache_wrapper :public Item_result_field,
|
||||
public With_subquery_cache,
|
||||
protected With_sum_func_cache
|
||||
public With_subquery_cache
|
||||
{
|
||||
private:
|
||||
/* Pointer on the cached expression */
|
||||
@@ -5755,8 +5706,6 @@ public:
|
||||
Type real_type() const override { return orig_item->type(); }
|
||||
bool with_subquery() const override
|
||||
{ DBUG_ASSERT(fixed); return m_with_subquery; }
|
||||
bool with_sum_func() const override { return m_with_sum_func; }
|
||||
With_sum_func_cache* get_with_sum_func_cache() override { return this; }
|
||||
|
||||
bool set_cache(THD *thd);
|
||||
Expression_cache_tracker* init_tracker(MEM_ROOT *mem_root);
|
||||
|
||||
@@ -1342,7 +1342,7 @@ bool Item_in_optimizer::fix_left(THD *thd)
|
||||
used_tables_cache= args[0]->used_tables();
|
||||
}
|
||||
eval_not_null_tables(NULL);
|
||||
copy_with_sum_func(args[0]);
|
||||
with_sum_func= args[0]->with_sum_func;
|
||||
with_param= args[0]->with_param || args[1]->with_param;
|
||||
with_field= args[0]->with_field;
|
||||
if ((const_item_cache= args[0]->const_item()))
|
||||
@@ -1354,7 +1354,7 @@ bool Item_in_optimizer::fix_left(THD *thd)
|
||||
{
|
||||
/* to avoid overriding is called to update left expression */
|
||||
used_tables_and_const_cache_join(args[1]);
|
||||
join_with_sum_func(args[1]);
|
||||
with_sum_func= with_sum_func || args[1]->with_sum_func;
|
||||
}
|
||||
DBUG_RETURN(0);
|
||||
}
|
||||
@@ -1390,7 +1390,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref)
|
||||
if (args[1]->maybe_null)
|
||||
maybe_null=1;
|
||||
m_with_subquery= true;
|
||||
join_with_sum_func(args[1]);
|
||||
with_sum_func= with_sum_func || args[1]->with_sum_func;
|
||||
with_field= with_field || args[1]->with_field;
|
||||
with_param= args[0]->with_param || args[1]->with_param;
|
||||
used_tables_and_const_cache_join(args[1]);
|
||||
@@ -1939,7 +1939,7 @@ bool Item_func_interval::fix_length_and_dec()
|
||||
max_length= 2;
|
||||
used_tables_and_const_cache_join(row);
|
||||
not_null_tables_cache= row->not_null_tables();
|
||||
join_with_sum_func(row);
|
||||
with_sum_func= with_sum_func || row->with_sum_func;
|
||||
with_param= with_param || row->with_param;
|
||||
with_field= with_field || row->with_field;
|
||||
return FALSE;
|
||||
@@ -4939,7 +4939,7 @@ Item_cond::fix_fields(THD *thd, Item **ref)
|
||||
const_item_cache= FALSE;
|
||||
}
|
||||
|
||||
join_with_sum_func(item);
|
||||
with_sum_func|= item->with_sum_func;
|
||||
with_param|= item->with_param;
|
||||
with_field|= item->with_field;
|
||||
m_with_subquery|= item->with_subquery();
|
||||
@@ -7058,7 +7058,7 @@ bool Item_equal::fix_fields(THD *thd, Item **ref)
|
||||
used_tables_cache|= item->used_tables();
|
||||
tmp_table_map= item->not_null_tables();
|
||||
not_null_tables_cache|= tmp_table_map;
|
||||
DBUG_ASSERT(!item->with_sum_func() && !item->with_subquery());
|
||||
DBUG_ASSERT(!item->with_sum_func && !item->with_subquery());
|
||||
if (item->maybe_null)
|
||||
maybe_null= 1;
|
||||
if (!item->get_item_equal())
|
||||
|
||||
@@ -134,7 +134,7 @@ void Item_func::sync_with_sum_func_and_with_field(List<Item> &list)
|
||||
Item *item;
|
||||
while ((item= li++))
|
||||
{
|
||||
join_with_sum_func(item);
|
||||
with_sum_func|= item->with_sum_func;
|
||||
with_window_func|= item->with_window_func;
|
||||
with_field|= item->with_field;
|
||||
with_param|= item->with_param;
|
||||
@@ -353,13 +353,11 @@ Item_func::fix_fields(THD *thd, Item **ref)
|
||||
return TRUE; /* purecov: inspected */
|
||||
item= *arg;
|
||||
|
||||
if (item->maybe_null)
|
||||
maybe_null=1;
|
||||
|
||||
join_with_sum_func(item);
|
||||
with_param= with_param || item->with_param;
|
||||
with_window_func= with_window_func || item->with_window_func;
|
||||
with_field= with_field || item->with_field;
|
||||
maybe_null |= item->maybe_null;
|
||||
with_sum_func |= item->with_sum_func;
|
||||
with_param |= item->with_param;
|
||||
with_window_func |= item->with_window_func;
|
||||
with_field |= item->with_field;
|
||||
used_tables_and_const_cache_join(item);
|
||||
not_null_tables_cache|= item->not_null_tables();
|
||||
m_with_subquery|= item->with_subquery();
|
||||
@@ -741,7 +739,7 @@ void Item_func::signal_divide_by_null()
|
||||
|
||||
Item *Item_func::get_tmp_table_item(THD *thd)
|
||||
{
|
||||
if (!Item_func::with_sum_func() && !const_item())
|
||||
if (!with_sum_func && !const_item())
|
||||
return new (thd->mem_root) Item_temptable_field(thd, result_field);
|
||||
return copy_or_same(thd);
|
||||
}
|
||||
@@ -3497,7 +3495,6 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func,
|
||||
}
|
||||
uint i;
|
||||
Item **arg,**arg_end;
|
||||
With_sum_func_cache *with_sum_func_cache= func->get_with_sum_func_cache();
|
||||
for (i=0, arg=arguments, arg_end=arguments+arg_count;
|
||||
arg != arg_end ;
|
||||
arg++,i++)
|
||||
@@ -3519,14 +3516,11 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func,
|
||||
*/
|
||||
if (item->collation.collation->state & MY_CS_BINSORT)
|
||||
func->collation.set(&my_charset_bin);
|
||||
if (item->maybe_null)
|
||||
func->maybe_null=1;
|
||||
if (with_sum_func_cache)
|
||||
with_sum_func_cache->join_with_sum_func(item);
|
||||
func->with_window_func= func->with_window_func ||
|
||||
item->with_window_func;
|
||||
func->with_field= func->with_field || item->with_field;
|
||||
func->with_param= func->with_param || item->with_param;
|
||||
func->maybe_null |= item->maybe_null;
|
||||
func->with_sum_func |= item->with_sum_func;
|
||||
func->with_window_func |= item->with_window_func;
|
||||
func->with_field |= item->with_field;
|
||||
func->with_param |= item->with_param;
|
||||
func->With_subquery_cache::join(item);
|
||||
func->used_tables_and_const_cache_join(item);
|
||||
f_args.arg_type[i]=item->result_type();
|
||||
|
||||
@@ -35,8 +35,7 @@ extern "C" /* Bug in BSDI include file */
|
||||
#include <cmath>
|
||||
|
||||
|
||||
class Item_func :public Item_func_or_sum,
|
||||
protected With_sum_func_cache
|
||||
class Item_func :public Item_func_or_sum
|
||||
{
|
||||
void sync_with_sum_func_and_with_field(List<Item> &list);
|
||||
protected:
|
||||
@@ -101,35 +100,41 @@ public:
|
||||
with_field= 0;
|
||||
with_param= 0;
|
||||
}
|
||||
Item_func(THD *thd, Item *a)
|
||||
:Item_func_or_sum(thd, a), With_sum_func_cache(a)
|
||||
Item_func(THD *thd, Item *a): Item_func_or_sum(thd, a)
|
||||
{
|
||||
with_sum_func= a->with_sum_func;
|
||||
with_param= a->with_param;
|
||||
with_field= a->with_field;
|
||||
}
|
||||
Item_func(THD *thd, Item *a, Item *b)
|
||||
:Item_func_or_sum(thd, a, b), With_sum_func_cache(a, b)
|
||||
Item_func(THD *thd, Item *a, Item *b):
|
||||
Item_func_or_sum(thd, a, b)
|
||||
{
|
||||
with_sum_func= a->with_sum_func || b->with_sum_func;
|
||||
with_param= a->with_param || b->with_param;
|
||||
with_field= a->with_field || b->with_field;
|
||||
}
|
||||
Item_func(THD *thd, Item *a, Item *b, Item *c)
|
||||
:Item_func_or_sum(thd, a, b, c), With_sum_func_cache(a, b, c)
|
||||
Item_func(THD *thd, Item *a, Item *b, Item *c):
|
||||
Item_func_or_sum(thd, a, b, c)
|
||||
{
|
||||
with_sum_func= a->with_sum_func || b->with_sum_func || c->with_sum_func;
|
||||
with_field= a->with_field || b->with_field || c->with_field;
|
||||
with_param= a->with_param || b->with_param || c->with_param;
|
||||
}
|
||||
Item_func(THD *thd, Item *a, Item *b, Item *c, Item *d)
|
||||
:Item_func_or_sum(thd, a, b, c, d), With_sum_func_cache(a, b, c, d)
|
||||
Item_func(THD *thd, Item *a, Item *b, Item *c, Item *d):
|
||||
Item_func_or_sum(thd, a, b, c, d)
|
||||
{
|
||||
with_sum_func= a->with_sum_func || b->with_sum_func ||
|
||||
c->with_sum_func || d->with_sum_func;
|
||||
with_field= a->with_field || b->with_field ||
|
||||
c->with_field || d->with_field;
|
||||
with_param= a->with_param || b->with_param ||
|
||||
c->with_param || d->with_param;
|
||||
}
|
||||
Item_func(THD *thd, Item *a, Item *b, Item *c, Item *d, Item* e)
|
||||
:Item_func_or_sum(thd, a, b, c, d, e), With_sum_func_cache(a, b, c, d, e)
|
||||
Item_func(THD *thd, Item *a, Item *b, Item *c, Item *d, Item* e):
|
||||
Item_func_or_sum(thd, a, b, c, d, e)
|
||||
{
|
||||
with_sum_func= a->with_sum_func || b->with_sum_func ||
|
||||
c->with_sum_func || d->with_sum_func || e->with_sum_func;
|
||||
with_field= a->with_field || b->with_field ||
|
||||
c->with_field || d->with_field || e->with_field;
|
||||
with_param= a->with_param || b->with_param ||
|
||||
@@ -141,8 +146,8 @@ public:
|
||||
set_arguments(thd, list);
|
||||
}
|
||||
// Constructor used for Item_cond_and/or (see Item comment)
|
||||
Item_func(THD *thd, Item_func *item)
|
||||
:Item_func_or_sum(thd, item), With_sum_func_cache(item),
|
||||
Item_func(THD *thd, Item_func *item):
|
||||
Item_func_or_sum(thd, item),
|
||||
not_null_tables_cache(item->not_null_tables_cache)
|
||||
{ }
|
||||
bool fix_fields(THD *, Item **ref);
|
||||
@@ -393,9 +398,6 @@ public:
|
||||
- or replaced to an Item_int_with_ref
|
||||
*/
|
||||
bool setup_args_and_comparator(THD *thd, Arg_comparator *cmp);
|
||||
|
||||
bool with_sum_func() const { return m_with_sum_func; }
|
||||
With_sum_func_cache* get_with_sum_func_cache() { return this; }
|
||||
Item_func *get_item_func() { return this; }
|
||||
bool is_simplified_cond_processor(void *arg)
|
||||
{ return const_item() && !val_int(); }
|
||||
|
||||
@@ -61,7 +61,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref)
|
||||
}
|
||||
}
|
||||
maybe_null|= item->maybe_null;
|
||||
join_with_sum_func(item);
|
||||
with_sum_func= with_sum_func || item->with_sum_func;
|
||||
with_window_func = with_window_func || item->with_window_func;
|
||||
with_field= with_field || item->with_field;
|
||||
m_with_subquery|= item->with_subquery();
|
||||
|
||||
@@ -36,8 +36,7 @@
|
||||
class Item_row: public Item_fixed_hybrid,
|
||||
private Item_args,
|
||||
private Used_tables_and_const_cache,
|
||||
private With_subquery_cache,
|
||||
private With_sum_func_cache
|
||||
private With_subquery_cache
|
||||
{
|
||||
table_map not_null_tables_cache;
|
||||
/**
|
||||
@@ -53,7 +52,6 @@ public:
|
||||
Item_row(THD *thd, Item_row *row)
|
||||
:Item_fixed_hybrid(thd), Item_args(thd, static_cast<Item_args*>(row)),
|
||||
Used_tables_and_const_cache(),
|
||||
With_sum_func_cache(*row),
|
||||
not_null_tables_cache(0), with_null(0)
|
||||
{ }
|
||||
|
||||
@@ -101,8 +99,6 @@ public:
|
||||
void cleanup();
|
||||
void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
List<Item> &fields, uint flags);
|
||||
bool with_sum_func() const { return m_with_sum_func; }
|
||||
With_sum_func_cache* get_with_sum_func_cache() { return this; }
|
||||
table_map used_tables() const { return used_tables_cache; };
|
||||
bool const_item() const { return const_item_cache; };
|
||||
void update_used_tables()
|
||||
|
||||
@@ -1059,7 +1059,7 @@ bool Item_subselect::const_item() const
|
||||
|
||||
Item *Item_subselect::get_tmp_table_item(THD *thd_arg)
|
||||
{
|
||||
if (!Item_subselect::with_sum_func() && !const_item())
|
||||
if (!with_sum_func && !const_item())
|
||||
return new (thd->mem_root) Item_temptable_field(thd_arg, result_field);
|
||||
return copy_or_same(thd_arg);
|
||||
}
|
||||
@@ -1262,7 +1262,7 @@ Item_singlerow_subselect::select_transformer(JOIN *join)
|
||||
if (!select_lex->master_unit()->is_unit_op() &&
|
||||
!select_lex->table_list.elements &&
|
||||
select_lex->item_list.elements == 1 &&
|
||||
!select_lex->item_list.head()->with_sum_func() &&
|
||||
!select_lex->item_list.head()->with_sum_func &&
|
||||
/*
|
||||
We can't change name of Item_field or Item_ref, because it will
|
||||
prevent its correct resolving, but we should save name of
|
||||
|
||||
@@ -47,8 +47,7 @@ class Cached_item;
|
||||
/* base class for subselects */
|
||||
|
||||
class Item_subselect :public Item_result_field,
|
||||
protected Used_tables_and_const_cache,
|
||||
protected With_sum_func_cache
|
||||
protected Used_tables_and_const_cache
|
||||
{
|
||||
/*
|
||||
Set to TRUE if the value is assigned for the subselect
|
||||
@@ -193,8 +192,6 @@ public:
|
||||
}
|
||||
bool fix_fields(THD *thd, Item **ref) override;
|
||||
bool with_subquery() const override { DBUG_ASSERT(fixed); return true; }
|
||||
bool with_sum_func() const override { return m_with_sum_func; }
|
||||
With_sum_func_cache* get_with_sum_func_cache() override { return this; }
|
||||
bool mark_as_dependent(THD *thd, st_select_lex *select, Item *item);
|
||||
void fix_after_pullout(st_select_lex *new_parent, Item **ref,
|
||||
bool merge) override;
|
||||
|
||||
@@ -407,7 +407,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->get_with_sum_func_cache()->set_with_sum_func();
|
||||
sl->master_unit()->item->with_sum_func= 1;
|
||||
}
|
||||
thd->lex->current_select->mark_as_dependent(thd, aggr_sel, NULL);
|
||||
|
||||
@@ -488,6 +488,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -587,8 +587,6 @@ public:
|
||||
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; }
|
||||
virtual void set_partition_row_count(ulonglong count) { DBUG_ASSERT(0); }
|
||||
};
|
||||
|
||||
|
||||
@@ -120,6 +120,7 @@ Item_window_func::fix_fields(THD *thd, Item **ref)
|
||||
|
||||
const_item_cache= false;
|
||||
with_window_func= true;
|
||||
with_sum_func= false;
|
||||
|
||||
if (fix_length_and_dec())
|
||||
return TRUE;
|
||||
|
||||
@@ -7711,7 +7711,7 @@ bool setup_fields(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
Item_window_func::split_sum_func.
|
||||
*/
|
||||
if (sum_func_list &&
|
||||
((item->with_sum_func() && item->type() != Item::SUM_FUNC_ITEM) ||
|
||||
((item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) ||
|
||||
item->with_window_func))
|
||||
{
|
||||
item->split_sum_func(thd, ref_pointer_array, *sum_func_list,
|
||||
|
||||
@@ -1233,7 +1233,7 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num,
|
||||
|
||||
while ((select_el= select_it++))
|
||||
{
|
||||
if (select_el->with_sum_func())
|
||||
if (select_el->with_sum_func)
|
||||
found_sum_func_elem= true;
|
||||
if (select_el->with_field)
|
||||
found_field_elem= true;
|
||||
@@ -1442,7 +1442,7 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num,
|
||||
item->max_length)))
|
||||
requires_sorting= TRUE;
|
||||
|
||||
if ((item->with_sum_func() && item->type() != Item::SUM_FUNC_ITEM) ||
|
||||
if ((item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) ||
|
||||
item->with_window_func)
|
||||
item->split_sum_func(thd, ref_ptrs, all_fields, SPLIT_SUM_SELECT);
|
||||
}
|
||||
@@ -1461,7 +1461,7 @@ JOIN::prepare(TABLE_LIST *tables_init, COND *conds_init, uint og_num,
|
||||
}
|
||||
}
|
||||
|
||||
if (having && having->with_sum_func())
|
||||
if (having && having->with_sum_func)
|
||||
having->split_sum_func2(thd, ref_ptrs, all_fields,
|
||||
&having, SPLIT_SUM_SKIP_REGISTERED);
|
||||
if (select_lex->inner_sum_func_list)
|
||||
@@ -2927,7 +2927,7 @@ int JOIN::optimize_stage2()
|
||||
elements may be lost during further having
|
||||
condition transformation in JOIN::exec.
|
||||
*/
|
||||
if (having && const_table_map && !having->with_sum_func())
|
||||
if (having && const_table_map && !having->with_sum_func)
|
||||
{
|
||||
having->update_used_tables();
|
||||
having= having->remove_eq_conds(thd, &select_lex->having_value, true);
|
||||
@@ -14290,7 +14290,7 @@ static void update_depend_map_for_order(JOIN *join, ORDER *order)
|
||||
order->used= 0;
|
||||
// Not item_sum(), RAND() and no reference to table outside of sub select
|
||||
if (!(order->depend_map & (OUTER_REF_TABLE_BIT | RAND_TABLE_BIT))
|
||||
&& !order->item[0]->with_sum_func() &&
|
||||
&& !order->item[0]->with_sum_func &&
|
||||
join->join_tab)
|
||||
{
|
||||
for (JOIN_TAB **tab=join->map2table;
|
||||
@@ -14397,7 +14397,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
|
||||
for (order=first_order; order ; order=order->next)
|
||||
{
|
||||
table_map order_tables=order->item[0]->used_tables();
|
||||
if (order->item[0]->with_sum_func() ||
|
||||
if (order->item[0]->with_sum_func ||
|
||||
order->item[0]->with_window_func ||
|
||||
/*
|
||||
If the outer table of an outer join is const (either by itself or
|
||||
@@ -14545,7 +14545,7 @@ ORDER *simple_remove_const(ORDER *order, COND *where)
|
||||
ORDER *first= NULL, *prev= NULL;
|
||||
for (; order; order= order->next)
|
||||
{
|
||||
DBUG_ASSERT(!order->item[0]->with_sum_func()); // should never happen
|
||||
DBUG_ASSERT(!order->item[0]->with_sum_func); // should never happen
|
||||
if (!const_expression_in_where(where, order->item[0]))
|
||||
{
|
||||
if (!first)
|
||||
@@ -18673,7 +18673,7 @@ bool Create_tmp_table::add_fields(THD *thd,
|
||||
}
|
||||
if (not_all_columns)
|
||||
{
|
||||
if (item->with_sum_func() && type != Item::SUM_FUNC_ITEM)
|
||||
if (item->with_sum_func && type != Item::SUM_FUNC_ITEM)
|
||||
{
|
||||
if (item->used_tables() & OUTER_REF_TABLE_BIT)
|
||||
item->update_used_tables();
|
||||
@@ -24784,7 +24784,7 @@ int setup_order(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!(*order->item)->with_sum_func())
|
||||
if (!(*order->item)->with_sum_func)
|
||||
continue;
|
||||
|
||||
/*
|
||||
@@ -24855,7 +24855,7 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
||||
all_fields, true, true, from_window_spec))
|
||||
return 1;
|
||||
(*ord->item)->marker= UNDEF_POS; /* Mark found */
|
||||
if ((*ord->item)->with_sum_func() && context_analysis_place == IN_GROUP_BY)
|
||||
if ((*ord->item)->with_sum_func && context_analysis_place == IN_GROUP_BY)
|
||||
{
|
||||
my_error(ER_WRONG_GROUP_FIELD, MYF(0), (*ord->item)->full_name());
|
||||
return 1;
|
||||
@@ -24868,7 +24868,7 @@ setup_group(THD *thd, Ref_ptr_array ref_pointer_array, TABLE_LIST *tables,
|
||||
my_error(ER_WINDOW_FUNCTION_IN_WINDOW_SPEC, MYF(0));
|
||||
return 1;
|
||||
}
|
||||
if (from_window_spec && (*ord->item)->with_sum_func() &&
|
||||
if (from_window_spec && (*ord->item)->with_sum_func &&
|
||||
(*ord->item)->type() != Item::SUM_FUNC_ITEM)
|
||||
(*ord->item)->split_sum_func(thd, ref_pointer_array,
|
||||
all_fields, SPLIT_SUM_SELECT);
|
||||
@@ -25018,7 +25018,7 @@ create_distinct_group(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
li.rewind();
|
||||
while ((item=li++))
|
||||
{
|
||||
if (!item->const_item() && !item->with_sum_func() && !item->marker)
|
||||
if (!item->const_item() && !item->with_sum_func && !item->marker)
|
||||
{
|
||||
/*
|
||||
Don't put duplicate columns from the SELECT list into the
|
||||
@@ -25115,11 +25115,9 @@ count_field_types(SELECT_LEX *select_lex, TMP_TABLE_PARAM *param,
|
||||
}
|
||||
else
|
||||
{
|
||||
With_sum_func_cache *cache= field->get_with_sum_func_cache();
|
||||
param->func_count++;
|
||||
// "field" can point to Item_std_field, so "cache" can be NULL here.
|
||||
if (reset_with_sum_func && cache)
|
||||
cache->reset_with_sum_func();
|
||||
if (reset_with_sum_func)
|
||||
field->with_sum_func=0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25541,7 +25539,7 @@ setup_copy_fields(THD *thd, TMP_TABLE_PARAM *param,
|
||||
real_pos->real_type() == Item::SUBSELECT_ITEM ||
|
||||
real_pos->type() == Item::CACHE_ITEM ||
|
||||
real_pos->type() == Item::COND_ITEM) &&
|
||||
!real_pos->with_sum_func())
|
||||
!real_pos->with_sum_func)
|
||||
{ // Save for send fields
|
||||
LEX_CSTRING real_name= pos->name;
|
||||
pos= real_pos;
|
||||
@@ -25750,7 +25748,7 @@ change_to_use_tmp_fields(THD *thd, Ref_ptr_array ref_pointer_array,
|
||||
for (uint i= 0; (item= it++); i++)
|
||||
{
|
||||
Field *field;
|
||||
if ((item->with_sum_func() && item->type() != Item::SUM_FUNC_ITEM) ||
|
||||
if ((item->with_sum_func && item->type() != Item::SUM_FUNC_ITEM) ||
|
||||
item->with_window_func)
|
||||
item_field= item;
|
||||
else if (item->type() == Item::FIELD_ITEM)
|
||||
@@ -26279,7 +26277,7 @@ bool JOIN::rollup_init()
|
||||
Marking the expression item as 'with_sum_func' will ensure this.
|
||||
*/
|
||||
if (changed)
|
||||
item->get_with_sum_func_cache()->set_with_sum_func();
|
||||
item->with_sum_func= 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user