1
/* Copyright (C) 2000-2003 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
1
/* Copyright (C) 2000-2006 MySQL AB
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; either version 2 of the License, or
6
(at your option) any later version.
5
the Free Software Foundation; version 2 of the License.
8
7
This program is distributed in the hope that it will be useful,
9
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
28
27
static bool convert_constant_item(THD *thd, Field *field, Item **item);
30
static Item_result item_store_type(Item_result a,Item_result b)
29
static Item_result item_store_type(Item_result a, Item *item,
30
my_bool unsigned_flag)
32
Item_result b= item->result_type();
32
34
if (a == STRING_RESULT || b == STRING_RESULT)
33
35
return STRING_RESULT;
34
36
else if (a == REAL_RESULT || b == REAL_RESULT)
35
37
return REAL_RESULT;
36
else if (a == DECIMAL_RESULT || b == DECIMAL_RESULT)
38
else if (a == DECIMAL_RESULT || b == DECIMAL_RESULT ||
39
unsigned_flag != item->unsigned_flag)
37
40
return DECIMAL_RESULT;
58
63
for (; item < item_end; item++)
60
65
if ((*item)->type() != Item::NULL_ITEM)
61
*type= item_store_type(type[0], (*item)->result_type());
66
*type= item_store_type(*type, *item, unsigned_flag);
156
We put any NOT expression into parenthesis to avoid
157
possible problems with internal view representations where
158
any '!' is converted to NOT. It may cause a problem if
159
'!' is used in an expression together with other operators
160
whose precedence is lower than the precedence of '!' yet
161
higher than the precedence of NOT.
164
void Item_func_not::print(String *str)
167
Item_func::print(str);
151
172
special NOT for ALL subquery
420
441
case DECIMAL_RESULT:
421
443
case REAL_RESULT:
445
if ((*a)->decimals < NOT_FIXED_DEC && (*b)->decimals < NOT_FIXED_DEC)
447
precision= 5 * log_01[max((*a)->decimals, (*b)->decimals)];
448
if (func == &Arg_comparator::compare_real)
449
func= &Arg_comparator::compare_real_fixed;
450
else if (func == &Arg_comparator::compare_e_real)
451
func= &Arg_comparator::compare_e_real_fixed;
558
590
return test(my_decimal_cmp(val1, val2) == 0);
594
int Arg_comparator::compare_real_fixed()
597
Fix yet another manifestation of Bug#2338. 'Volatile' will instruct
598
gcc to flush double values out of 80-bit Intel FPU registers before
599
performing the comparison.
601
volatile double val1, val2;
602
val1= (*a)->val_real();
603
if (!(*a)->null_value)
605
val2= (*b)->val_real();
606
if (!(*b)->null_value)
608
owner->null_value= 0;
609
if (val1 == val2 || fabs(val1 - val2) < precision)
616
owner->null_value= 1;
621
int Arg_comparator::compare_e_real_fixed()
623
double val1= (*a)->val_real();
624
double val2= (*b)->val_real();
625
if ((*a)->null_value || (*b)->null_value)
626
return test((*a)->null_value && (*b)->null_value);
627
return test(val1 == val2 || fabs(val1 - val2) < precision);
561
631
int Arg_comparator::compare_int_signed()
563
633
longlong val1= (*a)->val_int();
814
884
We disable the predicates we've pushed down into subselect, run the
815
885
subselect and see if it has produced any rows.
817
((Item_in_subselect*)args[1])->enable_pushed_conds= FALSE;
818
longlong tmp= args[1]->val_bool_result();
819
result_for_null_param= null_value=
820
!((Item_in_subselect*)args[1])->engine->no_rows();
821
((Item_in_subselect*)args[1])->enable_pushed_conds= TRUE;
887
Item_in_subselect *item_subs=(Item_in_subselect*)args[1];
888
if (cache->cols() == 1)
890
item_subs->set_cond_guard_var(0, FALSE);
891
longlong tmp= args[1]->val_bool_result();
892
result_for_null_param= null_value= !item_subs->engine->no_rows();
893
item_subs->set_cond_guard_var(0, TRUE);
898
uint ncols= cache->cols();
900
Turn off the predicates that are based on column compares for
901
which the left part is currently NULL
903
for (i= 0; i < ncols; i++)
905
if (cache->el(i)->null_value)
906
item_subs->set_cond_guard_var(i, FALSE);
909
longlong tmp= args[1]->val_bool_result();
910
result_for_null_param= null_value= !item_subs->engine->no_rows();
912
/* Turn all predicates back on */
913
for (i= 0; i < ncols; i++)
914
item_subs->set_cond_guard_var(i, TRUE);
1146
1240
They are compared as integers, so for const item this time-consuming
1147
1241
conversion can be done only once, not for every single comparison
1149
if (args[0]->type() == FIELD_ITEM &&
1243
if (args[0]->real_item()->type() == FIELD_ITEM &&
1150
1244
thd->lex->sql_command != SQLCOM_CREATE_VIEW &&
1151
1245
thd->lex->sql_command != SQLCOM_SHOW_CREATE)
1153
Field *field=((Item_field*) args[0])->field;
1247
Field *field=((Item_field*) (args[0]->real_item()))->field;
1154
1248
if (field->can_be_compared_as_longlong())
3000
3094
DBUG_ASSERT(fixed == 1);
3001
3095
DBUG_ENTER("Item_is_not_null_test::val_int");
3002
if (!used_tables_cache)
3096
if (!used_tables_cache && !with_subselect)
3004
3098
owner->was_null|= (!cached_value);
3005
3099
DBUG_PRINT("info", ("cached :%ld", (long) cached_value));
3028
3122
args[0]->update_used_tables();
3029
if (!(used_tables_cache=args[0]->used_tables()))
3123
if (!(used_tables_cache=args[0]->used_tables()) && !with_subselect)
3031
3125
/* Remember if the value is always NULL or never NULL */
3032
3126
cached_value= (longlong) !args[0]->is_null();
3996
4090
void Item_equal::fix_length_and_dec()
3998
Item *item= const_item ? const_item : get_first();
4092
Item *item= get_first();
3999
4093
eval_item= cmp_item::get_comparator(item->result_type(),
4000
4094
item->collation.collation);
4001
if (item->result_type() == STRING_RESULT)
4002
eval_item->cmp_charset= cmp_collation.collation;
4005
4097
bool Item_equal::walk(Item_processor processor, byte *arg)