summaryrefslogtreecommitdiff
path: root/sql/item_cmpfunc.cc
diff options
context:
space:
mode:
authorbell@laptop.sanja.is.com.ua <>2003-08-20 22:17:57 +0300
committerbell@laptop.sanja.is.com.ua <>2003-08-20 22:17:57 +0300
commitc514948a30c3db453c8bdef06f80ee6f9fe54588 (patch)
tree78307a7d09e186b6e58e668b4042398932133013 /sql/item_cmpfunc.cc
parentc06786fa0080e5d2e92b6a036eab3797165ff5b4 (diff)
parent1ab66ddad881fc77d67cbc003daa66aa95be385b (diff)
downloadmariadb-git-c514948a30c3db453c8bdef06f80ee6f9fe54588.tar.gz
merge
Diffstat (limited to 'sql/item_cmpfunc.cc')
-rw-r--r--sql/item_cmpfunc.cc67
1 files changed, 44 insertions, 23 deletions
diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc
index 6f493e2728c..01428dbf995 100644
--- a/sql/item_cmpfunc.cc
+++ b/sql/item_cmpfunc.cc
@@ -125,7 +125,7 @@ longlong Item_func_not_all::val_int()
static bool convert_constant_item(Field *field, Item **item)
{
- if ((*item)->const_item() && (*item)->type() != Item::INT_ITEM)
+ if ((*item)->const_item())
{
if (!(*item)->save_in_field(field, 1) && !((*item)->null_value))
{
@@ -401,7 +401,7 @@ bool Item_in_optimizer::fix_left(THD *thd,
cache->store(args[0]);
if (cache->cols() == 1)
{
- if (args[0]->used_tables())
+ if ((used_tables_cache= args[0]->used_tables()))
cache->set_used_tables(OUTER_REF_TABLE_BIT);
else
cache->set_used_tables(0);
@@ -416,7 +416,11 @@ bool Item_in_optimizer::fix_left(THD *thd,
else
((Item_cache *)cache->el(i))->set_used_tables(0);
}
+ used_tables_cache= args[0]->used_tables();
}
+ not_null_tables_cache= args[0]->not_null_tables();
+ with_sum_func= args[0]->with_sum_func;
+ const_item_cache= args[0]->const_item();
return 0;
}
@@ -430,9 +434,6 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
if (args[0]->maybe_null)
maybe_null=1;
- with_sum_func= args[0]->with_sum_func;
- used_tables_cache= args[0]->used_tables();
- const_item_cache= args[0]->const_item();
if (!args[1]->fixed && args[1]->fix_fields(thd, tables, args))
return 1;
Item_in_subselect * sub= (Item_in_subselect *)args[1];
@@ -445,6 +446,7 @@ bool Item_in_optimizer::fix_fields(THD *thd, struct st_table_list *tables,
maybe_null=1;
with_sum_func= with_sum_func || args[1]->with_sum_func;
used_tables_cache|= args[1]->used_tables();
+ not_null_tables_cache|= args[1]->not_null_tables();
const_item_cache&= args[1]->const_item();
return 0;
}
@@ -557,6 +559,7 @@ void Item_func_interval::fix_length_and_dec()
maybe_null= 0;
max_length= 2;
used_tables_cache|= row->used_tables();
+ not_null_tables_cache&= row->not_null_tables();
with_sum_func= with_sum_func || row->with_sum_func;
}
@@ -570,25 +573,27 @@ void Item_func_interval::fix_length_and_dec()
longlong Item_func_interval::val_int()
{
- double value=row->el(0)->val();
+ double value= row->el(0)->val();
+ uint i;
+
if (row->el(0)->null_value)
return -1; // -1 if null
if (intervals)
{ // Use binary search to find interval
uint start,end;
- start=1; end=row->cols()-2;
+ start= 1;
+ end= row->cols()-2;
while (start != end)
{
- uint mid=(start+end+1)/2;
+ uint mid= (start + end + 1) / 2;
if (intervals[mid] <= value)
- start=mid;
+ start= mid;
else
- end=mid-1;
+ end= mid - 1;
}
- return (value < intervals[start]) ? 0 : start+1;
+ return (value < intervals[start]) ? 0 : start + 1;
}
- uint i;
for (i=1 ; i < row->cols() ; i++)
{
if (row->el(i)->val() > value)
@@ -1476,7 +1481,6 @@ void Item_func_in::fix_length_and_dec()
}
maybe_null= args[0]->maybe_null;
max_length= 1;
- const_item_cache&=args[0]->const_item();
}
@@ -1557,13 +1561,19 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
#ifndef EMBEDDED_LIBRARY
char buff[sizeof(char*)]; // Max local vars in function
#endif
- used_tables_cache=0;
- const_item_cache=0;
+ not_null_tables_cache= used_tables_cache= 0;
+ const_item_cache= 0;
+ /*
+ and_table_cache is the value that Item_cond_or() returns for
+ not_null_tables()
+ */
+ and_tables_cache= ~(table_map) 0;
if (thd && check_stack_overrun(thd,buff))
return 0; // Fatal error flag is set!
while ((item=li++))
{
+ table_map tmp_table_map;
while (item->type() == Item::COND_ITEM &&
((Item_cond*) item)->functype() == functype())
{ // Identical function
@@ -1579,9 +1589,12 @@ Item_cond::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
if ((!item->fixed &&
item->fix_fields(thd, tables, li.ref())) || item->check_cols(1))
return 1; /* purecov: inspected */
- used_tables_cache|=item->used_tables();
- with_sum_func= with_sum_func || item->with_sum_func;
- const_item_cache&=item->const_item();
+ used_tables_cache|= item->used_tables();
+ tmp_table_map= item->not_null_tables();
+ not_null_tables_cache|= tmp_table_map;
+ and_tables_cache&= tmp_table_map;
+ const_item_cache&= item->const_item();
+ with_sum_func= with_sum_func || item->with_sum_func;
if (item->maybe_null)
maybe_null=1;
}
@@ -1632,17 +1645,19 @@ Item_cond::used_tables() const
return used_tables_cache;
}
+
void Item_cond::update_used_tables()
{
- used_tables_cache=0;
- const_item_cache=1;
List_iterator_fast<Item> li(list);
Item *item;
+
+ used_tables_cache=0;
+ const_item_cache=1;
while ((item=li++))
{
item->update_used_tables();
- used_tables_cache|=item->used_tables();
- const_item_cache&= item->const_item();
+ used_tables_cache|= item->used_tables();
+ const_item_cache&= item->const_item();
}
}
@@ -1746,12 +1761,16 @@ Item *and_expressions(Item *a, Item *b, Item **org_item)
{
Item_cond *res;
if ((res= new Item_cond_and(a, (Item*) b)))
+ {
res->used_tables_cache= a->used_tables() | b->used_tables();
+ res->not_null_tables_cache= a->not_null_tables() | b->not_null_tables();
+ }
return res;
}
if (((Item_cond_and*) a)->add((Item*) b))
return 0;
((Item_cond_and*) a)->used_tables_cache|= b->used_tables();
+ ((Item_cond_and*) a)->not_null_tables_cache|= b->not_null_tables();
return a;
}
@@ -1922,6 +1941,8 @@ Item_func_regex::fix_fields(THD *thd, TABLE_LIST *tables, Item **ref)
return 1;
used_tables_cache=args[0]->used_tables() | args[1]->used_tables();
+ not_null_tables_cache= (args[0]->not_null_tables() |
+ args[1]->not_null_tables());
const_item_cache=args[0]->const_item() && args[1]->const_item();
if (!regex_compiled && args[1]->const_item())
{
@@ -2163,7 +2184,7 @@ bool Item_func_like::turboBM_matches(const char* text, int text_len) const
int shift = pattern_len;
int j = 0;
int u = 0;
- CHARSET_INFO *cs=system_charset_info; // QQ Needs to be fixed
+ CHARSET_INFO *cs= cmp.cmp_collation.collation; // QQ Needs to be fixed
const int plm1= pattern_len - 1;
const int tlmpl= text_len - pattern_len;