summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Widenius <monty@mariadb.org>2020-07-29 13:51:47 +0300
committerSergei Golubchik <serg@mariadb.org>2021-05-19 22:27:28 +0200
commit189d03dac52ecce13d3dc2b01faba25b7ca168a0 (patch)
tree4e76077525693b04eb2a395eb6c3ca5af80b4765
parentae39f4f6d61bdd57394afa8f88285f9e34640eb7 (diff)
downloadmariadb-git-189d03dac52ecce13d3dc2b01faba25b7ca168a0.tar.gz
Revert MDEV-14517 Cleanup for Item::with_subselect
Added back variable 'with_subquery' 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. This is the last set of my patches the decreases the size of Item. Some examples from gdb: sizeof(Item): 144 -> 120 sizeof(Item_func) 208 -> 184 sizeof(Item_sum_max) 368 -> 344
-rw-r--r--sql/filesort.cc4
-rw-r--r--sql/item.cc5
-rw-r--r--sql/item.h39
-rw-r--r--sql/item_cmpfunc.cc6
-rw-r--r--sql/item_cmpfunc.h2
-rw-r--r--sql/item_func.cc4
-rw-r--r--sql/item_func.h2
-rw-r--r--sql/item_jsonfunc.cc2
-rw-r--r--sql/item_row.cc2
-rw-r--r--sql/item_row.h4
-rw-r--r--sql/item_subselect.cc5
-rw-r--r--sql/item_subselect.h1
-rw-r--r--sql/item_sum.cc8
-rw-r--r--sql/item_windowfunc.cc6
-rw-r--r--sql/opt_subselect.cc2
-rw-r--r--sql/sql_select.cc8
-rw-r--r--storage/spider/spd_table.cc6
17 files changed, 38 insertions, 68 deletions
diff --git a/sql/filesort.cc b/sql/filesort.cc
index 8f74059cb0d..1db95732e0f 100644
--- a/sql/filesort.cc
+++ b/sql/filesort.cc
@@ -936,10 +936,10 @@ static ha_rows find_all_keys(THD *thd, Sort_param *param, SQL_SELECT *select,
MY_BITMAP *tmp_read_set= sort_form->read_set;
MY_BITMAP *tmp_write_set= sort_form->write_set;
- if (select->cond->with_subquery())
+ if (select->cond->has_subquery())
sort_form->column_bitmaps_set(save_read_set, save_write_set);
write_record= (select->skip_record(thd) > 0);
- if (select->cond->with_subquery())
+ if (select->cond->has_subquery())
sort_form->column_bitmaps_set(tmp_read_set, tmp_write_set);
}
else
diff --git a/sql/item.cc b/sql/item.cc
index be7efaaa3f0..e5b1ef6cf39 100644
--- a/sql/item.cc
+++ b/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= with_sum_func= 0;
+ is_in_with_cycle= with_sum_func= with_subquery= 0;
fixed= 1; // Simple Item's doesn't have to be fixed
is_autogenerated_name= 1;
null_value= 0;
@@ -487,6 +487,7 @@ Item::Item(THD *thd, Item *item):
is_autogenerated_name(item->is_autogenerated_name),
is_in_with_cycle(item->is_in_with_cycle),
with_sum_func(item->with_sum_func),
+ with_subquery(item->with_subquery),
marker(item->marker),
null_value(item->null_value),
is_expensive_cache(-1),
@@ -8568,10 +8569,10 @@ Item_cache_wrapper::Item_cache_wrapper(THD *thd, Item *item_arg):
Type_std_attributes::set(orig_item);
maybe_null= orig_item->maybe_null;
with_sum_func= orig_item->with_sum_func;
+ with_subquery= orig_item->with_subquery;
with_param= orig_item->with_param;
with_field= orig_item->with_field;
name= item_arg->name;
- m_with_subquery= orig_item->with_subquery();
if ((expr_value= orig_item->get_cache(thd)))
expr_value->setup(thd, orig_item);
diff --git a/sql/item.h b/sql/item.h
index 862061e2085..60ad20b0750 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -928,7 +928,8 @@ public:
is_autogenerated_name:1,
/* Indicates that this item is in CYCLE clause of WITH */
is_in_with_cycle:1,
- with_sum_func:1; /* True if item contains a sum func */
+ with_sum_func:1, /* True if item contains a sum func */
+ with_subquery:1; /* True if item containts a sub query */
int16 marker;
@@ -2406,12 +2407,8 @@ public:
*/
virtual bool is_outer_field() const { DBUG_ASSERT(is_fixed()); return FALSE; }
- /**
- Checks if this item or any of its descendents contains a subquery.
- This is a replacement of the former Item::has_subquery() and
- Item::with_subselect.
- */
- virtual bool with_subquery() const { DBUG_ASSERT(is_fixed()); return false; }
+ /** Checks if this item or any of its decendents contains a subquery */
+ bool has_subquery() const { DBUG_ASSERT(is_fixed()); return with_subquery; }
Item* set_expr_cache(THD *thd);
@@ -2540,21 +2537,6 @@ public:
#endif
-/*
- This class is a replacement for the former member Item::with_subselect.
- Determines if the descendant Item is a subselect or some of
- its arguments is or contains a subselect.
-*/
-class With_subquery_cache
-{
-protected:
- bool m_with_subquery;
-public:
- With_subquery_cache(): m_with_subquery(false) { }
- void join(const Item *item) { m_with_subquery|= item->with_subquery(); }
-};
-
-
/**
Compare two Items for List<Item>::add_unique()
*/
@@ -5184,8 +5166,7 @@ public:
*/
class Item_func_or_sum: public Item_result_field,
public Item_args,
- public Used_tables_and_const_cache,
- public With_subquery_cache
+ public Used_tables_and_const_cache
{
protected:
bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems,
@@ -5268,8 +5249,6 @@ public:
Used_tables_and_const_cache(item) { }
Item_func_or_sum(THD *thd, List<Item> &list):
Item_result_field(thd), Item_args(thd, list) { }
- bool with_subquery() const override
- { DBUG_ASSERT(fixed); return m_with_subquery; }
bool walk(Item_processor processor, bool walk_subquery, void *arg) override
{
if (walk_args(processor, walk_subquery, arg))
@@ -5541,13 +5520,10 @@ public:
DBUG_ASSERT(ref);
return (*ref)->is_outer_field();
}
-
Item* build_clone(THD *thd) override;
-
/**
Checks if the item tree that ref points to contains a subquery.
*/
- bool with_subquery() const override { return (*ref)->with_subquery(); }
Item *get_copy(THD *thd) override
{ return get_item_copy<Item_ref>(thd, this); }
bool excl_dep_on_table(table_map tab_map) override
@@ -5676,8 +5652,7 @@ class Expression_cache_tracker;
The objects of this class can store its values in an expression cache.
*/
-class Item_cache_wrapper :public Item_result_field,
- public With_subquery_cache
+class Item_cache_wrapper :public Item_result_field
{
private:
/* Pointer on the cached expression */
@@ -5704,8 +5679,6 @@ public:
Type type() const override { return EXPR_CACHE_ITEM; }
Type real_type() const override { return orig_item->type(); }
- bool with_subquery() const override
- { DBUG_ASSERT(fixed); return m_with_subquery; }
bool set_cache(THD *thd);
Expression_cache_tracker* init_tracker(MEM_ROOT *mem_root);
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index aea30ebf0c1..686cd245369 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -1389,7 +1389,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, Item **ref)
}
if (args[1]->maybe_null)
maybe_null=1;
- m_with_subquery= true;
+ with_subquery= 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;
@@ -4942,7 +4942,7 @@ Item_cond::fix_fields(THD *thd, Item **ref)
with_sum_func|= item->with_sum_func;
with_param|= item->with_param;
with_field|= item->with_field;
- m_with_subquery|= item->with_subquery();
+ with_subquery|= item->with_subquery;
with_window_func|= item->with_window_func;
maybe_null|= item->maybe_null;
}
@@ -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())
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 2bc3475c7e0..bddbe970207 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -366,7 +366,7 @@ public:
Item_in_optimizer(THD *thd, Item *a, Item *b):
Item_bool_func(thd, a, b), cache(0), expr_cache(0),
save_cache(0), result_for_null_param(UNKNOWN)
- { m_with_subquery= true; }
+ { with_subquery= true; }
bool fix_fields(THD *, Item **) override;
bool fix_left(THD *thd);
table_map not_null_tables() const override { return 0; }
diff --git a/sql/item_func.cc b/sql/item_func.cc
index cc711cc98b1..a8caf7f916c 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -358,9 +358,9 @@ Item_func::fix_fields(THD *thd, Item **ref)
with_param |= item->with_param;
with_window_func |= item->with_window_func;
with_field |= item->with_field;
+ with_subquery|= item->with_subquery;
used_tables_and_const_cache_join(item);
not_null_tables_cache|= item->not_null_tables();
- m_with_subquery|= item->with_subquery();
}
}
if (check_arguments())
@@ -3521,7 +3521,7 @@ udf_handler::fix_fields(THD *thd, Item_func_or_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->with_subquery |= item->with_subquery;
func->used_tables_and_const_cache_join(item);
f_args.arg_type[i]=item->result_type();
}
diff --git a/sql/item_func.h b/sql/item_func.h
index 5c611dbfd56..08eda7203ab 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -346,7 +346,7 @@ public:
bool excl_dep_on_grouping_fields(st_select_lex *sel)
{
- if (has_rand_bit() || with_subquery())
+ if (has_rand_bit() || has_subquery())
return false;
return Item_args::excl_dep_on_grouping_fields(sel);
}
diff --git a/sql/item_jsonfunc.cc b/sql/item_jsonfunc.cc
index e7f2b3d8eee..4d7cd4bba50 100644
--- a/sql/item_jsonfunc.cc
+++ b/sql/item_jsonfunc.cc
@@ -3799,7 +3799,7 @@ Item_func_json_objectagg::fix_fields(THD *thd, Item **ref)
{
if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i]))
return TRUE;
- m_with_subquery|= args[i]->with_subquery();
+ with_subquery|= args[i]->with_subquery;
with_param|= args[i]->with_param;
with_window_func|= args[i]->with_window_func;
}
diff --git a/sql/item_row.cc b/sql/item_row.cc
index cf15b7f0b8c..4532b7575f2 100644
--- a/sql/item_row.cc
+++ b/sql/item_row.cc
@@ -64,7 +64,7 @@ bool Item_row::fix_fields(THD *thd, Item **ref)
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();
+ with_subquery|= item->with_subquery;
with_param|= item->with_param;
}
fixed= 1;
diff --git a/sql/item_row.h b/sql/item_row.h
index 0f2d62424e4..9b8620836b2 100644
--- a/sql/item_row.h
+++ b/sql/item_row.h
@@ -35,8 +35,7 @@
*/
class Item_row: public Item_fixed_hybrid,
private Item_args,
- private Used_tables_and_const_cache,
- private With_subquery_cache
+ private Used_tables_and_const_cache
{
table_map not_null_tables_cache;
/**
@@ -55,7 +54,6 @@ public:
not_null_tables_cache(0), with_null(0)
{ }
- bool with_subquery() const { DBUG_ASSERT(fixed); return m_with_subquery; }
enum Type type() const { return ROW_ITEM; };
const Type_handler *type_handler() const { return &type_handler_row; }
Field *create_tmp_field_ex(MEM_ROOT *root, TABLE *table, Tmp_field_src *src,
diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc
index 3e232a18abc..467138e364d 100644
--- a/sql/item_subselect.cc
+++ b/sql/item_subselect.cc
@@ -67,6 +67,7 @@ Item_subselect::Item_subselect(THD *thd_arg):
#ifndef DBUG_OFF
exec_counter= 0;
#endif
+ with_subquery= 1;
reset();
/*
Item value is NULL if select_result_interceptor didn't change this value
@@ -2944,7 +2945,7 @@ static bool check_equality_for_exist2in(Item_func *func,
if (args[0]->real_type() == Item::FIELD_ITEM &&
args[0]->all_used_tables() != OUTER_REF_TABLE_BIT &&
args[1]->all_used_tables() == OUTER_REF_TABLE_BIT &&
- (allow_subselect || !args[1]->with_subquery()))
+ (allow_subselect || !args[1]->with_subquery))
{
/* It is Item_field or Item_direct_view_ref) */
DBUG_ASSERT(args[0]->type() == Item::FIELD_ITEM ||
@@ -2956,7 +2957,7 @@ static bool check_equality_for_exist2in(Item_func *func,
else if (args[1]->real_type() == Item::FIELD_ITEM &&
args[1]->all_used_tables() != OUTER_REF_TABLE_BIT &&
args[0]->all_used_tables() == OUTER_REF_TABLE_BIT &&
- (allow_subselect || !args[0]->with_subquery()))
+ (allow_subselect || !args[0]->with_subquery))
{
/* It is Item_field or Item_direct_view_ref) */
DBUG_ASSERT(args[1]->type() == Item::FIELD_ITEM ||
diff --git a/sql/item_subselect.h b/sql/item_subselect.h
index 21b5ffdf3d7..43ee8fd9497 100644
--- a/sql/item_subselect.h
+++ b/sql/item_subselect.h
@@ -191,7 +191,6 @@ public:
return null_value;
}
bool fix_fields(THD *thd, Item **ref) override;
- bool with_subquery() const override { DBUG_ASSERT(fixed); return true; }
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;
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index a5a6c164141..8875fb9bc0a 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1124,7 +1124,7 @@ Item_sum_num::fix_fields(THD *thd, Item **ref)
if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i]))
return TRUE;
set_if_bigger(decimals, args[i]->decimals);
- m_with_subquery|= args[i]->with_subquery();
+ with_subquery|= args[i]->with_subquery;
with_param|= args[i]->with_param;
with_window_func|= args[i]->with_window_func;
}
@@ -1155,7 +1155,7 @@ Item_sum_min_max::fix_fields(THD *thd, Item **ref)
if (args[0]->fix_fields_if_needed_for_scalar(thd, &args[0]))
DBUG_RETURN(TRUE);
- m_with_subquery= args[0]->with_subquery();
+ with_subquery= args[0]->with_subquery;
with_param= args[0]->with_param;
with_window_func|= args[0]->with_window_func;
@@ -1357,7 +1357,7 @@ Item_sum_sp::fix_fields(THD *thd, Item **ref)
if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i]))
return TRUE;
set_if_bigger(decimals, args[i]->decimals);
- m_with_subquery|= args[i]->with_subquery();
+ with_subquery|= args[i]->with_subquery;
with_window_func|= args[i]->with_window_func;
}
result_field= NULL;
@@ -4229,7 +4229,7 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref)
{
if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i]))
return TRUE;
- m_with_subquery|= args[i]->with_subquery();
+ with_subquery|= args[i]->with_subquery;
with_param|= args[i]->with_param;
with_window_func|= args[i]->with_window_func;
}
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc
index d59ad322682..8b9157f8377 100644
--- a/sql/item_windowfunc.cc
+++ b/sql/item_windowfunc.cc
@@ -345,13 +345,11 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref)
if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i]))
return TRUE;
with_window_func|= args[i]->with_window_func;
+ with_subquery|= args[i]->with_subquery;
}
- for (uint i= 0; i < arg_count && !m_with_subquery; i++)
- m_with_subquery|= args[i]->with_subquery();
-
if (fix_length_and_dec())
- return true;
+ return TRUE;
setup_hybrid(thd, args[0]);
result_field=0;
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index e09bc179e75..ebc42b26490 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -1776,7 +1776,7 @@ static bool convert_subq_to_sj(JOIN *parent_join, Item_in_subselect *subq_pred)
// The subqueries were replaced for Item_int(1) earlier
subq_pred->reset_strategy(SUBS_SEMI_JOIN); // for subsequent executions
- /*TODO: also reset the 'm_with_subquery' there. */
+ /*TODO: also reset the 'with_subquery' there. */
/* n. Adjust the parent_join->table_count counter */
uint table_no= parent_join->table_count;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 1b411af3d03..a47ef297a7f 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -2015,10 +2015,10 @@ JOIN::optimize_inner()
if (optimize_constant_subqueries())
DBUG_RETURN(1);
- if (conds && conds->with_subquery())
+ if (conds && conds->has_subquery())
(void) conds->walk(&Item::cleanup_is_expensive_cache_processor,
0, (void *) 0);
- if (having && having->with_subquery())
+ if (having && having->has_subquery())
(void) having->walk(&Item::cleanup_is_expensive_cache_processor,
0, (void *) 0);
@@ -13833,7 +13833,7 @@ bool JOIN_TAB::pfs_batch_update(JOIN *join)
return join->join_tab + join->table_count - 1 == this && // 1
type != JT_EQ_REF && type != JT_CONST && type != JT_SYSTEM && // 2
- (!select_cond || !select_cond->with_subquery()); // 3
+ (!select_cond || !select_cond->has_subquery()); // 3
}
@@ -14414,7 +14414,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond,
*simple_order=0; // Must do a temp table to sort
else if (!(order_tables & not_const_tables))
{
- if (order->item[0]->with_subquery())
+ if (order->item[0]->has_subquery())
{
/*
Delay the evaluation of constant ORDER and/or GROUP expressions that
diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc
index 67166d522aa..c93404f476a 100644
--- a/storage/spider/spd_table.cc
+++ b/storage/spider/spd_table.cc
@@ -9592,10 +9592,10 @@ int spider_set_direct_limit_offset(
DBUG_RETURN(FALSE);
// ignore condition like 1=1
-#ifdef SPIDER_has_Item_with_subquery
- if (select_lex->where && select_lex->where->with_subquery())
+#ifdef SPIDER_has_Item_has_subquery
+ if (select_lex->where && select_lex->where->has_subquery())
#else
- if (select_lex->where && select_lex->where->with_subselect)
+ if (select_lex->where && select_lex->where->with_subquery)
#endif
DBUG_RETURN(FALSE);