diff options
Diffstat (limited to 'sql/item_func.h')
-rw-r--r-- | sql/item_func.h | 74 |
1 files changed, 54 insertions, 20 deletions
diff --git a/sql/item_func.h b/sql/item_func.h index c3cb3e3ba02..5477c27b13d 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1,7 +1,7 @@ #ifndef ITEM_FUNC_INCLUDED #define ITEM_FUNC_INCLUDED - -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. + Copyright (c) 2009-2011 Monty Program Ab This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -46,7 +46,7 @@ public: enum Functype { UNKNOWN_FUNC,EQ_FUNC,EQUAL_FUNC,NE_FUNC,LT_FUNC,LE_FUNC, GE_FUNC,GT_FUNC,FT_FUNC, LIKE_FUNC,ISNULL_FUNC,ISNOTNULL_FUNC, - COND_AND_FUNC, COND_OR_FUNC, COND_XOR_FUNC, + COND_AND_FUNC, COND_OR_FUNC, XOR_FUNC, BETWEEN, IN_FUNC, MULT_EQUAL_FUNC, INTERVAL_FUNC, ISNOTNULLTEST_FUNC, SP_EQUALS_FUNC, SP_DISJOINT_FUNC,SP_INTERSECTS_FUNC, @@ -67,6 +67,7 @@ public: allowed_arg_cols(1), arg_count(0) { with_sum_func= 0; + with_field= 0; } Item_func(Item *a): allowed_arg_cols(1), arg_count(1) @@ -74,6 +75,7 @@ public: args= tmp_arg; args[0]= a; with_sum_func= a->with_sum_func; + with_field= a->with_field; } Item_func(Item *a,Item *b): allowed_arg_cols(1), arg_count(2) @@ -81,6 +83,7 @@ public: args= tmp_arg; args[0]= a; args[1]= b; with_sum_func= a->with_sum_func || b->with_sum_func; + with_field= a->with_field || b->with_field; } Item_func(Item *a,Item *b,Item *c): allowed_arg_cols(1) @@ -91,6 +94,7 @@ public: arg_count= 3; args[0]= a; args[1]= b; args[2]= 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; } } Item_func(Item *a,Item *b,Item *c,Item *d): @@ -103,6 +107,8 @@ public: args[0]= a; args[1]= b; args[2]= c; args[3]= 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; } } Item_func(Item *a,Item *b,Item *c,Item *d,Item* e): @@ -114,6 +120,8 @@ public: args[0]= a; args[1]= b; args[2]= c; args[3]= d; args[4]= 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; } } Item_func(List<Item> &list); @@ -121,6 +129,7 @@ public: Item_func(THD *thd, Item_func *item); bool fix_fields(THD *, Item **ref); void fix_after_pullout(st_select_lex *new_parent, Item **ref); + void quick_fix_field(); table_map used_tables() const; table_map not_null_tables() const; void update_used_tables(); @@ -211,6 +220,7 @@ public: Item_transformer transformer, uchar *arg_t); void traverse_cond(Cond_traverser traverser, void * arg, traverse_order order); + bool eval_not_null_tables(uchar *opt_arg); // bool is_expensive_processor(uchar *arg); // virtual bool is_expensive() { return 0; } inline void raise_numeric_overflow(const char *type_name) @@ -315,6 +325,21 @@ public: } /* + By default only substitution for a field whose two different values + are never equal is allowed in the arguments of a function. + This is overruled for the direct arguments of comparison functions. + */ + bool subst_argument_checker(uchar **arg) + { + if (*arg) + { + *arg= (uchar *) Item::IDENTITY_SUBST; + return TRUE; + } + return FALSE; + } + + /* We assume the result of any function that has a TIMESTAMP argument to be timezone-dependent, since a TIMESTAMP value in both numeric and string contexts is interpreted according to the current timezone. @@ -371,6 +396,8 @@ class Item_func_numhybrid: public Item_func protected: Item_result hybrid_type; public: + Item_func_numhybrid() :Item_func(), hybrid_type(REAL_RESULT) + {} Item_func_numhybrid(Item *a) :Item_func(a), hybrid_type(REAL_RESULT) { collation.set_numeric(); } Item_func_numhybrid(Item *a,Item *b) @@ -530,7 +557,7 @@ class Item_decimal_typecast :public Item_func public: Item_decimal_typecast(Item *a, int len, int dec) :Item_func(a) { - decimals= dec; + decimals= (uint8) dec; collation.set_numeric(); fix_char_length(my_decimal_precision_to_length_no_truncation(len, dec, unsigned_flag)); @@ -541,12 +568,29 @@ public: my_decimal *val_decimal(my_decimal*); enum Item_result result_type () const { return DECIMAL_RESULT; } enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } - void fix_length_and_dec() {}; + void fix_length_and_dec() {} const char *func_name() const { return "decimal_typecast"; } virtual void print(String *str, enum_query_type query_type); }; +class Item_double_typecast :public Item_real_func +{ +public: + Item_double_typecast(Item *a, int len, int dec) :Item_real_func(a) + { + decimals= (uint8) dec; + max_length= (uint32) len; + } + double val_real(); + enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; } + void fix_length_and_dec() { maybe_null= 1; } + const char *func_name() const { return "double_typecast"; } + virtual void print(String *str, enum_query_type query_type); +}; + + + class Item_func_additive_op :public Item_num_op { public: @@ -914,25 +958,21 @@ class Item_func_min_max :public Item_func Item_result cmp_type; String tmp_value; int cmp_sign; - /* TRUE <=> arguments should be compared in the DATETIME context. */ - bool compare_as_dates; /* An item used for issuing warnings while string to DATETIME conversion. */ - Item *datetime_item; + Item *compare_as_dates; THD *thd; protected: enum_field_types cached_field_type; public: Item_func_min_max(List<Item> &list,int cmp_sign_arg) :Item_func(list), - cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(FALSE), - datetime_item(0) {} + cmp_type(INT_RESULT), cmp_sign(cmp_sign_arg), compare_as_dates(0) {} double val_real(); longlong val_int(); String *val_str(String *); my_decimal *val_decimal(my_decimal *); + bool get_date(MYSQL_TIME *res, uint fuzzy_date); void fix_length_and_dec(); enum Item_result result_type () const { return cmp_type; } - bool result_as_longlong() { return compare_as_dates; }; - uint cmp_datetimes(ulonglong *value); enum_field_types field_type() const { return cached_field_type; } }; @@ -1762,14 +1802,7 @@ public: void fix_length_and_dec() { decimals=0; max_length=1; maybe_null=1;} bool check_vcol_func_processor(uchar *int_arg) { -#if 0 - DBUG_ENTER("Item_func_is_free_lock::check_vcol_func_processor"); - DBUG_PRINT("info", - ("check_vcol_func_processor returns TRUE: unsupported function")); - DBUG_RETURN(TRUE); -#else return trace_unsupported_by_check_vcol_func_processor(func_name()); -#endif } }; @@ -1793,7 +1826,7 @@ enum Cast_target { ITEM_CAST_BINARY, ITEM_CAST_SIGNED_INT, ITEM_CAST_UNSIGNED_INT, ITEM_CAST_DATE, ITEM_CAST_TIME, ITEM_CAST_DATETIME, ITEM_CAST_CHAR, - ITEM_CAST_DECIMAL + ITEM_CAST_DECIMAL, ITEM_CAST_DOUBLE }; @@ -1962,6 +1995,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name, LEX_STRING component); extern bool check_reserved_words(LEX_STRING *name); extern enum_field_types agg_field_type(Item **items, uint nitems); +Item *find_date_time_item(Item **args, uint nargs, uint col); double my_double_round(double value, longlong dec, bool dec_unsigned, bool truncate); bool eval_const_cond(COND *cond); |