mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
MDEV-23001 Precreate static Item_bool() to simplify code
The following changes where done: - Create global Item: Item_false and Item_true - Replace all creation if 'FALSE' and 'TRUE' top level items used for WHERE/HAVING/ON clauses to use Item_false and Item_true. The benefit are: - Less and faster code - No test needed if we where able to create the new item. - Fixed possible errors if 'new' would have failed for the Item_bool's fixup! 470277728d2e27fe057cf33a437a9e40e1a04b61
This commit is contained in:
@ -2444,7 +2444,7 @@ int JOIN::optimize_stage2()
|
||||
if (!conds && outer_join)
|
||||
{
|
||||
/* Handle the case where we have an OUTER JOIN without a WHERE */
|
||||
conds= new (thd->mem_root) Item_bool(thd, true); // Always true
|
||||
conds= (Item*) &Item_true;
|
||||
}
|
||||
|
||||
if (impossible_where)
|
||||
@ -2615,7 +2615,7 @@ int JOIN::optimize_stage2()
|
||||
if (conds && const_table_map != found_const_table_map &&
|
||||
(select_options & SELECT_DESCRIBE))
|
||||
{
|
||||
conds=new (thd->mem_root) Item_bool(thd, false); // Always false
|
||||
conds= (Item*) &Item_false;
|
||||
}
|
||||
|
||||
/* Cache constant expressions in WHERE, HAVING, ON clauses. */
|
||||
@ -2933,7 +2933,7 @@ int JOIN::optimize_stage2()
|
||||
having= having->remove_eq_conds(thd, &select_lex->having_value, true);
|
||||
if (select_lex->having_value == Item::COND_FALSE)
|
||||
{
|
||||
having= new (thd->mem_root) Item_bool(thd, false);
|
||||
having= (Item*) &Item_false;
|
||||
zero_result_cause= "Impossible HAVING noticed after reading const tables";
|
||||
error= 0;
|
||||
select_lex->mark_const_derived(zero_result_cause);
|
||||
@ -5513,7 +5513,7 @@ make_join_statistics(JOIN *join, List<TABLE_LIST> &tables_list,
|
||||
if (join->cond_value == Item::COND_FALSE)
|
||||
{
|
||||
join->impossible_where= true;
|
||||
conds= new (join->thd->mem_root) Item_bool(join->thd, false);
|
||||
conds= (Item*) &Item_false;
|
||||
}
|
||||
|
||||
join->cond_equal= NULL;
|
||||
@ -11758,7 +11758,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
|
||||
below to check if we should use 'quick' instead.
|
||||
*/
|
||||
DBUG_PRINT("info", ("Item_int"));
|
||||
tmp= new (thd->mem_root) Item_bool(thd, true); // Always true
|
||||
tmp= (Item*) &Item_true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -15318,7 +15318,7 @@ COND *Item_cond_and::build_equal_items(THD *thd,
|
||||
if (!cond_args->elements &&
|
||||
!cond_equal.current_level.elements &&
|
||||
!eq_list.elements)
|
||||
return new (thd->mem_root) Item_bool(thd, true);
|
||||
return (Item*) &Item_true;
|
||||
|
||||
List_iterator_fast<Item_equal> it(cond_equal.current_level);
|
||||
while ((item_equal= it++))
|
||||
@ -15425,7 +15425,7 @@ COND *Item_func_eq::build_equal_items(THD *thd,
|
||||
Item_equal *item_equal;
|
||||
int n= cond_equal.current_level.elements + eq_list.elements;
|
||||
if (n == 0)
|
||||
return new (thd->mem_root) Item_bool(thd, true);
|
||||
return (Item*) &Item_true;
|
||||
else if (n == 1)
|
||||
{
|
||||
if ((item_equal= cond_equal.current_level.pop()))
|
||||
@ -15829,7 +15829,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels,
|
||||
List<Item> eq_list;
|
||||
Item_func_eq *eq_item= 0;
|
||||
if (((Item *) item_equal)->const_item() && !item_equal->val_int())
|
||||
return new (thd->mem_root) Item_bool(thd, false);
|
||||
return (Item*) &Item_false;
|
||||
Item *item_const= item_equal->get_const();
|
||||
Item_equal_fields_iterator it(*item_equal);
|
||||
Item *head;
|
||||
@ -15974,7 +15974,7 @@ Item *eliminate_item_equal(THD *thd, COND *cond, COND_EQUAL *upper_levels,
|
||||
switch (eq_list.elements)
|
||||
{
|
||||
case 0:
|
||||
res= cond ? cond : new (thd->mem_root) Item_bool(thd, true);
|
||||
res= cond ? cond : (Item*) &Item_true;
|
||||
break;
|
||||
case 1:
|
||||
if (!cond || cond->is_bool_literal())
|
||||
@ -17812,7 +17812,7 @@ Item_func_isnull::remove_eq_conds(THD *thd, Item::cond_result *cond_value,
|
||||
|
||||
*/
|
||||
|
||||
Item *item0= new(thd->mem_root) Item_bool(thd, false);
|
||||
Item *item0= (Item*) &Item_false;
|
||||
Item *eq_cond= new(thd->mem_root) Item_func_eq(thd, args[0], item0);
|
||||
if (!eq_cond)
|
||||
return this;
|
||||
@ -22855,6 +22855,8 @@ make_cond_for_table_from_pred(THD *thd, Item *root_cond, Item *cond,
|
||||
return new_cond;
|
||||
}
|
||||
}
|
||||
else if (cond->basic_const_item())
|
||||
return cond;
|
||||
|
||||
if (is_top_and_level && used_table == rand_table_bit &&
|
||||
(cond->used_tables() & ~OUTER_REF_TABLE_BIT) != rand_table_bit)
|
||||
@ -29432,17 +29434,13 @@ void JOIN::make_notnull_conds_for_range_scans()
|
||||
if (conds && build_notnull_conds_for_range_scans(this, conds,
|
||||
conds->used_tables()))
|
||||
{
|
||||
Item *false_cond= new (thd->mem_root) Item_int(thd, (longlong) 0, 1);
|
||||
if (false_cond)
|
||||
{
|
||||
/*
|
||||
Found a IS NULL conjunctive predicate for a null-rejected field
|
||||
in the WHERE clause
|
||||
*/
|
||||
conds= false_cond;
|
||||
cond_equal= 0;
|
||||
impossible_where= true;
|
||||
}
|
||||
/*
|
||||
Found a IS NULL conjunctive predicate for a null-rejected field
|
||||
in the WHERE clause
|
||||
*/
|
||||
conds= (Item*) &Item_false;
|
||||
cond_equal= 0;
|
||||
impossible_where= true;
|
||||
DBUG_VOID_RETURN;
|
||||
}
|
||||
|
||||
@ -29463,9 +29461,7 @@ void JOIN::make_notnull_conds_for_range_scans()
|
||||
Found a IS NULL conjunctive predicate for a null-rejected field
|
||||
of the inner table of an outer join with ON expression tbl->on_expr
|
||||
*/
|
||||
Item *false_cond= new (thd->mem_root) Item_int(thd, (longlong) 0, 1);
|
||||
if (false_cond)
|
||||
tbl->on_expr= false_cond;
|
||||
tbl->on_expr= (Item*) &Item_false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -29606,7 +29602,6 @@ void build_notnull_conds_for_inner_nest_of_outer_join(JOIN *join,
|
||||
{
|
||||
TABLE_LIST *tbl;
|
||||
table_map used_tables= 0;
|
||||
THD *thd= join->thd;
|
||||
List_iterator<TABLE_LIST> li(nest_tbl->nested_join->join_list);
|
||||
|
||||
while ((tbl= li++))
|
||||
@ -29617,9 +29612,7 @@ void build_notnull_conds_for_inner_nest_of_outer_join(JOIN *join,
|
||||
if (used_tables &&
|
||||
build_notnull_conds_for_range_scans(join, nest_tbl->on_expr, used_tables))
|
||||
{
|
||||
Item *false_cond= new (thd->mem_root) Item_int(thd, (longlong) 0, 1);
|
||||
if (false_cond)
|
||||
nest_tbl->on_expr= false_cond;
|
||||
nest_tbl->on_expr= (Item*) &Item_false;
|
||||
}
|
||||
|
||||
li.rewind();
|
||||
@ -29633,11 +29626,7 @@ void build_notnull_conds_for_inner_nest_of_outer_join(JOIN *join,
|
||||
}
|
||||
else if (build_notnull_conds_for_range_scans(join, tbl->on_expr,
|
||||
tbl->table->map))
|
||||
{
|
||||
Item *false_cond= new (thd->mem_root) Item_int(thd, (longlong) 0, 1);
|
||||
if (false_cond)
|
||||
tbl->on_expr= false_cond;
|
||||
}
|
||||
tbl->on_expr= (Item*) &Item_false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user