My Project
|
00001 #ifndef ITEM_INCLUDED 00002 #define ITEM_INCLUDED 00003 00004 /* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; version 2 of the License. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00018 00019 00020 #include "sql_priv.h" /* STRING_BUFFER_USUAL_SIZE */ 00021 #include "unireg.h" 00022 #include "sql_const.h" /* RAND_TABLE_BIT, MAX_FIELD_NAME */ 00023 #include "unireg.h" // REQUIRED: for other includes 00024 #include "thr_malloc.h" /* sql_calloc */ 00025 #include "field.h" /* Derivation */ 00026 #include "sql_array.h" 00027 00028 class Protocol; 00029 struct TABLE_LIST; 00030 void item_init(void); /* Init item functions */ 00031 class Item_field; 00032 class user_var_entry; 00033 00034 typedef Bounds_checked_array<Item*> Ref_ptr_array; 00035 00036 static inline uint32 00037 char_to_byte_length_safe(uint32 char_length_arg, uint32 mbmaxlen_arg) 00038 { 00039 ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg; 00040 return (tmp > UINT_MAX32) ? (uint32) UINT_MAX32 : (uint32) tmp; 00041 } 00042 00043 00044 /* 00045 "Declared Type Collation" 00046 A combination of collation and its derivation. 00047 00048 Flags for collation aggregation modes: 00049 MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset 00050 MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value 00051 (i.e. constant). 00052 MY_COLL_ALLOW_CONV - allow any kind of conversion 00053 (combination of the above two) 00054 MY_COLL_ALLOW_NUMERIC_CONV - if all items were numbers, convert to 00055 @@character_set_connection 00056 MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE 00057 (e.g. when aggregating for comparison) 00058 MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV 00059 and MY_COLL_DISALLOW_NONE 00060 */ 00061 00062 #define MY_COLL_ALLOW_SUPERSET_CONV 1 00063 #define MY_COLL_ALLOW_COERCIBLE_CONV 2 00064 #define MY_COLL_DISALLOW_NONE 4 00065 #define MY_COLL_ALLOW_NUMERIC_CONV 8 00066 00067 #define MY_COLL_ALLOW_CONV (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV) 00068 #define MY_COLL_CMP_CONV (MY_COLL_ALLOW_CONV | MY_COLL_DISALLOW_NONE) 00069 00070 class DTCollation { 00071 public: 00072 const CHARSET_INFO *collation; 00073 enum Derivation derivation; 00074 uint repertoire; 00075 00076 void set_repertoire_from_charset(const CHARSET_INFO *cs) 00077 { 00078 repertoire= cs->state & MY_CS_PUREASCII ? 00079 MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30; 00080 } 00081 DTCollation() 00082 { 00083 collation= &my_charset_bin; 00084 derivation= DERIVATION_NONE; 00085 repertoire= MY_REPERTOIRE_UNICODE30; 00086 } 00087 DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg) 00088 { 00089 collation= collation_arg; 00090 derivation= derivation_arg; 00091 set_repertoire_from_charset(collation_arg); 00092 } 00093 void set(DTCollation &dt) 00094 { 00095 collation= dt.collation; 00096 derivation= dt.derivation; 00097 repertoire= dt.repertoire; 00098 } 00099 void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg) 00100 { 00101 collation= collation_arg; 00102 derivation= derivation_arg; 00103 set_repertoire_from_charset(collation_arg); 00104 } 00105 void set(const CHARSET_INFO *collation_arg, 00106 Derivation derivation_arg, 00107 uint repertoire_arg) 00108 { 00109 collation= collation_arg; 00110 derivation= derivation_arg; 00111 repertoire= repertoire_arg; 00112 } 00113 void set_numeric() 00114 { 00115 collation= &my_charset_numeric; 00116 derivation= DERIVATION_NUMERIC; 00117 repertoire= MY_REPERTOIRE_NUMERIC; 00118 } 00119 void set(const CHARSET_INFO *collation_arg) 00120 { 00121 collation= collation_arg; 00122 set_repertoire_from_charset(collation_arg); 00123 } 00124 void set(Derivation derivation_arg) 00125 { derivation= derivation_arg; } 00126 void set_repertoire(uint repertoire_arg) 00127 { repertoire= repertoire_arg; } 00128 bool aggregate(DTCollation &dt, uint flags= 0); 00129 bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0) 00130 { set(dt1); return aggregate(dt2, flags); } 00131 const char *derivation_name() const 00132 { 00133 switch(derivation) 00134 { 00135 case DERIVATION_NUMERIC: return "NUMERIC"; 00136 case DERIVATION_IGNORABLE: return "IGNORABLE"; 00137 case DERIVATION_COERCIBLE: return "COERCIBLE"; 00138 case DERIVATION_IMPLICIT: return "IMPLICIT"; 00139 case DERIVATION_SYSCONST: return "SYSCONST"; 00140 case DERIVATION_EXPLICIT: return "EXPLICIT"; 00141 case DERIVATION_NONE: return "NONE"; 00142 default: return "UNKNOWN"; 00143 } 00144 } 00145 }; 00146 00147 /*************************************************************************/ 00148 00158 class Name_string: public Simple_cstring 00159 { 00160 private: 00161 void set_or_copy(const char *str, size_t length, bool is_null_terminated) 00162 { 00163 if (is_null_terminated) 00164 set(str, length); 00165 else 00166 copy(str, length); 00167 } 00168 public: 00169 Name_string(): Simple_cstring() {} 00170 /* 00171 Please do NOT add constructor Name_string(const char *str) ! 00172 It will involve hidden strlen() call, which can affect 00173 performance negatively. Use Name_string(str, len) instead. 00174 */ 00175 Name_string(const char *str, size_t length): 00176 Simple_cstring(str, length) {} 00177 Name_string(const LEX_STRING str): Simple_cstring(str) {} 00178 Name_string(const char *str, size_t length, bool is_null_terminated): 00179 Simple_cstring() 00180 { 00181 set_or_copy(str, length, is_null_terminated); 00182 } 00183 Name_string(const LEX_STRING str, bool is_null_terminated): 00184 Simple_cstring() 00185 { 00186 set_or_copy(str.str, str.length, is_null_terminated); 00187 } 00191 void copy(const char *str, size_t length, const CHARSET_INFO *cs); 00195 void copy(const char *str, size_t length) 00196 { 00197 copy(str, length, system_charset_info); 00198 } 00199 void copy(const char *str) 00200 { 00201 copy(str, (str ? strlen(str) : 0), system_charset_info); 00202 } 00203 void copy(const LEX_STRING lex) 00204 { 00205 copy(lex.str, lex.length); 00206 } 00207 void copy(const LEX_STRING *lex) 00208 { 00209 copy(lex->str, lex->length); 00210 } 00211 void copy(const Name_string str) 00212 { 00213 copy(str.ptr(), str.length()); 00214 } 00218 bool eq(const char *str) const 00219 { 00220 DBUG_ASSERT(str && ptr()); 00221 return my_strcasecmp(system_charset_info, ptr(), str) == 0; 00222 } 00223 bool eq_safe(const char *str) const 00224 { 00225 return is_set() && str && eq(str); 00226 } 00230 bool eq(const Name_string name) const 00231 { 00232 return eq(name.ptr()); 00233 } 00234 bool eq_safe(const Name_string name) const 00235 { 00236 return is_set() && name.is_set() && eq(name); 00237 } 00238 }; 00239 00240 00241 #define NAME_STRING(x) Name_string(C_STRING_WITH_LEN(x)) 00242 00243 00244 extern const Name_string null_name_string; 00245 00246 00251 class Item_name_string: public Name_string 00252 { 00253 private: 00254 bool m_is_autogenerated; /* indicates if name of this Item 00255 was autogenerated or set by user */ 00256 public: 00257 Item_name_string(): Name_string(), m_is_autogenerated(true) 00258 { } 00259 Item_name_string(const Name_string name) 00260 :Name_string(name), m_is_autogenerated(true) 00261 { } 00265 void set_autogenerated(bool is_autogenerated) 00266 { 00267 m_is_autogenerated= is_autogenerated; 00268 } 00272 bool is_autogenerated() const { return m_is_autogenerated; } 00273 using Name_string::copy; 00278 void copy(const char *str_arg, size_t length_arg, const CHARSET_INFO *cs_arg, 00279 bool is_autogenerated_arg); 00280 }; 00281 00282 00283 00284 /*************************************************************************/ 00285 /* 00286 A framework to easily handle different return types for hybrid items 00287 (hybrid item is an item whose operand can be of any type, e.g. integer, 00288 real, decimal). 00289 */ 00290 00291 struct Hybrid_type_traits; 00292 00293 struct Hybrid_type 00294 { 00295 longlong integer; 00296 00297 double real; 00298 /* 00299 Use two decimal buffers interchangeably to speed up += operation 00300 which has no native support in decimal library. 00301 Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg. 00302 The third decimal is used as a handy temporary storage. 00303 */ 00304 my_decimal dec_buf[3]; 00305 int used_dec_buf_no; 00306 00307 /* 00308 Traits moved to a separate class to 00309 a) be able to easily change object traits in runtime 00310 b) they work as a differentiator for the union above 00311 */ 00312 const Hybrid_type_traits *traits; 00313 00314 Hybrid_type() {} 00315 /* XXX: add traits->copy() when needed */ 00316 Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {} 00317 }; 00318 00319 00320 /* Hybryd_type_traits interface + default implementation for REAL_RESULT */ 00321 00322 struct Hybrid_type_traits 00323 { 00324 virtual Item_result type() const { return REAL_RESULT; } 00325 00326 virtual void 00327 fix_length_and_dec(Item *item, Item *arg) const; 00328 00329 /* Hybrid_type operations. */ 00330 virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; } 00331 virtual void add(Hybrid_type *val, Field *f) const 00332 { val->real+= f->val_real(); } 00333 virtual void div(Hybrid_type *val, ulonglong u) const 00334 { val->real/= ulonglong2double(u); } 00335 00336 virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const 00337 { return (longlong) rint(val->real); } 00338 virtual double val_real(Hybrid_type *val) const { return val->real; } 00339 virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const; 00340 virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const; 00341 static const Hybrid_type_traits *instance(); 00342 Hybrid_type_traits() {} 00343 virtual ~Hybrid_type_traits() {} 00344 }; 00345 00346 00347 struct Hybrid_type_traits_decimal: public Hybrid_type_traits 00348 { 00349 virtual Item_result type() const { return DECIMAL_RESULT; } 00350 00351 virtual void 00352 fix_length_and_dec(Item *arg, Item *item) const; 00353 00354 /* Hybrid_type operations. */ 00355 virtual void set_zero(Hybrid_type *val) const; 00356 virtual void add(Hybrid_type *val, Field *f) const; 00357 virtual void div(Hybrid_type *val, ulonglong u) const; 00358 00359 virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const; 00360 virtual double val_real(Hybrid_type *val) const; 00361 virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const 00362 { return &val->dec_buf[val->used_dec_buf_no]; } 00363 virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const; 00364 static const Hybrid_type_traits_decimal *instance(); 00365 Hybrid_type_traits_decimal() {}; 00366 }; 00367 00368 00369 struct Hybrid_type_traits_integer: public Hybrid_type_traits 00370 { 00371 virtual Item_result type() const { return INT_RESULT; } 00372 00373 virtual void 00374 fix_length_and_dec(Item *arg, Item *item) const; 00375 00376 /* Hybrid_type operations. */ 00377 virtual void set_zero(Hybrid_type *val) const 00378 { val->integer= 0; } 00379 virtual void add(Hybrid_type *val, Field *f) const 00380 { val->integer+= f->val_int(); } 00381 virtual void div(Hybrid_type *val, ulonglong u) const 00382 { val->integer/= (longlong) u; } 00383 00384 virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const 00385 { return val->integer; } 00386 virtual double val_real(Hybrid_type *val) const 00387 { return (double) val->integer; } 00388 virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const 00389 { 00390 int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]); 00391 return &val->dec_buf[2]; 00392 } 00393 virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const 00394 { buf->set(val->integer, &my_charset_bin); return buf;} 00395 static const Hybrid_type_traits_integer *instance(); 00396 Hybrid_type_traits_integer() {}; 00397 }; 00398 00399 00400 void dummy_error_processor(THD *thd, void *data); 00401 00402 void view_error_processor(THD *thd, void *data); 00403 00404 /* 00405 Instances of Name_resolution_context store the information necesary for 00406 name resolution of Items and other context analysis of a query made in 00407 fix_fields(). 00408 00409 This structure is a part of SELECT_LEX, a pointer to this structure is 00410 assigned when an item is created (which happens mostly during parsing 00411 (sql_yacc.yy)), but the structure itself will be initialized after parsing 00412 is complete 00413 00414 TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to 00415 separate SELECT_LEX which allow to remove tricks of changing this 00416 structure before and after INSERT/CREATE and its SELECT to make correct 00417 field name resolution. 00418 */ 00419 struct Name_resolution_context: Sql_alloc 00420 { 00421 /* 00422 The name resolution context to search in when an Item cannot be 00423 resolved in this context (the context of an outer select) 00424 */ 00425 Name_resolution_context *outer_context; 00426 00427 /* 00428 List of tables used to resolve the items of this context. Usually these 00429 are tables from the FROM clause of SELECT statement. The exceptions are 00430 INSERT ... SELECT and CREATE ... SELECT statements, where SELECT 00431 subquery is not moved to a separate SELECT_LEX. For these types of 00432 statements we have to change this member dynamically to ensure correct 00433 name resolution of different parts of the statement. 00434 */ 00435 TABLE_LIST *table_list; 00436 /* 00437 In most cases the two table references below replace 'table_list' above 00438 for the purpose of name resolution. The first and last name resolution 00439 table references allow us to search only in a sub-tree of the nested 00440 join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING 00441 and JOIN ... ON. 00442 */ 00443 TABLE_LIST *first_name_resolution_table; 00444 /* 00445 Last table to search in the list of leaf table references that begins 00446 with first_name_resolution_table. 00447 */ 00448 TABLE_LIST *last_name_resolution_table; 00449 00450 /* 00451 SELECT_LEX item belong to, in case of merged VIEW it can differ from 00452 SELECT_LEX where item was created, so we can't use table_list/field_list 00453 from there 00454 */ 00455 st_select_lex *select_lex; 00456 00457 /* 00458 Processor of errors caused during Item name resolving, now used only to 00459 hide underlying tables in errors about views (i.e. it substitute some 00460 errors for views) 00461 */ 00462 void (*error_processor)(THD *, void *); 00463 void *error_processor_data; 00464 00473 bool resolve_in_select_list; 00474 00475 /* 00476 Security context of this name resolution context. It's used for views 00477 and is non-zero only if the view is defined with SQL SECURITY DEFINER. 00478 */ 00479 Security_context *security_ctx; 00480 00481 Name_resolution_context() 00482 :outer_context(0), table_list(0), select_lex(0), 00483 error_processor_data(0), 00484 security_ctx(0) 00485 {} 00486 00487 void init() 00488 { 00489 resolve_in_select_list= FALSE; 00490 error_processor= &dummy_error_processor; 00491 first_name_resolution_table= NULL; 00492 last_name_resolution_table= NULL; 00493 } 00494 00495 void resolve_in_table_list_only(TABLE_LIST *tables) 00496 { 00497 table_list= first_name_resolution_table= tables; 00498 resolve_in_select_list= FALSE; 00499 } 00500 00501 void process_error(THD *thd) 00502 { 00503 (*error_processor)(thd, error_processor_data); 00504 } 00505 }; 00506 00507 00508 /* 00509 Store and restore the current state of a name resolution context. 00510 */ 00511 00512 class Name_resolution_context_state 00513 { 00514 private: 00515 TABLE_LIST *save_table_list; 00516 TABLE_LIST *save_first_name_resolution_table; 00517 TABLE_LIST *save_next_name_resolution_table; 00518 bool save_resolve_in_select_list; 00519 TABLE_LIST *save_next_local; 00520 00521 public: 00522 Name_resolution_context_state() {} /* Remove gcc warning */ 00523 00524 public: 00525 /* Save the state of a name resolution context. */ 00526 void save_state(Name_resolution_context *context, TABLE_LIST *table_list) 00527 { 00528 save_table_list= context->table_list; 00529 save_first_name_resolution_table= context->first_name_resolution_table; 00530 save_resolve_in_select_list= context->resolve_in_select_list; 00531 save_next_local= table_list->next_local; 00532 save_next_name_resolution_table= table_list->next_name_resolution_table; 00533 } 00534 00535 /* Restore a name resolution context from saved state. */ 00536 void restore_state(Name_resolution_context *context, TABLE_LIST *table_list) 00537 { 00538 table_list->next_local= save_next_local; 00539 table_list->next_name_resolution_table= save_next_name_resolution_table; 00540 context->table_list= save_table_list; 00541 context->first_name_resolution_table= save_first_name_resolution_table; 00542 context->resolve_in_select_list= save_resolve_in_select_list; 00543 } 00544 00545 TABLE_LIST *get_first_name_resolution_table() 00546 { 00547 return save_first_name_resolution_table; 00548 } 00549 }; 00550 00551 00552 /* 00553 This enum is used to report information about monotonicity of function 00554 represented by Item* tree. 00555 Monotonicity is defined only for Item* trees that represent table 00556 partitioning expressions (i.e. have no subselects/user vars/PS parameters 00557 etc etc). An Item* tree is assumed to have the same monotonicity properties 00558 as its correspoinding function F: 00559 00560 [signed] longlong F(field1, field2, ...) { 00561 put values of field_i into table record buffer; 00562 return item->val_int(); 00563 } 00564 00565 NOTE 00566 At the moment function monotonicity is not well defined (and so may be 00567 incorrect) for Item trees with parameters/return types that are different 00568 from INT_RESULT, may be NULL, or are unsigned. 00569 It will be possible to address this issue once the related partitioning bugs 00570 (BUG#16002, BUG#15447, BUG#13436) are fixed. 00571 00572 The NOT_NULL enums are used in TO_DAYS, since TO_DAYS('2001-00-00') returns 00573 NULL which puts those rows into the NULL partition, but 00574 '2000-12-31' < '2001-00-00' < '2001-01-01'. So special handling is needed 00575 for this (see Bug#20577). 00576 */ 00577 00578 typedef enum monotonicity_info 00579 { 00580 NON_MONOTONIC, /* none of the below holds */ 00581 MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */ 00582 MONOTONIC_INCREASING_NOT_NULL, /* But only for valid/real x and y */ 00583 MONOTONIC_STRICT_INCREASING,/* F() is unary and (x < y) => (F(x) < F(y)) */ 00584 MONOTONIC_STRICT_INCREASING_NOT_NULL /* But only for valid/real x and y */ 00585 } enum_monotonicity_info; 00586 00587 /*************************************************************************/ 00588 00589 class sp_rcontext; 00590 00591 00592 class Settable_routine_parameter 00593 { 00594 public: 00595 /* 00596 Set required privileges for accessing the parameter. 00597 00598 SYNOPSIS 00599 set_required_privilege() 00600 rw if 'rw' is true then we are going to read and set the 00601 parameter, so SELECT and UPDATE privileges might be 00602 required, otherwise we only reading it and SELECT 00603 privilege might be required. 00604 */ 00605 Settable_routine_parameter() {} 00606 virtual ~Settable_routine_parameter() {} 00607 virtual void set_required_privilege(bool rw) {}; 00608 00609 /* 00610 Set parameter value. 00611 00612 SYNOPSIS 00613 set_value() 00614 thd thread handle 00615 ctx context to which parameter belongs (if it is local 00616 variable). 00617 it item which represents new value 00618 00619 RETURN 00620 FALSE if parameter value has been set, 00621 TRUE if error has occured. 00622 */ 00623 virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)= 0; 00624 00625 virtual void set_out_param_info(Send_field *info) {} 00626 00627 virtual const Send_field *get_out_param_info() const 00628 { return NULL; } 00629 }; 00630 00631 00632 typedef bool (Item::*Item_processor) (uchar *arg); 00633 /* 00634 Analyzer function 00635 SYNOPSIS 00636 argp in/out IN: Analysis parameter 00637 OUT: Parameter to be passed to the transformer 00638 00639 RETURN 00640 TRUE Invoke the transformer 00641 FALSE Don't do it 00642 00643 */ 00644 typedef bool (Item::*Item_analyzer) (uchar **argp); 00645 typedef Item* (Item::*Item_transformer) (uchar *arg); 00646 typedef void (*Cond_traverser) (const Item *item, void *arg); 00647 00648 00649 class Item 00650 { 00651 Item(const Item &); /* Prevent use of these */ 00652 void operator=(Item &); 00653 /* Cache of the result of is_expensive(). */ 00654 int8 is_expensive_cache; 00655 virtual bool is_expensive_processor(uchar *arg) { return 0; } 00656 00657 public: 00658 static void *operator new(size_t size) throw () 00659 { return sql_alloc(size); } 00660 static void *operator new(size_t size, MEM_ROOT *mem_root) throw () 00661 { return alloc_root(mem_root, size); } 00662 static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); } 00663 static void operator delete(void *ptr, MEM_ROOT *mem_root) {} 00664 00665 enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM, 00666 INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM, 00667 COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM, 00668 PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM, 00669 FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM, 00670 SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER, 00671 PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM, 00672 XPATH_NODESET, XPATH_NODESET_CMP, 00673 VIEW_FIXER_ITEM}; 00674 00675 enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE }; 00676 00677 enum traverse_order { POSTFIX, PREFIX }; 00678 00679 /* Reuse size, only used by SP local variable assignment, otherwize 0 */ 00680 uint rsize; 00681 00682 /* 00683 str_values's main purpose is to be used to cache the value in 00684 save_in_field 00685 */ 00686 String str_value; 00687 00688 Item_name_string item_name; /* Name from select */ 00689 Item_name_string orig_name; /* Original item name (if it was renamed)*/ 00690 00698 Item *next; 00699 uint32 max_length; /* Maximum length, in bytes */ 00717 int marker; 00718 uint8 decimals; 00719 my_bool maybe_null; /* If item may be null */ 00720 my_bool null_value; /* if item is null */ 00721 my_bool unsigned_flag; 00722 my_bool with_sum_func; 00723 my_bool fixed; /* If item fixed with fix_fields */ 00724 DTCollation collation; 00725 Item_result cmp_context; /* Comparison context */ 00726 /* 00727 If this item was created in runtime memroot,it cannot be used for 00728 substitution in subquery transformation process 00729 */ 00730 bool runtime_item; 00731 protected: 00732 my_bool with_subselect; /* If this item is a subselect or some 00733 of its arguments is or contains a 00734 subselect. Computed by fix_fields 00735 and updated by update_used_tables. */ 00736 my_bool with_stored_program; /* If this item is a stored program 00737 or some of its arguments is or 00738 contains a stored program. 00739 Computed by fix_fields and updated 00740 by update_used_tables. */ 00741 00750 bool tables_locked_cache; 00751 public: 00752 // alloc & destruct is done as start of select using sql_alloc 00753 Item(); 00754 /* 00755 Constructor used by Item_field, Item_ref & aggregate (sum) functions. 00756 Used for duplicating lists in processing queries with temporary 00757 tables 00758 Also it used for Item_cond_and/Item_cond_or for creating 00759 top AND/OR structure of WHERE clause to protect it of 00760 optimisation changes in prepared statements 00761 */ 00762 Item(THD *thd, Item *item); 00763 virtual ~Item() 00764 { 00765 #ifdef EXTRA_DEBUG 00766 item_name.set(0); 00767 #endif 00768 } /*lint -e1509 */ 00769 void rename(char *new_name); 00770 void init_make_field(Send_field *tmp_field,enum enum_field_types type); 00771 virtual void cleanup(); 00772 virtual void make_field(Send_field *field); 00773 virtual Field *make_string_field(TABLE *table); 00774 virtual bool fix_fields(THD *, Item **); 00784 virtual void fix_after_pullout(st_select_lex *parent_select, 00785 st_select_lex *removed_select) 00786 {}; 00787 /* 00788 should be used in case where we are sure that we do not need 00789 complete fix_fields() procedure. 00790 */ 00791 inline void quick_fix_field() { fixed= 1; } 00792 /* Function returns 1 on overflow and -1 on fatal errors */ 00793 type_conversion_status save_in_field_no_warnings(Field *field, 00794 bool no_conversions); 00802 virtual type_conversion_status save_in_field(Field *field, 00803 bool no_conversions); 00804 virtual void save_org_in_field(Field *field) 00805 { (void) save_in_field(field, 1); } 00806 virtual type_conversion_status save_safe_in_field(Field *field) 00807 { return save_in_field(field, 1); } 00808 virtual bool send(Protocol *protocol, String *str); 00809 virtual bool eq(const Item *, bool binary_cmp) const; 00810 virtual Item_result result_type() const { return REAL_RESULT; } 00815 virtual enum Item_result numeric_context_result_type() const 00816 { 00817 if (is_temporal()) 00818 return decimals ? DECIMAL_RESULT : INT_RESULT; 00819 if (result_type() == STRING_RESULT) 00820 return REAL_RESULT; 00821 return result_type(); 00822 } 00827 inline enum Item_result temporal_with_date_as_number_result_type() const 00828 { 00829 return is_temporal_with_date() ? 00830 (decimals ? DECIMAL_RESULT : INT_RESULT) : result_type(); 00831 } 00832 virtual Item_result cast_to_int_type() const { return result_type(); } 00833 virtual enum_field_types string_field_type() const; 00834 virtual enum_field_types field_type() const; 00835 virtual enum Type type() const =0; 00836 00837 /* 00838 Return information about function monotonicity. See comment for 00839 enum_monotonicity_info for details. This function can only be called 00840 after fix_fields() call. 00841 */ 00842 virtual enum_monotonicity_info get_monotonicity_info() const 00843 { return NON_MONOTONIC; } 00844 00845 /* 00846 Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2" 00847 00848 SYNOPSIS 00849 val_int_endpoint() 00850 left_endp FALSE <=> The interval is "x < const" or "x <= const" 00851 TRUE <=> The interval is "x > const" or "x >= const" 00852 00853 incl_endp IN FALSE <=> the comparison is '<' or '>' 00854 TRUE <=> the comparison is '<=' or '>=' 00855 OUT The same but for the "F(x) $CMP$ F(const)" comparison 00856 00857 DESCRIPTION 00858 This function is defined only for unary monotonic functions. The caller 00859 supplies the source half-interval 00860 00861 x $CMP$ const 00862 00863 The value of const is supplied implicitly as the value this item's 00864 argument, the form of $CMP$ comparison is specified through the 00865 function's arguments. The calle returns the result interval 00866 00867 F(x) $CMP2$ F(const) 00868 00869 passing back F(const) as the return value, and the form of $CMP2$ 00870 through the out parameter. NULL values are assumed to be comparable and 00871 be less than any non-NULL values. 00872 00873 RETURN 00874 The output range bound, which equal to the value of val_int() 00875 - If the value of the function is NULL then the bound is the 00876 smallest possible value of LONGLONG_MIN 00877 */ 00878 virtual longlong val_int_endpoint(bool left_endp, bool *incl_endp) 00879 { DBUG_ASSERT(0); return 0; } 00880 00881 00882 /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */ 00883 /* 00884 Return double precision floating point representation of item. 00885 00886 SYNOPSIS 00887 val_real() 00888 00889 RETURN 00890 In case of NULL value return 0.0 and set null_value flag to TRUE. 00891 If value is not null null_value flag will be reset to FALSE. 00892 */ 00893 virtual double val_real()=0; 00894 /* 00895 Return integer representation of item. 00896 00897 SYNOPSIS 00898 val_int() 00899 00900 RETURN 00901 In case of NULL value return 0 and set null_value flag to TRUE. 00902 If value is not null null_value flag will be reset to FALSE. 00903 */ 00904 virtual longlong val_int()=0; 00908 virtual longlong val_date_temporal(); 00912 virtual longlong val_time_temporal(); 00917 longlong val_temporal_by_field_type() 00918 { 00919 if (field_type() == MYSQL_TYPE_TIME) 00920 return val_time_temporal(); 00921 DBUG_ASSERT(is_temporal_with_date()); 00922 return val_date_temporal(); 00923 } 00929 longlong val_temporal_with_round(enum_field_types type, uint8 dec); 00930 00931 /* 00932 This is just a shortcut to avoid the cast. You should still use 00933 unsigned_flag to check the sign of the item. 00934 */ 00935 inline ulonglong val_uint() { return (ulonglong) val_int(); } 00936 /* 00937 Return string representation of this item object. 00938 00939 SYNOPSIS 00940 val_str() 00941 str an allocated buffer this or any nested Item object can use to 00942 store return value of this method. 00943 00944 NOTE 00945 Buffer passed via argument should only be used if the item itself 00946 doesn't have an own String buffer. In case when the item maintains 00947 it's own string buffer, it's preferable to return it instead to 00948 minimize number of mallocs/memcpys. 00949 The caller of this method can modify returned string, but only in case 00950 when it was allocated on heap, (is_alloced() is true). This allows 00951 the caller to efficiently use a buffer allocated by a child without 00952 having to allocate a buffer of it's own. The buffer, given to 00953 val_str() as argument, belongs to the caller and is later used by the 00954 caller at it's own choosing. 00955 A few implications from the above: 00956 - unless you return a string object which only points to your buffer 00957 but doesn't manages it you should be ready that it will be 00958 modified. 00959 - even for not allocated strings (is_alloced() == false) the caller 00960 can change charset (see Item_func_{typecast/binary}. XXX: is this 00961 a bug? 00962 - still you should try to minimize data copying and return internal 00963 object whenever possible. 00964 00965 RETURN 00966 In case of NULL value return 0 (NULL pointer) and set null_value flag 00967 to TRUE. 00968 If value is not null null_value flag will be reset to FALSE. 00969 */ 00970 virtual String *val_str(String *str)=0; 00971 00972 /* 00973 Returns string representation of this item in ASCII format. 00974 00975 SYNOPSIS 00976 val_str_ascii() 00977 str - similar to val_str(); 00978 00979 NOTE 00980 This method is introduced for performance optimization purposes. 00981 00982 1. val_str() result of some Items in string context 00983 depends on @@character_set_results. 00984 @@character_set_results can be set to a "real multibyte" character 00985 set like UCS2, UTF16, UTF32. (We'll use only UTF32 in the examples 00986 below for convenience.) 00987 00988 So the default string result of such functions 00989 in these circumstances is real multi-byte character set, like UTF32. 00990 00991 For example, all numbers in string context 00992 return result in @@character_set_results: 00993 00994 SELECT CONCAT(20010101); -> UTF32 00995 00996 We do sprintf() first (to get ASCII representation) 00997 and then convert to UTF32; 00998 00999 So these kind "data sources" can use ASCII representation 01000 internally, but return multi-byte data only because 01001 @@character_set_results wants so. 01002 Therefore, conversion from ASCII to UTF32 is applied internally. 01003 01004 01005 2. Some other functions need in fact ASCII input. 01006 01007 For example, 01008 inet_aton(), GeometryFromText(), Convert_TZ(), GET_FORMAT(). 01009 01010 Similar, fields of certain type, like DATE, TIME, 01011 when you insert string data into them, expect in fact ASCII input. 01012 If they get non-ASCII input, for example UTF32, they 01013 convert input from UTF32 to ASCII, and then use ASCII 01014 representation to do further processing. 01015 01016 01017 3. Now imagine we pass result of a data source of the first type 01018 to a data destination of the second type. 01019 01020 What happens: 01021 a. data source converts data from ASCII to UTF32, because 01022 @@character_set_results wants so and passes the result to 01023 data destination. 01024 b. data destination gets UTF32 string. 01025 c. data destination converts UTF32 string to ASCII, 01026 because it needs ASCII representation to be able to handle data 01027 correctly. 01028 01029 As a result we get two steps of unnecessary conversion: 01030 From ASCII to UTF32, then from UTF32 to ASCII. 01031 01032 A better way to handle these situations is to pass ASCII 01033 representation directly from the source to the destination. 01034 01035 This is why val_str_ascii() introduced. 01036 01037 RETURN 01038 Similar to val_str() 01039 */ 01040 virtual String *val_str_ascii(String *str); 01041 01042 /* 01043 Return decimal representation of item with fixed point. 01044 01045 SYNOPSIS 01046 val_decimal() 01047 decimal_buffer buffer which can be used by Item for returning value 01048 (but can be not) 01049 01050 NOTE 01051 Returned value should not be changed if it is not the same which was 01052 passed via argument. 01053 01054 RETURN 01055 Return pointer on my_decimal (it can be other then passed via argument) 01056 if value is not NULL (null_value flag will be reset to FALSE). 01057 In case of NULL value it return 0 pointer and set null_value flag 01058 to TRUE. 01059 */ 01060 virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0; 01061 /* 01062 Return boolean value of item. 01063 01064 RETURN 01065 FALSE value is false or NULL 01066 TRUE value is true (not equal to 0) 01067 */ 01068 virtual bool val_bool(); 01069 virtual String *val_nodeset(String*) { return 0; } 01070 01071 protected: 01072 /* Helper functions, see item_sum.cc */ 01073 String *val_string_from_real(String *str); 01074 String *val_string_from_int(String *str); 01075 String *val_string_from_decimal(String *str); 01076 String *val_string_from_date(String *str); 01077 String *val_string_from_datetime(String *str); 01078 String *val_string_from_time(String *str); 01079 my_decimal *val_decimal_from_real(my_decimal *decimal_value); 01080 my_decimal *val_decimal_from_int(my_decimal *decimal_value); 01081 my_decimal *val_decimal_from_string(my_decimal *decimal_value); 01082 my_decimal *val_decimal_from_date(my_decimal *decimal_value); 01083 my_decimal *val_decimal_from_time(my_decimal *decimal_value); 01084 longlong val_int_from_decimal(); 01085 longlong val_int_from_date(); 01086 longlong val_int_from_time(); 01087 longlong val_int_from_datetime(); 01088 double val_real_from_decimal(); 01089 01093 bool get_date_from_string(MYSQL_TIME *ltime, uint flags); 01097 bool get_date_from_real(MYSQL_TIME *ltime, uint flags); 01101 bool get_date_from_decimal(MYSQL_TIME *ltime, uint flags); 01105 bool get_date_from_int(MYSQL_TIME *ltime, uint flags); 01109 bool get_date_from_time(MYSQL_TIME *ltime); 01110 01114 bool get_date_from_numeric(MYSQL_TIME *ltime, uint fuzzydate); 01115 01119 bool get_date_from_non_temporal(MYSQL_TIME *ltime, uint fuzzydate); 01120 01124 bool get_time_from_string(MYSQL_TIME *ltime); 01128 bool get_time_from_real(MYSQL_TIME *ltime); 01132 bool get_time_from_decimal(MYSQL_TIME *ltime); 01136 bool get_time_from_int(MYSQL_TIME *ltime); 01140 bool get_time_from_date(MYSQL_TIME *ltime); 01144 bool get_time_from_datetime(MYSQL_TIME *ltime); 01145 01149 bool get_time_from_numeric(MYSQL_TIME *ltime); 01150 01154 bool get_time_from_non_temporal(MYSQL_TIME *ltime); 01155 01156 01157 public: 01158 01159 type_conversion_status save_time_in_field(Field *field); 01160 type_conversion_status save_date_in_field(Field *field); 01161 type_conversion_status save_str_value_in_field(Field *field, String *result); 01162 01163 virtual Field *get_tmp_table_field() { return 0; } 01164 /* This is also used to create fields in CREATE ... SELECT: */ 01165 virtual Field *tmp_table_field(TABLE *t_arg) { return 0; } 01166 virtual const char *full_name() const 01167 { 01168 return item_name.is_set() ? item_name.ptr() : "???"; 01169 } 01170 01171 /* 01172 *result* family of methods is analog of *val* family (see above) but 01173 return value of result_field of item if it is present. If Item have not 01174 result field, it return val(). This methods set null_value flag in same 01175 way as *val* methods do it. 01176 */ 01177 virtual double val_result() { return val_real(); } 01178 virtual longlong val_int_result() { return val_int(); } 01182 virtual longlong val_time_temporal_result() { return val_time_temporal(); } 01186 virtual longlong val_date_temporal_result() { return val_date_temporal(); } 01187 virtual String *str_result(String* tmp) { return val_str(tmp); } 01188 virtual my_decimal *val_decimal_result(my_decimal *val) 01189 { return val_decimal(val); } 01190 virtual bool val_bool_result() { return val_bool(); } 01191 virtual bool is_null_result() { return is_null(); } 01192 01193 /* bit map of tables used by item */ 01194 virtual table_map used_tables() const { return (table_map) 0L; } 01205 virtual table_map resolved_used_tables() const 01206 { 01207 // As this is the level this item was resolved on, it cannot be outer: 01208 DBUG_ASSERT(!(used_tables() & OUTER_REF_TABLE_BIT)); 01209 01210 return used_tables(); 01211 } 01212 /* 01213 Return table map of tables that can't be NULL tables (tables that are 01214 used in a context where if they would contain a NULL row generated 01215 by a LEFT or RIGHT join, the item would not be true). 01216 This expression is used on WHERE item to determinate if a LEFT JOIN can be 01217 converted to a normal join. 01218 Generally this function should return used_tables() if the function 01219 would return null if any of the arguments are null 01220 As this is only used in the beginning of optimization, the value don't 01221 have to be updated in update_used_tables() 01222 */ 01223 virtual table_map not_null_tables() const { return used_tables(); } 01224 /* 01225 Returns true if this is a simple constant item like an integer, not 01226 a constant expression. Used in the optimizer to propagate basic constants. 01227 */ 01228 virtual bool basic_const_item() const { return 0; } 01229 /* cloning of constant items (0 if it is not const) */ 01230 virtual Item *clone_item() { return 0; } 01231 virtual cond_result eq_cmp_result() const { return COND_OK; } 01232 inline uint float_length(uint decimals_par) const 01233 { return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;} 01234 virtual uint decimal_precision() const; 01235 inline int decimal_int_part() const 01236 { return my_decimal_int_part(decimal_precision(), decimals); } 01240 virtual uint time_precision(); 01244 virtual uint datetime_precision(); 01245 /* 01246 Returns true if this is constant (during query execution, i.e. its value 01247 will not change until next fix_fields) and its value is known. 01248 When the default implementation of used_tables() is effective, this 01249 function will always return true (because used_tables() is empty). 01250 */ 01251 virtual bool const_item() const 01252 { 01253 if (used_tables() == 0) 01254 return can_be_evaluated_now(); 01255 return false; 01256 } 01257 /* 01258 Returns true if this is constant but its value may be not known yet. 01259 (Can be used for parameters of prep. stmts or of stored procedures.) 01260 */ 01261 virtual bool const_during_execution() const 01262 { return (used_tables() & ~PARAM_TABLE_BIT) == 0; } 01263 01275 virtual inline void print(String *str, enum_query_type query_type) 01276 { 01277 str->append(full_name()); 01278 } 01279 01280 void print_item_w_name(String *, enum_query_type query_type); 01287 void print_for_order(String *str, enum_query_type query_type, 01288 bool used_alias); 01289 01290 virtual void update_used_tables() {} 01291 virtual void split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, 01292 List<Item> &fields) {} 01293 /* Called for items that really have to be split */ 01294 void split_sum_func2(THD *thd, Ref_ptr_array ref_pointer_array, 01295 List<Item> &fields, 01296 Item **ref, bool skip_registered); 01297 virtual bool get_date(MYSQL_TIME *ltime,uint fuzzydate)= 0; 01298 virtual bool get_time(MYSQL_TIME *ltime)= 0; 01304 virtual bool get_timeval(struct timeval *tm, int *warnings); 01305 virtual bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate) 01306 { return get_date(ltime,fuzzydate); } 01307 /* 01308 The method allows to determine nullness of a complex expression 01309 without fully evaluating it, instead of calling val/result*() then 01310 checking null_value. Used in Item_func_isnull/Item_func_isnotnull 01311 and Item_sum_count/Item_sum_count_distinct. 01312 Any new item which can be NULL must implement this method. 01313 */ 01314 virtual bool is_null() { return 0; } 01315 01316 /* 01317 Make sure the null_value member has a correct value. 01318 */ 01319 virtual void update_null_value () { (void) val_int(); } 01320 01321 /* 01322 Inform the item that there will be no distinction between its result 01323 being FALSE or NULL. 01324 01325 NOTE 01326 This function will be called for eg. Items that are top-level AND-parts 01327 of the WHERE clause. Items implementing this function (currently 01328 Item_cond_and and subquery-related item) enable special optimizations 01329 when they are "top level". 01330 */ 01331 virtual void top_level_item() {} 01332 /* 01333 set field of temporary table for Item which can be switched on temporary 01334 table during query processing (grouping and so on) 01335 */ 01336 virtual void set_result_field(Field *field) {} 01337 virtual bool is_result_field() { return 0; } 01338 virtual bool is_bool_func() { return 0; } 01339 virtual void save_in_result_field(bool no_conversions) {} 01340 /* 01341 Set value of aggregate function in case of no rows for grouping were found. 01342 Also used for subqueries with outer references in SELECT list. 01343 */ 01344 virtual void no_rows_in_result() {} 01345 virtual Item *copy_or_same(THD *thd) { return this; } 01351 virtual Item *copy_andor_structure(THD *thd, bool real_items= false) 01352 { return real_items ? real_item() : this; } 01353 virtual Item *real_item() { return this; } 01354 virtual Item *substitutional_item() 01355 { 01356 return runtime_item ? real_item() : this; 01357 } 01358 virtual void set_runtime_created() { runtime_item= true; } 01359 virtual Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); } 01360 01361 static const CHARSET_INFO *default_charset(); 01362 virtual const CHARSET_INFO *compare_collation() { return NULL; } 01363 01364 /* 01365 For backward compatibility, to make numeric 01366 data types return "binary" charset in client-side metadata. 01367 */ 01368 virtual const CHARSET_INFO *charset_for_protocol(void) const 01369 { 01370 return result_type() == STRING_RESULT ? collation.collation : 01371 &my_charset_bin; 01372 }; 01373 01374 virtual bool walk(Item_processor processor, bool walk_subquery, uchar *arg) 01375 { 01376 return (this->*processor)(arg); 01377 } 01378 01379 virtual Item* transform(Item_transformer transformer, uchar *arg); 01380 01381 /* 01382 This function performs a generic "compilation" of the Item tree. 01383 The process of compilation is assumed to go as follows: 01384 01385 compile() 01386 { 01387 if (this->*some_analyzer(...)) 01388 { 01389 compile children if any; 01390 return this->*some_transformer(...); 01391 } 01392 else 01393 return this; 01394 } 01395 01396 i.e. analysis is performed top-down while transformation is done 01397 bottom-up. If no transformation is applied, the item is returned unchanged. 01398 A transformation error is indicated by returning a NULL pointer. Notice 01399 that the analyzer function should never cause an error. 01400 */ 01401 virtual Item* compile(Item_analyzer analyzer, uchar **arg_p, 01402 Item_transformer transformer, uchar *arg_t) 01403 { 01404 if ((this->*analyzer) (arg_p)) 01405 return ((this->*transformer) (arg_t)); 01406 return this; 01407 } 01408 01409 virtual void traverse_cond(Cond_traverser traverser, 01410 void *arg, traverse_order order) 01411 { 01412 (*traverser)(this, arg); 01413 } 01414 01415 /* 01416 This is used to get the most recent version of any function in 01417 an item tree. The version is the version where a MySQL function 01418 was introduced in. So any function which is added should use 01419 this function and set the int_arg to maximum of the input data 01420 and their own version info. 01421 */ 01422 virtual bool intro_version(uchar *int_arg) { return 0; } 01423 01424 virtual bool remove_dependence_processor(uchar * arg) { return 0; } 01425 virtual bool remove_fixed(uchar * arg) { fixed= 0; return 0; } 01426 virtual bool cleanup_processor(uchar *arg); 01427 virtual bool collect_item_field_processor(uchar * arg) { return 0; } 01428 virtual bool add_field_to_set_processor(uchar * arg) { return 0; } 01429 01437 virtual bool remove_column_from_bitmap(uchar *arg) { return false; } 01438 virtual bool find_item_in_field_list_processor(uchar *arg) { return 0; } 01439 virtual bool change_context_processor(uchar *context) { return 0; } 01440 virtual bool reset_query_id_processor(uchar *query_id_arg) { return 0; } 01441 virtual bool find_item_processor(uchar *arg) { return this == (void *) arg; } 01442 virtual bool register_field_in_read_map(uchar *arg) { return 0; } 01443 virtual bool inform_item_in_cond_of_tab(uchar *join_tab_index) { return false; } 01450 virtual bool clean_up_after_removal(uchar *arg) { return false; } 01451 01452 virtual bool cache_const_expr_analyzer(uchar **arg); 01453 virtual Item* cache_const_expr_transformer(uchar *arg); 01454 01463 virtual bool item_field_by_name_analyzer(uchar **arg) { return true; }; 01464 01474 virtual Item* item_field_by_name_transformer(uchar *arg) { return this; } 01475 01476 virtual bool equality_substitution_analyzer(uchar **arg) { return false; } 01477 01478 virtual Item* equality_substitution_transformer(uchar *arg) { return this; } 01479 01480 /* 01481 Check if a partition function is allowed 01482 SYNOPSIS 01483 check_partition_func_processor() 01484 int_arg Ignored 01485 RETURN VALUE 01486 TRUE Partition function not accepted 01487 FALSE Partition function accepted 01488 01489 DESCRIPTION 01490 check_partition_func_processor is used to check if a partition function 01491 uses an allowed function. An allowed function will always ensure that 01492 X=Y guarantees that also part_function(X)=part_function(Y) where X is 01493 a set of partition fields and so is Y. The problems comes mainly from 01494 character sets where two equal strings can be quite unequal. E.g. the 01495 german character for double s is equal to 2 s. 01496 01497 The default is that an item is not allowed 01498 in a partition function. Allowed functions 01499 can never depend on server version, they cannot depend on anything 01500 related to the environment. They can also only depend on a set of 01501 fields in the table itself. They cannot depend on other tables and 01502 cannot contain any queries and cannot contain udf's or similar. 01503 If a new Item class is defined and it inherits from a class that is 01504 allowed in a partition function then it is very important to consider 01505 whether this should be inherited to the new class. If not the function 01506 below should be defined in the new Item class. 01507 01508 The general behaviour is that most integer functions are allowed. 01509 If the partition function contains any multi-byte collations then 01510 the function check_part_func_fields will report an error on the 01511 partition function independent of what functions are used. So the 01512 only character sets allowed are single character collation and 01513 even for those only a limited set of functions are allowed. The 01514 problem with multi-byte collations is that almost every string 01515 function has the ability to change things such that two strings 01516 that are equal will not be equal after manipulated by a string 01517 function. E.g. two strings one contains a double s, there is a 01518 special german character that is equal to two s. Now assume a 01519 string function removes one character at this place, then in 01520 one the double s will be removed and in the other there will 01521 still be one s remaining and the strings are no longer equal 01522 and thus the partition function will not sort equal strings into 01523 the same partitions. 01524 01525 So the check if a partition function is valid is two steps. First 01526 check that the field types are valid, next check that the partition 01527 function is valid. The current set of partition functions valid 01528 assumes that there are no multi-byte collations amongst the partition 01529 fields. 01530 */ 01531 virtual bool check_partition_func_processor(uchar *bool_arg) { return TRUE;} 01532 virtual bool subst_argument_checker(uchar **arg) 01533 { 01534 if (*arg) 01535 *arg= NULL; 01536 return TRUE; 01537 } 01538 virtual bool explain_subquery_checker(uchar **arg) { return true; } 01539 virtual Item *explain_subquery_propagator(uchar *arg) { return this; } 01540 01541 virtual Item *equal_fields_propagator(uchar * arg) { return this; } 01542 virtual bool set_no_const_sub(uchar *arg) { return FALSE; } 01543 virtual Item *replace_equal_field(uchar * arg) { return this; } 01544 /* 01545 Check if an expression value has allowed arguments, like DATE/DATETIME 01546 for date functions. Also used by partitioning code to reject 01547 timezone-dependent expressions in a (sub)partitioning function. 01548 */ 01549 virtual bool check_valid_arguments_processor(uchar *bool_arg) 01550 { 01551 return FALSE; 01552 } 01553 01566 virtual bool find_function_processor (uchar *arg) 01567 { 01568 return FALSE; 01569 } 01570 01571 /* 01572 For SP local variable returns pointer to Item representing its 01573 current value and pointer to current Item otherwise. 01574 */ 01575 virtual Item *this_item() { return this; } 01576 virtual const Item *this_item() const { return this; } 01577 01578 /* 01579 For SP local variable returns address of pointer to Item representing its 01580 current value and pointer passed via parameter otherwise. 01581 */ 01582 virtual Item **this_item_addr(THD *thd, Item **addr_arg) { return addr_arg; } 01583 01584 // Row emulation 01585 virtual uint cols() { return 1; } 01586 virtual Item* element_index(uint i) { return this; } 01587 virtual Item** addr(uint i) { return 0; } 01588 virtual bool check_cols(uint c); 01589 // It is not row => null inside is impossible 01590 virtual bool null_inside() { return 0; } 01591 // used in row subselects to get value of elements 01592 virtual void bring_value() {} 01593 01594 Field *tmp_table_field_from_field_type(TABLE *table, bool fixed_length); 01595 virtual Item_field *field_for_view_update() { return 0; } 01596 01597 virtual Item *neg_transformer(THD *thd) { return NULL; } 01598 virtual Item *update_value_transformer(uchar *select_arg) { return this; } 01599 virtual Item *safe_charset_converter(const CHARSET_INFO *tocs); 01600 void delete_self() 01601 { 01602 cleanup(); 01603 delete this; 01604 } 01605 01606 virtual bool is_splocal() { return 0; } /* Needed for error checking */ 01607 01608 /* 01609 Return Settable_routine_parameter interface of the Item. Return 0 01610 if this Item is not Settable_routine_parameter. 01611 */ 01612 virtual Settable_routine_parameter *get_settable_routine_parameter() 01613 { 01614 return 0; 01615 } 01616 inline bool is_temporal_with_date() const 01617 { 01618 return is_temporal_type_with_date(field_type()); 01619 } 01620 inline bool is_temporal_with_date_and_time() const 01621 { 01622 return is_temporal_type_with_date_and_time(field_type()); 01623 } 01624 inline bool is_temporal_with_time() const 01625 { 01626 return is_temporal_type_with_time(field_type()); 01627 } 01628 inline bool is_temporal() const 01629 { 01630 return is_temporal_type(field_type()); 01631 } 01641 inline bool has_compatible_context(Item *item) const 01642 { 01643 /* Same context. */ 01644 if (cmp_context == (Item_result)-1 || item->cmp_context == cmp_context) 01645 return TRUE; 01646 /* DATETIME comparison context. */ 01647 if (is_temporal_with_date()) 01648 return item->is_temporal_with_date() || 01649 item->cmp_context == STRING_RESULT; 01650 if (item->is_temporal_with_date()) 01651 return is_temporal_with_date() || cmp_context == STRING_RESULT; 01652 return FALSE; 01653 } 01654 virtual Field::geometry_type get_geometry_type() const 01655 { return Field::GEOM_GEOMETRY; }; 01656 String *check_well_formed_result(String *str, bool send_error= 0); 01657 bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO *cs); 01658 01659 /* 01660 Test whether an expression is expensive to compute. Used during 01661 optimization to avoid computing expensive expressions during this 01662 phase. Also used to force temp tables when sorting on expensive 01663 functions. 01664 TODO: 01665 Normally we should have a method: 01666 cost Item::execution_cost(), 01667 where 'cost' is either 'double' or some structure of various cost 01668 parameters. 01669 */ 01670 virtual bool is_expensive() 01671 { 01672 if (is_expensive_cache < 0) 01673 is_expensive_cache= walk(&Item::is_expensive_processor, 0, (uchar*)0); 01674 return MY_TEST(is_expensive_cache); 01675 } 01676 virtual bool can_be_evaluated_now() const; 01677 uint32 max_char_length() const 01678 { return max_length / collation.collation->mbmaxlen; } 01679 void fix_length_and_charset(uint32 max_char_length_arg, 01680 const CHARSET_INFO *cs) 01681 { 01682 max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen); 01683 collation.collation= cs; 01684 } 01685 void fix_char_length(uint32 max_char_length_arg) 01686 { 01687 max_length= char_to_byte_length_safe(max_char_length_arg, 01688 collation.collation->mbmaxlen); 01689 } 01690 void fix_char_length_ulonglong(ulonglong max_char_length_arg) 01691 { 01692 ulonglong max_result_length= max_char_length_arg * 01693 collation.collation->mbmaxlen; 01694 if (max_result_length >= MAX_BLOB_WIDTH) 01695 { 01696 max_length= MAX_BLOB_WIDTH; 01697 maybe_null= 1; 01698 } 01699 else 01700 max_length= (uint32) max_result_length; 01701 } 01702 void fix_length_and_charset_datetime(uint32 max_char_length_arg) 01703 { 01704 collation.set(&my_charset_numeric, DERIVATION_NUMERIC, MY_REPERTOIRE_ASCII); 01705 fix_char_length(max_char_length_arg); 01706 } 01707 void fix_length_and_dec_and_charset_datetime(uint32 max_char_length_arg, 01708 uint8 dec_arg) 01709 { 01710 decimals= dec_arg; 01711 fix_length_and_charset_datetime(max_char_length_arg + 01712 (dec_arg ? dec_arg + 1 : 0)); 01713 } 01714 /* 01715 Return TRUE if the item points to a column of an outer-joined table. 01716 */ 01717 virtual bool is_outer_field() const { DBUG_ASSERT(fixed); return FALSE; } 01718 01726 bool is_blob_field() const; 01727 01731 virtual bool has_subquery() const { return with_subselect; } 01732 virtual bool has_stored_program() const { return with_stored_program; } 01734 virtual bool created_by_in2exists() const { return false; } 01735 }; 01736 01737 01738 class sp_head; 01739 01740 01741 class Item_basic_constant :public Item 01742 { 01743 table_map used_table_map; 01744 public: 01745 Item_basic_constant(): Item(), used_table_map(0) {}; 01746 void set_used_tables(table_map map) { used_table_map= map; } 01747 table_map used_tables() const { return used_table_map; } 01748 /* to prevent drop fixed flag (no need parent cleanup call) */ 01749 void cleanup() 01750 { 01751 /* 01752 Restore the original field name as it might not have been allocated 01753 in the statement memory. If the name is auto generated, it must be 01754 done again between subsequent executions of a prepared statement. 01755 */ 01756 if (orig_name.is_set()) 01757 item_name= orig_name; 01758 } 01759 }; 01760 01761 01762 /***************************************************************************** 01763 The class is a base class for representation of stored routine variables in 01764 the Item-hierarchy. There are the following kinds of SP-vars: 01765 - local variables (Item_splocal); 01766 - CASE expression (Item_case_expr); 01767 *****************************************************************************/ 01768 01769 class Item_sp_variable :public Item 01770 { 01771 protected: 01772 /* 01773 THD, which is stored in fix_fields() and is used in this_item() to avoid 01774 current_thd use. 01775 */ 01776 THD *m_thd; 01777 01778 public: 01779 Name_string m_name; 01780 01781 public: 01782 #ifndef DBUG_OFF 01783 /* 01784 Routine to which this Item_splocal belongs. Used for checking if correct 01785 runtime context is used for variable handling. 01786 */ 01787 sp_head *m_sp; 01788 #endif 01789 01790 public: 01791 Item_sp_variable(const Name_string sp_var_name); 01792 01793 public: 01794 bool fix_fields(THD *thd, Item **); 01795 01796 double val_real(); 01797 longlong val_int(); 01798 String *val_str(String *sp); 01799 my_decimal *val_decimal(my_decimal *decimal_value); 01800 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 01801 bool get_time(MYSQL_TIME *ltime); 01802 bool is_null(); 01803 01804 public: 01805 inline void make_field(Send_field *field); 01806 inline type_conversion_status save_in_field(Field *field, 01807 bool no_conversions); 01808 inline bool send(Protocol *protocol, String *str); 01809 }; 01810 01811 /***************************************************************************** 01812 Item_sp_variable inline implementation. 01813 *****************************************************************************/ 01814 01815 inline void Item_sp_variable::make_field(Send_field *field) 01816 { 01817 Item *it= this_item(); 01818 it->item_name.copy(item_name.is_set() ? item_name : m_name); 01819 it->make_field(field); 01820 } 01821 01822 inline type_conversion_status 01823 Item_sp_variable::save_in_field(Field *field, bool no_conversions) 01824 { 01825 return this_item()->save_in_field(field, no_conversions); 01826 } 01827 01828 inline bool Item_sp_variable::send(Protocol *protocol, String *str) 01829 { 01830 return this_item()->send(protocol, str); 01831 } 01832 01833 01834 /***************************************************************************** 01835 A reference to local SP variable (incl. reference to SP parameter), used in 01836 runtime. 01837 *****************************************************************************/ 01838 01839 class Item_splocal :public Item_sp_variable, 01840 private Settable_routine_parameter 01841 { 01842 uint m_var_idx; 01843 01844 Type m_type; 01845 Item_result m_result_type; 01846 enum_field_types m_field_type; 01847 public: 01848 /* 01849 If this variable is a parameter in LIMIT clause. 01850 Used only during NAME_CONST substitution, to not append 01851 NAME_CONST to the resulting query and thus not break 01852 the slave. 01853 */ 01854 bool limit_clause_param; 01855 /* 01856 Position of this reference to SP variable in the statement (the 01857 statement itself is in sp_instr_stmt::m_query). 01858 This is valid only for references to SP variables in statements, 01859 excluding DECLARE CURSOR statement. It is used to replace references to SP 01860 variables with NAME_CONST calls when putting statements into the binary 01861 log. 01862 Value of 0 means that this object doesn't corresponding to reference to 01863 SP variable in query text. 01864 */ 01865 uint pos_in_query; 01866 /* 01867 Byte length of SP variable name in the statement (see pos_in_query). 01868 The value of this field may differ from the name_length value because 01869 name_length contains byte length of UTF8-encoded item name, but 01870 the query string (see sp_instr_stmt::m_query) is currently stored with 01871 a charset from the SET NAMES statement. 01872 */ 01873 uint len_in_query; 01874 01875 Item_splocal(const Name_string sp_var_name, uint sp_var_idx, 01876 enum_field_types sp_var_type, 01877 uint pos_in_q= 0, uint len_in_q= 0); 01878 01879 bool is_splocal() { return 1; } /* Needed for error checking */ 01880 01881 Item *this_item(); 01882 const Item *this_item() const; 01883 Item **this_item_addr(THD *thd, Item **); 01884 01885 virtual void print(String *str, enum_query_type query_type); 01886 01887 public: 01888 inline uint get_var_idx() const; 01889 01890 inline enum Type type() const; 01891 inline Item_result result_type() const; 01892 inline enum_field_types field_type() const { return m_field_type; } 01893 01894 private: 01895 bool set_value(THD *thd, sp_rcontext *ctx, Item **it); 01896 01897 public: 01898 Settable_routine_parameter *get_settable_routine_parameter() 01899 { 01900 return this; 01901 } 01902 }; 01903 01904 /***************************************************************************** 01905 Item_splocal inline implementation. 01906 *****************************************************************************/ 01907 01908 inline uint Item_splocal::get_var_idx() const 01909 { 01910 return m_var_idx; 01911 } 01912 01913 inline enum Item::Type Item_splocal::type() const 01914 { 01915 return m_type; 01916 } 01917 01918 inline Item_result Item_splocal::result_type() const 01919 { 01920 return m_result_type; 01921 } 01922 01923 01924 /***************************************************************************** 01925 A reference to case expression in SP, used in runtime. 01926 *****************************************************************************/ 01927 01928 class Item_case_expr :public Item_sp_variable 01929 { 01930 public: 01931 Item_case_expr(uint case_expr_id); 01932 01933 public: 01934 Item *this_item(); 01935 const Item *this_item() const; 01936 Item **this_item_addr(THD *thd, Item **); 01937 01938 inline enum Type type() const; 01939 inline Item_result result_type() const; 01940 01941 public: 01942 /* 01943 NOTE: print() is intended to be used from views and for debug. 01944 Item_case_expr can not occur in views, so here it is only for debug 01945 purposes. 01946 */ 01947 virtual void print(String *str, enum_query_type query_type); 01948 01949 private: 01950 uint m_case_expr_id; 01951 }; 01952 01953 /***************************************************************************** 01954 Item_case_expr inline implementation. 01955 *****************************************************************************/ 01956 01957 inline enum Item::Type Item_case_expr::type() const 01958 { 01959 return this_item()->type(); 01960 } 01961 01962 inline Item_result Item_case_expr::result_type() const 01963 { 01964 return this_item()->result_type(); 01965 } 01966 01967 01968 /* 01969 NAME_CONST(given_name, const_value). 01970 This 'function' has all properties of the supplied const_value (which is 01971 assumed to be a literal constant), and the name given_name. 01972 01973 This is used to replace references to SP variables when we write PROCEDURE 01974 statements into the binary log. 01975 01976 TODO 01977 Together with Item_splocal and Item::this_item() we can actually extract 01978 common a base of this class and Item_splocal. Maybe it is possible to 01979 extract a common base with class Item_ref, too. 01980 */ 01981 01982 class Item_name_const : public Item 01983 { 01984 Item *value_item; 01985 Item *name_item; 01986 bool valid_args; 01987 public: 01988 Item_name_const(Item *name_arg, Item *val); 01989 01990 bool fix_fields(THD *, Item **); 01991 01992 enum Type type() const; 01993 double val_real(); 01994 longlong val_int(); 01995 String *val_str(String *sp); 01996 my_decimal *val_decimal(my_decimal *); 01997 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 01998 bool get_time(MYSQL_TIME *ltime); 01999 bool is_null(); 02000 virtual void print(String *str, enum_query_type query_type); 02001 02002 Item_result result_type() const 02003 { 02004 return value_item->result_type(); 02005 } 02006 02007 type_conversion_status save_in_field(Field *field, bool no_conversions) 02008 { 02009 return value_item->save_in_field(field, no_conversions); 02010 } 02011 02012 bool send(Protocol *protocol, String *str) 02013 { 02014 return value_item->send(protocol, str); 02015 } 02016 }; 02017 02018 bool agg_item_collations(DTCollation &c, const char *name, 02019 Item **items, uint nitems, uint flags, int item_sep); 02020 bool agg_item_collations_for_comparison(DTCollation &c, const char *name, 02021 Item **items, uint nitems, uint flags); 02022 bool agg_item_set_converter(DTCollation &coll, const char *fname, 02023 Item **args, uint nargs, uint flags, int item_sep); 02024 bool agg_item_charsets(DTCollation &c, const char *name, 02025 Item **items, uint nitems, uint flags, int item_sep); 02026 inline bool 02027 agg_item_charsets_for_string_result(DTCollation &c, const char *name, 02028 Item **items, uint nitems, 02029 int item_sep= 1) 02030 { 02031 uint flags= MY_COLL_ALLOW_SUPERSET_CONV | 02032 MY_COLL_ALLOW_COERCIBLE_CONV | 02033 MY_COLL_ALLOW_NUMERIC_CONV; 02034 return agg_item_charsets(c, name, items, nitems, flags, item_sep); 02035 } 02036 inline bool 02037 agg_item_charsets_for_comparison(DTCollation &c, const char *name, 02038 Item **items, uint nitems, 02039 int item_sep= 1) 02040 { 02041 uint flags= MY_COLL_ALLOW_SUPERSET_CONV | 02042 MY_COLL_ALLOW_COERCIBLE_CONV | 02043 MY_COLL_DISALLOW_NONE; 02044 return agg_item_charsets(c, name, items, nitems, flags, item_sep); 02045 } 02046 inline bool 02047 agg_item_charsets_for_string_result_with_comparison(DTCollation &c, 02048 const char *name, 02049 Item **items, uint nitems, 02050 int item_sep= 1) 02051 { 02052 uint flags= MY_COLL_ALLOW_SUPERSET_CONV | 02053 MY_COLL_ALLOW_COERCIBLE_CONV | 02054 MY_COLL_ALLOW_NUMERIC_CONV | 02055 MY_COLL_DISALLOW_NONE; 02056 return agg_item_charsets(c, name, items, nitems, flags, item_sep); 02057 } 02058 02059 02060 class Item_num: public Item_basic_constant 02061 { 02062 public: 02063 Item_num() { collation.set_numeric(); } /* Remove gcc warning */ 02064 virtual Item_num *neg()= 0; 02065 Item *safe_charset_converter(const CHARSET_INFO *tocs); 02066 bool check_partition_func_processor(uchar *int_arg) { return FALSE;} 02067 }; 02068 02069 #define NO_CACHED_FIELD_INDEX ((uint)(-1)) 02070 02071 class st_select_lex; 02072 class Item_ident :public Item 02073 { 02074 protected: 02075 /* 02076 We have to store initial values of db_name, table_name and field_name 02077 to be able to restore them during cleanup() because they can be 02078 updated during fix_fields() to values from Field object and life-time 02079 of those is shorter than life-time of Item_field. 02080 */ 02081 const char *orig_db_name; 02082 const char *orig_table_name; 02083 const char *orig_field_name; 02084 02085 public: 02086 Name_resolution_context *context; 02087 const char *db_name; 02088 const char *table_name; 02089 const char *field_name; 02090 bool alias_name_used; /* true if item was resolved against alias */ 02091 /* 02092 Cached value of index for this field in table->field array, used by prep. 02093 stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX 02094 if index value is not known. 02095 */ 02096 uint cached_field_index; 02097 /* 02098 Cached pointer to table which contains this field, used for the same reason 02099 by prep. stmt. too in case then we have not-fully qualified field. 02100 0 - means no cached value. 02101 */ 02102 TABLE_LIST *cached_table; 02103 st_select_lex *depended_from; 02104 Item_ident(Name_resolution_context *context_arg, 02105 const char *db_name_arg, const char *table_name_arg, 02106 const char *field_name_arg); 02107 Item_ident(THD *thd, Item_ident *item); 02108 const char *full_name() const; 02109 virtual void fix_after_pullout(st_select_lex *parent_select, 02110 st_select_lex *removed_select); 02111 void cleanup(); 02112 bool remove_dependence_processor(uchar * arg); 02113 virtual void print(String *str, enum_query_type query_type); 02114 virtual bool change_context_processor(uchar *cntx) 02115 { context= (Name_resolution_context *)cntx; return FALSE; } 02116 friend bool insert_fields(THD *thd, Name_resolution_context *context, 02117 const char *db_name, 02118 const char *table_name, List_iterator<Item> *it, 02119 bool any_privileges); 02120 }; 02121 02122 02123 class Item_ident_for_show :public Item 02124 { 02125 public: 02126 Field *field; 02127 const char *db_name; 02128 const char *table_name; 02129 02130 Item_ident_for_show(Field *par_field, const char *db_arg, 02131 const char *table_name_arg) 02132 :field(par_field), db_name(db_arg), table_name(table_name_arg) 02133 {} 02134 02135 enum Type type() const { return FIELD_ITEM; } 02136 double val_real() { return field->val_real(); } 02137 longlong val_int() { return field->val_int(); } 02138 String *val_str(String *str) { return field->val_str(str); } 02139 my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); } 02140 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02141 { 02142 return field->get_date(ltime, fuzzydate); 02143 } 02144 bool get_time(MYSQL_TIME *ltime) 02145 { 02146 return field->get_time(ltime); 02147 } 02148 void make_field(Send_field *tmp_field); 02149 CHARSET_INFO *charset_for_protocol(void) const 02150 { return (CHARSET_INFO *)field->charset_for_protocol(); } 02151 }; 02152 02153 02154 class Item_equal; 02155 class COND_EQUAL; 02156 02157 class Item_field :public Item_ident 02158 { 02159 protected: 02160 void set_field(Field *field); 02161 public: 02162 Field *field,*result_field; 02163 Item_equal *item_equal; 02164 bool no_const_subst; 02165 /* 02166 if any_privileges set to TRUE then here real effective privileges will 02167 be stored 02168 */ 02169 uint have_privileges; 02170 /* field need any privileges (for VIEW creation) */ 02171 bool any_privileges; 02172 Item_field(Name_resolution_context *context_arg, 02173 const char *db_arg,const char *table_name_arg, 02174 const char *field_name_arg); 02175 /* 02176 Constructor needed to process subquery with temporary tables (see Item). 02177 Notice that it will have no name resolution context. 02178 */ 02179 Item_field(THD *thd, Item_field *item); 02180 /* 02181 Ensures that field, table, and database names will live as long as 02182 Item_field (this is important in prepared statements). 02183 */ 02184 Item_field(THD *thd, Name_resolution_context *context_arg, Field *field); 02185 /* 02186 If this constructor is used, fix_fields() won't work, because 02187 db_name, table_name and column_name are unknown. It's necessary to call 02188 reset_field() before fix_fields() for all fields created this way. 02189 */ 02190 Item_field(Field *field); 02191 enum Type type() const { return FIELD_ITEM; } 02192 bool eq(const Item *item, bool binary_cmp) const; 02193 double val_real(); 02194 longlong val_int(); 02195 longlong val_time_temporal(); 02196 longlong val_date_temporal(); 02197 my_decimal *val_decimal(my_decimal *); 02198 String *val_str(String*); 02199 double val_result(); 02200 longlong val_int_result(); 02201 longlong val_time_temporal_result(); 02202 longlong val_date_temporal_result(); 02203 String *str_result(String* tmp); 02204 my_decimal *val_decimal_result(my_decimal *); 02205 bool val_bool_result(); 02206 bool is_null_result(); 02207 bool send(Protocol *protocol, String *str_arg); 02208 void reset_field(Field *f); 02209 bool fix_fields(THD *, Item **); 02210 void make_field(Send_field *tmp_field); 02211 type_conversion_status save_in_field(Field *field,bool no_conversions); 02212 void save_org_in_field(Field *field); 02213 table_map used_tables() const; 02214 virtual table_map resolved_used_tables() const; 02215 enum Item_result result_type () const 02216 { 02217 return field->result_type(); 02218 } 02219 enum Item_result numeric_context_result_type() const 02220 { 02221 return field->numeric_context_result_type(); 02222 } 02223 Item_result cast_to_int_type() const 02224 { 02225 return field->cast_to_int_type(); 02226 } 02227 enum_field_types field_type() const 02228 { 02229 return field->type(); 02230 } 02231 enum_monotonicity_info get_monotonicity_info() const 02232 { 02233 return MONOTONIC_STRICT_INCREASING; 02234 } 02235 longlong val_int_endpoint(bool left_endp, bool *incl_endp); 02236 Field *get_tmp_table_field() { return result_field; } 02237 Field *tmp_table_field(TABLE *t_arg) { return result_field; } 02238 bool get_date(MYSQL_TIME *ltime,uint fuzzydate); 02239 bool get_date_result(MYSQL_TIME *ltime,uint fuzzydate); 02240 bool get_time(MYSQL_TIME *ltime); 02241 bool get_timeval(struct timeval *tm, int *warnings); 02242 bool is_null() { return field->is_null(); } 02243 void update_null_value(); 02244 Item *get_tmp_table_item(THD *thd); 02245 bool collect_item_field_processor(uchar * arg); 02246 bool add_field_to_set_processor(uchar * arg); 02247 bool remove_column_from_bitmap(uchar * arg); 02248 bool find_item_in_field_list_processor(uchar *arg); 02249 bool register_field_in_read_map(uchar *arg); 02250 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 02251 void cleanup(); 02252 Item_equal *find_item_equal(COND_EQUAL *cond_equal); 02253 bool subst_argument_checker(uchar **arg); 02254 Item *equal_fields_propagator(uchar *arg); 02255 bool set_no_const_sub(uchar *arg); 02256 Item *replace_equal_field(uchar *arg); 02257 inline uint32 max_disp_length() { return field->max_display_length(); } 02258 Item_field *field_for_view_update() { return this; } 02259 Item *safe_charset_converter(const CHARSET_INFO *tocs); 02260 int fix_outer_field(THD *thd, Field **field, Item **reference); 02261 virtual Item *update_value_transformer(uchar *select_arg); 02262 virtual bool item_field_by_name_analyzer(uchar **arg); 02263 virtual Item* item_field_by_name_transformer(uchar *arg); 02264 virtual void print(String *str, enum_query_type query_type); 02265 bool is_outer_field() const 02266 { 02267 DBUG_ASSERT(fixed); 02268 return field->table->pos_in_table_list->outer_join || 02269 field->table->pos_in_table_list->outer_join_nest(); 02270 } 02271 Field::geometry_type get_geometry_type() const 02272 { 02273 DBUG_ASSERT(field_type() == MYSQL_TYPE_GEOMETRY); 02274 return field->get_geometry_type(); 02275 } 02276 const CHARSET_INFO *charset_for_protocol(void) const 02277 { return field->charset_for_protocol(); } 02278 02279 #ifndef DBUG_OFF 02280 void dbug_print() 02281 { 02282 fprintf(DBUG_FILE, "<field "); 02283 if (field) 02284 { 02285 fprintf(DBUG_FILE, "'%s.%s': ", field->table->alias, field->field_name); 02286 field->dbug_print(); 02287 } 02288 else 02289 fprintf(DBUG_FILE, "NULL"); 02290 02291 fprintf(DBUG_FILE, ", result_field: "); 02292 if (result_field) 02293 { 02294 fprintf(DBUG_FILE, "'%s.%s': ", 02295 result_field->table->alias, result_field->field_name); 02296 result_field->dbug_print(); 02297 } 02298 else 02299 fprintf(DBUG_FILE, "NULL"); 02300 fprintf(DBUG_FILE, ">\n"); 02301 } 02302 #endif 02303 02305 bool push_to_non_agg_fields(st_select_lex *select_lex); 02306 02307 friend class Item_default_value; 02308 friend class Item_insert_value; 02309 friend class st_select_lex_unit; 02310 }; 02311 02312 class Item_null :public Item_basic_constant 02313 { 02314 void init() 02315 { 02316 maybe_null= null_value= TRUE; 02317 max_length= 0; 02318 fixed= 1; 02319 collation.set(&my_charset_bin, DERIVATION_IGNORABLE); 02320 } 02321 public: 02322 Item_null() 02323 { 02324 init(); 02325 item_name= NAME_STRING("NULL"); 02326 } 02327 Item_null(const Name_string &name_par) 02328 { 02329 init(); 02330 item_name= name_par; 02331 } 02332 enum Type type() const { return NULL_ITEM; } 02333 bool eq(const Item *item, bool binary_cmp) const; 02334 double val_real(); 02335 longlong val_int(); 02336 longlong val_time_temporal() { return val_int(); } 02337 longlong val_date_temporal() { return val_int(); } 02338 String *val_str(String *str); 02339 my_decimal *val_decimal(my_decimal *); 02340 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02341 { 02342 return true; 02343 } 02344 bool get_time(MYSQL_TIME *ltime) 02345 { 02346 return true; 02347 } 02348 type_conversion_status save_in_field(Field *field, bool no_conversions); 02349 type_conversion_status save_safe_in_field(Field *field); 02350 bool send(Protocol *protocol, String *str); 02351 enum Item_result result_type () const { return STRING_RESULT; } 02352 enum_field_types field_type() const { return MYSQL_TYPE_NULL; } 02353 bool basic_const_item() const { return 1; } 02354 Item *clone_item() { return new Item_null(item_name); } 02355 bool is_null() { return 1; } 02356 02357 virtual inline void print(String *str, enum_query_type query_type) 02358 { 02359 str->append(STRING_WITH_LEN("NULL")); 02360 } 02361 02362 Item *safe_charset_converter(const CHARSET_INFO *tocs); 02363 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 02364 }; 02365 02375 class Item_null_result :public Item_null 02376 { 02378 enum_field_types fld_type; 02380 Item_result res_type; 02381 02382 public: 02383 Field *result_field; 02384 Item_null_result(enum_field_types fld_type, Item_result res_type) 02385 : Item_null(), fld_type(fld_type), res_type(res_type), result_field(0) {} 02386 bool is_result_field() { return result_field != 0; } 02387 void save_in_result_field(bool no_conversions) 02388 { 02389 save_in_field(result_field, no_conversions); 02390 } 02391 bool check_partition_func_processor(uchar *int_arg) {return TRUE;} 02392 enum_field_types field_type() const { return fld_type; } 02393 Item_result result_type() const { return res_type; } 02394 }; 02395 02396 /* Item represents one placeholder ('?') of prepared statement */ 02397 02398 class Item_param :public Item, 02399 private Settable_routine_parameter 02400 { 02401 char cnvbuf[MAX_FIELD_WIDTH]; 02402 String cnvstr; 02403 Item *cnvitem; 02404 02405 public: 02406 enum enum_item_param_state 02407 { 02408 NO_VALUE, NULL_VALUE, INT_VALUE, REAL_VALUE, 02409 STRING_VALUE, TIME_VALUE, LONG_DATA_VALUE, 02410 DECIMAL_VALUE 02411 } state; 02412 02413 /* 02414 A buffer for string and long data values. Historically all allocated 02415 values returned from val_str() were treated as eligible to 02416 modification. I. e. in some cases Item_func_concat can append it's 02417 second argument to return value of the first one. Because of that we 02418 can't return the original buffer holding string data from val_str(), 02419 and have to have one buffer for data and another just pointing to 02420 the data. This is the latter one and it's returned from val_str(). 02421 Can not be declared inside the union as it's not a POD type. 02422 */ 02423 String str_value_ptr; 02424 my_decimal decimal_value; 02425 union 02426 { 02427 longlong integer; 02428 double real; 02429 /* 02430 Character sets conversion info for string values. 02431 Character sets of client and connection defined at bind time are used 02432 for all conversions, even if one of them is later changed (i.e. 02433 between subsequent calls to mysql_stmt_execute). 02434 */ 02435 struct CONVERSION_INFO 02436 { 02437 const CHARSET_INFO *character_set_client; 02438 const CHARSET_INFO *character_set_of_placeholder; 02439 /* 02440 This points at character set of connection if conversion 02441 to it is required (i. e. if placeholder typecode is not BLOB). 02442 Otherwise it's equal to character_set_client (to simplify 02443 check in convert_str_value()). 02444 */ 02445 const CHARSET_INFO *final_character_set_of_str_value; 02446 } cs_info; 02447 MYSQL_TIME time; 02448 } value; 02449 02450 /* Cached values for virtual methods to save us one switch. */ 02451 enum Item_result item_result_type; 02452 enum Type item_type; 02453 02454 /* 02455 Used when this item is used in a temporary table. 02456 This is NOT placeholder metadata sent to client, as this value 02457 is assigned after sending metadata (in setup_one_conversion_function). 02458 For example in case of 'SELECT ?' you'll get MYSQL_TYPE_STRING both 02459 in result set and placeholders metadata, no matter what type you will 02460 supply for this placeholder in mysql_stmt_execute. 02461 */ 02462 enum enum_field_types param_type; 02463 /* 02464 Offset of placeholder inside statement text. Used to create 02465 no-placeholders version of this statement for the binary log. 02466 */ 02467 uint pos_in_query; 02468 02469 Item_param(uint pos_in_query_arg); 02470 02471 enum Item_result result_type () const { return item_result_type; } 02472 enum Type type() const { return item_type; } 02473 enum_field_types field_type() const { return param_type; } 02474 02475 double val_real(); 02476 longlong val_int(); 02477 my_decimal *val_decimal(my_decimal*); 02478 String *val_str(String*); 02479 bool get_time(MYSQL_TIME *tm); 02480 bool get_date(MYSQL_TIME *tm, uint fuzzydate); 02481 type_conversion_status save_in_field(Field *field, bool no_conversions); 02482 02483 void set_null(); 02484 void set_int(longlong i, uint32 max_length_arg); 02485 void set_double(double i); 02486 void set_decimal(const char *str, ulong length); 02487 void set_decimal(const my_decimal *dv); 02488 bool set_str(const char *str, ulong length); 02489 bool set_longdata(const char *str, ulong length); 02490 void set_time(MYSQL_TIME *tm, timestamp_type type, uint32 max_length_arg); 02491 bool set_from_user_var(THD *thd, const user_var_entry *entry); 02492 void reset(); 02493 /* 02494 Assign placeholder value from bind data. 02495 Note, that 'len' has different semantics in embedded library (as we 02496 don't need to check that packet is not broken there). See 02497 sql_prepare.cc for details. 02498 */ 02499 void (*set_param_func)(Item_param *param, uchar **pos, ulong len); 02500 02501 const String *query_val_str(THD *thd, String *str) const; 02502 02503 bool convert_str_value(THD *thd); 02504 02505 /* 02506 If value for parameter was not set we treat it as non-const 02507 so noone will use parameters value in fix_fields still 02508 parameter is constant during execution. 02509 */ 02510 virtual table_map used_tables() const 02511 { return state != NO_VALUE ? (table_map)0 : PARAM_TABLE_BIT; } 02512 virtual void print(String *str, enum_query_type query_type); 02513 bool is_null() 02514 { DBUG_ASSERT(state != NO_VALUE); return state == NULL_VALUE; } 02515 bool basic_const_item() const; 02516 /* 02517 This method is used to make a copy of a basic constant item when 02518 propagating constants in the optimizer. The reason to create a new 02519 item and not use the existing one is not precisely known (2005/04/16). 02520 Probably we are trying to preserve tree structure of items, in other 02521 words, avoid pointing at one item from two different nodes of the tree. 02522 Return a new basic constant item if parameter value is a basic 02523 constant, assert otherwise. This method is called only if 02524 basic_const_item returned TRUE. 02525 */ 02526 Item *safe_charset_converter(const CHARSET_INFO *tocs); 02527 Item *clone_item(); 02528 /* 02529 Implement by-value equality evaluation if parameter value 02530 is set and is a basic constant (integer, real or string). 02531 Otherwise return FALSE. 02532 */ 02533 bool eq(const Item *item, bool binary_cmp) const; 02535 bool limit_clause_param; 02536 void set_param_type_and_swap_value(Item_param *from); 02537 02538 private: 02539 virtual inline Settable_routine_parameter * 02540 get_settable_routine_parameter() 02541 { 02542 return this; 02543 } 02544 02545 virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it); 02546 02547 virtual void set_out_param_info(Send_field *info); 02548 02549 public: 02550 virtual const Send_field *get_out_param_info() const; 02551 02552 virtual void make_field(Send_field *field); 02553 02554 private: 02555 Send_field *m_out_param_info; 02556 }; 02557 02558 02559 class Item_int :public Item_num 02560 { 02561 public: 02562 longlong value; 02563 Item_int(int32 i,uint length= MY_INT32_NUM_DECIMAL_DIGITS) 02564 :value((longlong) i) 02565 { max_length=length; fixed= 1; } 02566 Item_int(longlong i,uint length= MY_INT64_NUM_DECIMAL_DIGITS) 02567 :value(i) 02568 { max_length=length; fixed= 1; } 02569 Item_int(ulonglong i, uint length= MY_INT64_NUM_DECIMAL_DIGITS) 02570 :value((longlong)i) 02571 { max_length=length; fixed= 1; unsigned_flag= 1; } 02572 Item_int(Item_int *item_arg) 02573 { 02574 value= item_arg->value; 02575 item_name= item_arg->item_name; 02576 max_length= item_arg->max_length; 02577 fixed= 1; 02578 } 02579 Item_int(const Name_string &name_arg, longlong i, uint length) :value(i) 02580 { 02581 max_length= length; 02582 item_name= name_arg; 02583 fixed= 1; 02584 } 02585 Item_int(const char *str_arg, uint length); 02586 enum Type type() const { return INT_ITEM; } 02587 enum Item_result result_type () const { return INT_RESULT; } 02588 enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; } 02589 longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } 02590 double val_real() { DBUG_ASSERT(fixed == 1); return (double) value; } 02591 my_decimal *val_decimal(my_decimal *); 02592 String *val_str(String*); 02593 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02594 { 02595 return get_date_from_int(ltime, fuzzydate); 02596 } 02597 bool get_time(MYSQL_TIME *ltime) 02598 { 02599 return get_time_from_int(ltime); 02600 } 02601 type_conversion_status save_in_field(Field *field, bool no_conversions); 02602 bool basic_const_item() const { return 1; } 02603 Item *clone_item() { return new Item_int(this); } 02604 virtual void print(String *str, enum_query_type query_type); 02605 Item_num *neg() { value= -value; return this; } 02606 uint decimal_precision() const 02607 { return (uint)(max_length - MY_TEST(value < 0)); } 02608 bool eq(const Item *, bool binary_cmp) const; 02609 bool check_partition_func_processor(uchar *bool_arg) { return FALSE;} 02610 }; 02611 02612 02616 class Item_int_0 :public Item_int 02617 { 02618 public: 02619 Item_int_0() :Item_int(NAME_STRING("0"), 0, 1) {} 02620 }; 02621 02622 02623 /* 02624 Item_temporal is used to store numeric representation 02625 of time/date/datetime values for queries like: 02626 02627 WHERE datetime_column NOT IN 02628 ('2006-04-25 10:00:00','2006-04-25 10:02:00', ...); 02629 02630 and for SHOW/INFORMATION_SCHEMA purposes (see sql_show.cc) 02631 02632 TS-TODO: Can't we use Item_time_literal, Item_date_literal, 02633 TS-TODO: and Item_datetime_literal for this purpose? 02634 */ 02635 class Item_temporal :public Item_int 02636 { 02637 enum_field_types cached_field_type; 02638 public: 02639 Item_temporal(enum_field_types field_type_arg, longlong i): Item_int(i), 02640 cached_field_type(field_type_arg) 02641 { 02642 DBUG_ASSERT(is_temporal_type(field_type_arg)); 02643 } 02644 Item_temporal(enum_field_types field_type_arg, const Name_string &name_arg, 02645 longlong i, uint length): Item_int(i), 02646 cached_field_type(field_type_arg) 02647 { 02648 DBUG_ASSERT(is_temporal_type(field_type_arg)); 02649 max_length= length; 02650 item_name= name_arg; 02651 fixed= 1; 02652 } 02653 Item *clone_item() { return new Item_temporal(field_type(), value); } 02654 type_conversion_status save_in_field(Field *field, bool no_conversions); 02655 longlong val_time_temporal() { return val_int(); } 02656 longlong val_date_temporal() { return val_int(); } 02657 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02658 { 02659 DBUG_ASSERT(0); 02660 return false; 02661 } 02662 bool get_time(MYSQL_TIME *ltime) 02663 { 02664 DBUG_ASSERT(0); 02665 return false; 02666 } 02667 enum_field_types field_type() const 02668 { 02669 return cached_field_type; 02670 } 02671 }; 02672 02673 02674 class Item_uint :public Item_int 02675 { 02676 public: 02677 Item_uint(const char *str_arg, uint length) 02678 :Item_int(str_arg, length) { unsigned_flag= 1; } 02679 Item_uint(ulonglong i) :Item_int((ulonglong) i, 10) {} 02680 Item_uint(const Name_string &name_arg, longlong i, uint length) 02681 :Item_int(name_arg, i, length) { unsigned_flag= 1; } 02682 double val_real() 02683 { DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); } 02684 String *val_str(String*); 02685 02686 Item *clone_item() { return new Item_uint(item_name, value, max_length); } 02687 type_conversion_status save_in_field(Field *field, bool no_conversions); 02688 virtual void print(String *str, enum_query_type query_type); 02689 Item_num *neg (); 02690 uint decimal_precision() const { return max_length; } 02691 bool check_partition_func_processor(uchar *bool_arg) { return FALSE;} 02692 }; 02693 02694 02695 /* decimal (fixed point) constant */ 02696 class Item_decimal :public Item_num 02697 { 02698 protected: 02699 my_decimal decimal_value; 02700 public: 02701 Item_decimal(const char *str_arg, uint length, const CHARSET_INFO *charset); 02702 Item_decimal(const Name_string &name_arg, 02703 const my_decimal *val_arg, uint decimal_par, uint length); 02704 Item_decimal(my_decimal *value_par); 02705 Item_decimal(longlong val, bool unsig); 02706 Item_decimal(double val, int precision, int scale); 02707 Item_decimal(const uchar *bin, int precision, int scale); 02708 02709 enum Type type() const { return DECIMAL_ITEM; } 02710 enum Item_result result_type () const { return DECIMAL_RESULT; } 02711 enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } 02712 longlong val_int(); 02713 double val_real(); 02714 String *val_str(String*); 02715 my_decimal *val_decimal(my_decimal *val) { return &decimal_value; } 02716 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02717 { 02718 return get_date_from_decimal(ltime, fuzzydate); 02719 } 02720 bool get_time(MYSQL_TIME *ltime) 02721 { 02722 return get_time_from_decimal(ltime); 02723 } 02724 type_conversion_status save_in_field(Field *field, bool no_conversions); 02725 bool basic_const_item() const { return 1; } 02726 Item *clone_item() 02727 { 02728 return new Item_decimal(item_name, &decimal_value, decimals, max_length); 02729 } 02730 virtual void print(String *str, enum_query_type query_type); 02731 Item_num *neg() 02732 { 02733 my_decimal_neg(&decimal_value); 02734 unsigned_flag= !decimal_value.sign(); 02735 return this; 02736 } 02737 uint decimal_precision() const { return decimal_value.precision(); } 02738 bool eq(const Item *, bool binary_cmp) const; 02739 void set_decimal_value(my_decimal *value_par); 02740 bool check_partition_func_processor(uchar *bool_arg) { return FALSE;} 02741 }; 02742 02743 02744 class Item_float :public Item_num 02745 { 02746 Name_string presentation; 02747 public: 02748 double value; 02749 // Item_real() :value(0) {} 02750 Item_float(const char *str_arg, uint length); 02751 Item_float(const Name_string name_arg, 02752 double val_arg, uint decimal_par, uint length) 02753 :value(val_arg) 02754 { 02755 presentation= name_arg; 02756 item_name= name_arg; 02757 decimals= (uint8) decimal_par; 02758 max_length= length; 02759 fixed= 1; 02760 } 02761 Item_float(double value_par, uint decimal_par) :value(value_par) 02762 { 02763 decimals= (uint8) decimal_par; 02764 fixed= 1; 02765 } 02766 type_conversion_status save_in_field(Field *field, bool no_conversions); 02767 enum Type type() const { return REAL_ITEM; } 02768 enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; } 02769 double val_real() { DBUG_ASSERT(fixed == 1); return value; } 02770 longlong val_int() 02771 { 02772 DBUG_ASSERT(fixed == 1); 02773 if (value <= (double) LONGLONG_MIN) 02774 { 02775 return LONGLONG_MIN; 02776 } 02777 else if (value >= (double) (ulonglong) LONGLONG_MAX) 02778 { 02779 return LONGLONG_MAX; 02780 } 02781 return (longlong) rint(value); 02782 } 02783 String *val_str(String*); 02784 my_decimal *val_decimal(my_decimal *); 02785 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02786 { 02787 return get_date_from_real(ltime, fuzzydate); 02788 } 02789 bool get_time(MYSQL_TIME *ltime) 02790 { 02791 return get_time_from_real(ltime); 02792 } 02793 bool basic_const_item() const { return 1; } 02794 Item *clone_item() 02795 { return new Item_float(item_name, value, decimals, max_length); } 02796 Item_num *neg() { value= -value; return this; } 02797 virtual void print(String *str, enum_query_type query_type); 02798 bool eq(const Item *, bool binary_cmp) const; 02799 }; 02800 02801 02802 class Item_static_float_func :public Item_float 02803 { 02804 const Name_string func_name; 02805 public: 02806 Item_static_float_func(const Name_string &name_arg, 02807 double val_arg, uint decimal_par, uint length) 02808 :Item_float(null_name_string, 02809 val_arg, decimal_par, length), func_name(name_arg) 02810 {} 02811 02812 virtual inline void print(String *str, enum_query_type query_type) 02813 { 02814 str->append(func_name); 02815 } 02816 02817 Item *safe_charset_converter(const CHARSET_INFO *tocs); 02818 }; 02819 02820 02821 class Item_string :public Item_basic_constant 02822 { 02823 public: 02824 /* Create from a string, set name from the string itself. */ 02825 Item_string(const char *str,uint length, 02826 const CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE, 02827 uint repertoire= MY_REPERTOIRE_UNICODE30) 02828 : m_cs_specified(FALSE) 02829 { 02830 str_value.set_or_copy_aligned(str, length, cs); 02831 collation.set(cs, dv, repertoire); 02832 /* 02833 We have to have a different max_length than 'length' here to 02834 ensure that we get the right length if we do use the item 02835 to create a new table. In this case max_length must be the maximum 02836 number of chars for a string of this type because we in Create_field:: 02837 divide the max_length with mbmaxlen). 02838 */ 02839 max_length= str_value.numchars()*cs->mbmaxlen; 02840 item_name.copy(str, length, cs); 02841 decimals=NOT_FIXED_DEC; 02842 // it is constant => can be used without fix_fields (and frequently used) 02843 fixed= 1; 02844 } 02845 /* Just create an item and do not fill string representation */ 02846 Item_string(const CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE) 02847 : m_cs_specified(FALSE) 02848 { 02849 collation.set(cs, dv); 02850 max_length= 0; 02851 decimals= NOT_FIXED_DEC; 02852 fixed= 1; 02853 } 02854 /* Create from the given name and string. */ 02855 Item_string(const Name_string name_par, const char *str, uint length, 02856 const CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE, 02857 uint repertoire= MY_REPERTOIRE_UNICODE30) 02858 : m_cs_specified(FALSE) 02859 { 02860 str_value.set_or_copy_aligned(str, length, cs); 02861 collation.set(cs, dv, repertoire); 02862 max_length= str_value.numchars()*cs->mbmaxlen; 02863 item_name= name_par; 02864 decimals=NOT_FIXED_DEC; 02865 // it is constant => can be used without fix_fields (and frequently used) 02866 fixed= 1; 02867 } 02868 /* 02869 This is used in stored procedures to avoid memory leaks and 02870 does a deep copy of its argument. 02871 */ 02872 void set_str_with_copy(const char *str_arg, uint length_arg) 02873 { 02874 str_value.copy(str_arg, length_arg, collation.collation); 02875 max_length= str_value.numchars() * collation.collation->mbmaxlen; 02876 } 02877 void set_repertoire_from_value() 02878 { 02879 collation.repertoire= my_string_repertoire(str_value.charset(), 02880 str_value.ptr(), 02881 str_value.length()); 02882 } 02883 enum Type type() const { return STRING_ITEM; } 02884 double val_real(); 02885 longlong val_int(); 02886 String *val_str(String*) 02887 { 02888 DBUG_ASSERT(fixed == 1); 02889 return (String*) &str_value; 02890 } 02891 my_decimal *val_decimal(my_decimal *); 02892 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 02893 { 02894 return get_date_from_string(ltime, fuzzydate); 02895 } 02896 bool get_time(MYSQL_TIME *ltime) 02897 { 02898 return get_time_from_string(ltime); 02899 } 02900 type_conversion_status save_in_field(Field *field, bool no_conversions); 02901 enum Item_result result_type () const { return STRING_RESULT; } 02902 enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } 02903 bool basic_const_item() const { return 1; } 02904 bool eq(const Item *item, bool binary_cmp) const; 02905 Item *clone_item() 02906 { 02907 return new Item_string(static_cast<Name_string>(item_name), str_value.ptr(), 02908 str_value.length(), collation.collation); 02909 } 02910 Item *safe_charset_converter(const CHARSET_INFO *tocs); 02911 Item *charset_converter(const CHARSET_INFO *tocs, bool lossless); 02912 inline void append(char *str, uint length) 02913 { 02914 str_value.append(str, length); 02915 max_length= str_value.numchars() * collation.collation->mbmaxlen; 02916 } 02917 virtual void print(String *str, enum_query_type query_type); 02918 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 02919 02939 inline bool is_cs_specified() const 02940 { 02941 return m_cs_specified; 02942 } 02943 02954 inline void set_cs_specified(bool cs_specified) 02955 { 02956 m_cs_specified= cs_specified; 02957 } 02958 02959 private: 02960 bool m_cs_specified; 02961 }; 02962 02963 02964 longlong 02965 longlong_from_string_with_check (const CHARSET_INFO *cs, 02966 const char *cptr, char *end); 02967 double 02968 double_from_string_with_check (const CHARSET_INFO *cs, 02969 const char *cptr, char *end); 02970 02971 class Item_static_string_func :public Item_string 02972 { 02973 const Name_string func_name; 02974 public: 02975 Item_static_string_func(const Name_string &name_par, 02976 const char *str, uint length, const CHARSET_INFO *cs, 02977 Derivation dv= DERIVATION_COERCIBLE) 02978 :Item_string(null_name_string, str, length, cs, dv), func_name(name_par) 02979 {} 02980 Item *safe_charset_converter(const CHARSET_INFO *tocs); 02981 02982 virtual inline void print(String *str, enum_query_type query_type) 02983 { 02984 str->append(func_name); 02985 } 02986 02987 bool check_partition_func_processor(uchar *int_arg) {return TRUE;} 02988 }; 02989 02990 02991 /* for show tables */ 02992 class Item_partition_func_safe_string: public Item_string 02993 { 02994 public: 02995 Item_partition_func_safe_string(const Name_string name, uint length, 02996 const CHARSET_INFO *cs= NULL): 02997 Item_string(name, NullS, 0, cs) 02998 { 02999 max_length= length; 03000 } 03001 }; 03002 03003 03004 class Item_blob :public Item_partition_func_safe_string 03005 { 03006 public: 03007 Item_blob(const char *name, uint length) : 03008 Item_partition_func_safe_string(Name_string(name, strlen(name)), 03009 length, &my_charset_bin) 03010 { } 03011 enum Type type() const { return TYPE_HOLDER; } 03012 enum_field_types field_type() const { return MYSQL_TYPE_BLOB; } 03013 }; 03014 03015 03022 class Item_empty_string :public Item_partition_func_safe_string 03023 { 03024 public: 03025 Item_empty_string(const char *header, uint length, 03026 const CHARSET_INFO *cs= NULL) : 03027 Item_partition_func_safe_string(Name_string(header, strlen(header)), 03028 0, cs ? cs : &my_charset_utf8_general_ci) 03029 { 03030 max_length= length * collation.collation->mbmaxlen; 03031 } 03032 void make_field(Send_field *field); 03033 }; 03034 03035 03036 class Item_return_int :public Item_int 03037 { 03038 enum_field_types int_field_type; 03039 public: 03040 Item_return_int(const char *name_arg, uint length, 03041 enum_field_types field_type_arg, longlong value= 0) 03042 :Item_int(Name_string(name_arg, name_arg ? strlen(name_arg) : 0), 03043 value, length), int_field_type(field_type_arg) 03044 { 03045 unsigned_flag=1; 03046 } 03047 enum_field_types field_type() const { return int_field_type; } 03048 }; 03049 03050 03051 class Item_hex_string: public Item_basic_constant 03052 { 03053 public: 03054 Item_hex_string(); 03055 Item_hex_string(const char *str,uint str_length); 03056 enum Type type() const { return VARBIN_ITEM; } 03057 double val_real() 03058 { 03059 DBUG_ASSERT(fixed == 1); 03060 return (double) (ulonglong) Item_hex_string::val_int(); 03061 } 03062 longlong val_int(); 03063 bool basic_const_item() const { return 1; } 03064 String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; } 03065 my_decimal *val_decimal(my_decimal *); 03066 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 03067 { 03068 return get_date_from_string(ltime, fuzzydate); 03069 } 03070 bool get_time(MYSQL_TIME *ltime) 03071 { 03072 return get_time_from_string(ltime); 03073 } 03074 type_conversion_status save_in_field(Field *field, bool no_conversions); 03075 enum Item_result result_type () const { return STRING_RESULT; } 03076 enum Item_result cast_to_int_type() const { return INT_RESULT; } 03077 enum_field_types field_type() const { return MYSQL_TYPE_VARCHAR; } 03078 virtual void print(String *str, enum_query_type query_type); 03079 bool eq(const Item *item, bool binary_cmp) const; 03080 virtual Item *safe_charset_converter(const CHARSET_INFO *tocs); 03081 bool check_partition_func_processor(uchar *int_arg) {return FALSE;} 03082 private: 03083 void hex_string_init(const char *str, uint str_length); 03084 }; 03085 03086 03087 class Item_bin_string: public Item_hex_string 03088 { 03089 public: 03090 Item_bin_string(const char *str,uint str_length); 03091 }; 03092 03093 class Item_result_field :public Item /* Item with result field */ 03094 { 03095 public: 03096 Field *result_field; /* Save result here */ 03097 Item_result_field() :result_field(0) {} 03098 // Constructor used for Item_sum/Item_cond_and/or (see Item comment) 03099 Item_result_field(THD *thd, Item_result_field *item): 03100 Item(thd, item), result_field(item->result_field) 03101 {} 03102 ~Item_result_field() {} /* Required with gcc 2.95 */ 03103 Field *get_tmp_table_field() { return result_field; } 03104 Field *tmp_table_field(TABLE *t_arg) { return result_field; } 03105 table_map used_tables() const { return 1; } 03106 virtual void fix_length_and_dec()=0; 03107 void set_result_field(Field *field) { result_field= field; } 03108 bool is_result_field() { return 1; } 03109 void save_in_result_field(bool no_conversions) 03110 { 03111 save_in_field(result_field, no_conversions); 03112 } 03113 void cleanup(); 03114 /* 03115 This method is used for debug purposes to print the name of an 03116 item to the debug log. The second use of this method is as 03117 a helper function of print() and error messages, where it is 03118 applicable. To suit both goals it should return a meaningful, 03119 distinguishable and sintactically correct string. This method 03120 should not be used for runtime type identification, use enum 03121 {Sum}Functype and Item_func::functype()/Item_sum::sum_func() 03122 instead. 03123 Added here, to the parent class of both Item_func and Item_sum_func. 03124 03125 NOTE: for Items inherited from Item_sum, func_name() return part of 03126 function name till first argument (including '(') to make difference in 03127 names for functions with 'distinct' clause and without 'distinct' and 03128 also to make printing of items inherited from Item_sum uniform. 03129 */ 03130 virtual const char *func_name() const= 0; 03131 }; 03132 03133 03134 class Item_ref :public Item_ident 03135 { 03136 protected: 03137 void set_properties(); 03138 public: 03139 enum Ref_Type { REF, DIRECT_REF, VIEW_REF, OUTER_REF, AGGREGATE_REF }; 03140 Field *result_field; /* Save result here */ 03141 Item **ref; 03142 Item_ref(Name_resolution_context *context_arg, 03143 const char *db_arg, const char *table_name_arg, 03144 const char *field_name_arg) 03145 :Item_ident(context_arg, db_arg, table_name_arg, field_name_arg), 03146 result_field(0), ref(0) {} 03147 /* 03148 This constructor is used in two scenarios: 03149 A) *item = NULL 03150 No initialization is performed, fix_fields() call will be necessary. 03151 03152 B) *item points to an Item this Item_ref will refer to. This is 03153 used for GROUP BY. fix_fields() will not be called in this case, 03154 so we call set_properties to make this item "fixed". set_properties 03155 performs a subset of action Item_ref::fix_fields does, and this subset 03156 is enough for Item_ref's used in GROUP BY. 03157 03158 TODO we probably fix a superset of problems like in BUG#6658. Check this 03159 with Bar, and if we have a more broader set of problems like this. 03160 */ 03161 Item_ref(Name_resolution_context *context_arg, Item **item, 03162 const char *table_name_arg, const char *field_name_arg, 03163 bool alias_name_used_arg= FALSE); 03164 03165 /* Constructor need to process subselect with temporary tables (see Item) */ 03166 Item_ref(THD *thd, Item_ref *item) 03167 :Item_ident(thd, item), result_field(item->result_field), ref(item->ref) {} 03168 enum Type type() const { return REF_ITEM; } 03169 bool eq(const Item *item, bool binary_cmp) const 03170 { 03171 Item *it= ((Item *) item)->real_item(); 03172 return ref && (*ref)->eq(it, binary_cmp); 03173 } 03174 double val_real(); 03175 longlong val_int(); 03176 longlong val_time_temporal(); 03177 longlong val_date_temporal(); 03178 my_decimal *val_decimal(my_decimal *); 03179 bool val_bool(); 03180 String *val_str(String* tmp); 03181 bool is_null(); 03182 bool get_date(MYSQL_TIME *ltime,uint fuzzydate); 03183 double val_result(); 03184 longlong val_int_result(); 03185 String *str_result(String* tmp); 03186 my_decimal *val_decimal_result(my_decimal *); 03187 bool val_bool_result(); 03188 bool is_null_result(); 03189 bool send(Protocol *prot, String *tmp); 03190 void make_field(Send_field *field); 03191 bool fix_fields(THD *, Item **); 03192 void fix_after_pullout(st_select_lex *parent_select, 03193 st_select_lex *removed_select); 03194 type_conversion_status save_in_field(Field *field, bool no_conversions); 03195 void save_org_in_field(Field *field); 03196 enum Item_result result_type () const { return (*ref)->result_type(); } 03197 enum_field_types field_type() const { return (*ref)->field_type(); } 03198 Field *get_tmp_table_field() 03199 { return result_field ? result_field : (*ref)->get_tmp_table_field(); } 03200 Item *get_tmp_table_item(THD *thd); 03201 bool const_item() const 03202 { 03203 return (*ref)->const_item() && (used_tables() == 0); 03204 } 03205 table_map used_tables() const 03206 { 03207 return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->used_tables(); 03208 } 03209 void update_used_tables() 03210 { 03211 if (!depended_from) 03212 (*ref)->update_used_tables(); 03213 } 03214 03215 virtual table_map resolved_used_tables() const 03216 { return (*ref)->resolved_used_tables(); } 03217 03218 table_map not_null_tables() const 03219 { 03220 /* 03221 It can happen that our 'depended_from' member is set but the 03222 'depended_from' member of the referenced item is not (example: if a 03223 field in a subquery belongs to an outer merged view), so we first test 03224 ours: 03225 */ 03226 return depended_from ? OUTER_REF_TABLE_BIT : (*ref)->not_null_tables(); 03227 } 03228 void set_result_field(Field *field) { result_field= field; } 03229 bool is_result_field() { return 1; } 03230 void save_in_result_field(bool no_conversions) 03231 { 03232 (*ref)->save_in_field(result_field, no_conversions); 03233 } 03234 Item *real_item() 03235 { 03236 return ref ? (*ref)->real_item() : this; 03237 } 03238 bool walk(Item_processor processor, bool walk_subquery, uchar *arg) 03239 { 03240 return (*ref)->walk(processor, walk_subquery, arg) || 03241 (this->*processor)(arg); 03242 } 03243 virtual Item* transform(Item_transformer, uchar *arg); 03244 virtual Item* compile(Item_analyzer analyzer, uchar **arg_p, 03245 Item_transformer transformer, uchar *arg_t); 03246 virtual bool explain_subquery_checker(uchar **arg) 03247 { 03248 /* 03249 Always return false: we don't need to go deeper into referenced 03250 expression tree since we have to mark aliased subqueries at 03251 their original places (select list, derived tables), not by 03252 references from other expression (order by etc). 03253 */ 03254 return false; 03255 } 03256 virtual void print(String *str, enum_query_type query_type); 03257 void cleanup(); 03258 Item_field *field_for_view_update() 03259 { return (*ref)->field_for_view_update(); } 03260 virtual Ref_Type ref_type() { return REF; } 03261 03262 // Row emulation: forwarding of ROW-related calls to ref 03263 uint cols() 03264 { 03265 return ref && result_type() == ROW_RESULT ? (*ref)->cols() : 1; 03266 } 03267 Item* element_index(uint i) 03268 { 03269 return ref && result_type() == ROW_RESULT ? (*ref)->element_index(i) : this; 03270 } 03271 Item** addr(uint i) 03272 { 03273 return ref && result_type() == ROW_RESULT ? (*ref)->addr(i) : 0; 03274 } 03275 bool check_cols(uint c) 03276 { 03277 return ref && result_type() == ROW_RESULT ? (*ref)->check_cols(c) 03278 : Item::check_cols(c); 03279 } 03280 bool null_inside() 03281 { 03282 return ref && result_type() == ROW_RESULT ? (*ref)->null_inside() : 0; 03283 } 03284 void bring_value() 03285 { 03286 if (ref && result_type() == ROW_RESULT) 03287 (*ref)->bring_value(); 03288 } 03289 bool get_time(MYSQL_TIME *ltime) 03290 { 03291 DBUG_ASSERT(fixed); 03292 return (*ref)->get_time(ltime); 03293 } 03294 virtual bool basic_const_item() const { return ref && (*ref)->basic_const_item(); } 03295 bool is_outer_field() const 03296 { 03297 DBUG_ASSERT(fixed); 03298 DBUG_ASSERT(ref); 03299 return (*ref)->is_outer_field(); 03300 } 03301 03305 virtual bool has_subquery() const 03306 { 03307 DBUG_ASSERT(ref); 03308 return (*ref)->has_subquery(); 03309 } 03310 03314 virtual bool has_stored_program() const 03315 { 03316 DBUG_ASSERT(ref); 03317 return (*ref)->has_stored_program(); 03318 } 03319 03320 virtual bool created_by_in2exists() const 03321 { 03322 return (*ref)->created_by_in2exists(); 03323 } 03324 }; 03325 03326 03327 /* 03328 The same as Item_ref, but get value from val_* family of method to get 03329 value of item on which it referred instead of result* family. 03330 */ 03331 class Item_direct_ref :public Item_ref 03332 { 03333 public: 03334 Item_direct_ref(Name_resolution_context *context_arg, Item **item, 03335 const char *table_name_arg, 03336 const char *field_name_arg, 03337 bool alias_name_used_arg= FALSE) 03338 :Item_ref(context_arg, item, table_name_arg, 03339 field_name_arg, alias_name_used_arg) 03340 {} 03341 /* Constructor need to process subselect with temporary tables (see Item) */ 03342 Item_direct_ref(THD *thd, Item_direct_ref *item) : Item_ref(thd, item) {} 03343 03344 double val_real(); 03345 longlong val_int(); 03346 longlong val_time_temporal(); 03347 longlong val_date_temporal(); 03348 String *val_str(String* tmp); 03349 my_decimal *val_decimal(my_decimal *); 03350 bool val_bool(); 03351 bool is_null(); 03352 bool get_date(MYSQL_TIME *ltime,uint fuzzydate); 03353 virtual Ref_Type ref_type() { return DIRECT_REF; } 03354 }; 03355 03356 /* 03357 Class for view fields, the same as Item_direct_ref, but call fix_fields 03358 of reference if it is not called yet 03359 */ 03360 class Item_direct_view_ref :public Item_direct_ref 03361 { 03362 public: 03363 Item_direct_view_ref(Name_resolution_context *context_arg, 03364 Item **item, 03365 const char *alias_name_arg, 03366 const char *table_name_arg, 03367 const char *field_name_arg) 03368 : Item_direct_ref(context_arg, item, alias_name_arg, field_name_arg) 03369 { 03370 orig_table_name= table_name_arg; 03371 } 03372 03373 /* Constructor need to process subselect with temporary tables (see Item) */ 03374 Item_direct_view_ref(THD *thd, Item_direct_ref *item) 03375 :Item_direct_ref(thd, item) {} 03376 03377 /* 03378 We share one underlying Item_field, so we have to disable 03379 build_equal_items_for_cond(). 03380 TODO: Implement multiple equality optimization for views. 03381 */ 03382 virtual bool subst_argument_checker(uchar **arg) 03383 { 03384 return false; 03385 } 03386 03387 bool fix_fields(THD *, Item **); 03388 bool eq(const Item *item, bool binary_cmp) const; 03389 Item *get_tmp_table_item(THD *thd) 03390 { 03391 Item *item= Item_ref::get_tmp_table_item(thd); 03392 item->item_name= item_name; 03393 return item; 03394 } 03395 virtual Ref_Type ref_type() { return VIEW_REF; } 03396 }; 03397 03398 03399 /* 03400 Class for outer fields. 03401 An object of this class is created when the select where the outer field was 03402 resolved is a grouping one. After it has been fixed the ref field will point 03403 to either an Item_ref or an Item_direct_ref object which will be used to 03404 access the field. 03405 The ref field may also point to an Item_field instance. 03406 See also comments for the fix_inner_refs() and the 03407 Item_field::fix_outer_field() functions. 03408 */ 03409 03410 class Item_sum; 03411 class Item_outer_ref :public Item_direct_ref 03412 { 03413 public: 03414 Item *outer_ref; 03415 /* The aggregate function under which this outer ref is used, if any. */ 03416 Item_sum *in_sum_func; 03417 /* 03418 TRUE <=> that the outer_ref is already present in the select list 03419 of the outer select. 03420 */ 03421 bool found_in_select_list; 03422 Item_outer_ref(Name_resolution_context *context_arg, 03423 Item_field *outer_field_arg) 03424 :Item_direct_ref(context_arg, 0, outer_field_arg->table_name, 03425 outer_field_arg->field_name), 03426 outer_ref(outer_field_arg), in_sum_func(0), 03427 found_in_select_list(0) 03428 { 03429 ref= &outer_ref; 03430 set_properties(); 03431 fixed= 0; 03432 } 03433 Item_outer_ref(Name_resolution_context *context_arg, Item **item, 03434 const char *table_name_arg, const char *field_name_arg, 03435 bool alias_name_used_arg) 03436 :Item_direct_ref(context_arg, item, table_name_arg, field_name_arg, 03437 alias_name_used_arg), 03438 outer_ref(0), in_sum_func(0), found_in_select_list(1) 03439 {} 03440 void save_in_result_field(bool no_conversions) 03441 { 03442 outer_ref->save_org_in_field(result_field); 03443 } 03444 bool fix_fields(THD *, Item **); 03445 void fix_after_pullout(st_select_lex *parent_select, 03446 st_select_lex *removed_select); 03447 table_map used_tables() const 03448 { 03449 return (*ref)->const_item() ? 0 : OUTER_REF_TABLE_BIT; 03450 } 03451 table_map not_null_tables() const { return 0; } 03452 03453 virtual Ref_Type ref_type() { return OUTER_REF; } 03454 }; 03455 03456 03457 class Item_in_subselect; 03458 03459 03460 /* 03461 An object of this class: 03462 - Converts val_XXX() calls to ref->val_XXX_result() calls, like Item_ref. 03463 - Sets owner->was_null=TRUE if it has returned a NULL value from any 03464 val_XXX() function. This allows to inject an Item_ref_null_helper 03465 object into subquery and then check if the subquery has produced a row 03466 with NULL value. 03467 */ 03468 03469 class Item_ref_null_helper: public Item_ref 03470 { 03471 protected: 03472 Item_in_subselect* owner; 03473 public: 03474 Item_ref_null_helper(Name_resolution_context *context_arg, 03475 Item_in_subselect* master, Item **item, 03476 const char *table_name_arg, const char *field_name_arg) 03477 :Item_ref(context_arg, item, table_name_arg, field_name_arg), 03478 owner(master) {} 03479 double val_real(); 03480 longlong val_int(); 03481 longlong val_time_temporal(); 03482 longlong val_date_temporal(); 03483 String* val_str(String* s); 03484 my_decimal *val_decimal(my_decimal *); 03485 bool val_bool(); 03486 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 03487 virtual void print(String *str, enum_query_type query_type); 03488 /* 03489 we add RAND_TABLE_BIT to prevent moving this item from HAVING to WHERE 03490 */ 03491 table_map used_tables() const 03492 { 03493 return (depended_from ? 03494 OUTER_REF_TABLE_BIT : 03495 (*ref)->used_tables() | RAND_TABLE_BIT); 03496 } 03497 }; 03498 03499 /* 03500 The following class is used to optimize comparing of bigint columns. 03501 We need to save the original item ('ref') to be able to call 03502 ref->save_in_field(). This is used to create index search keys. 03503 03504 An instance of Item_int_with_ref may have signed or unsigned integer value. 03505 03506 */ 03507 03508 class Item_int_with_ref :public Item_int 03509 { 03510 protected: 03511 Item *ref; 03512 public: 03513 Item_int_with_ref(longlong i, Item *ref_arg, my_bool unsigned_arg) : 03514 Item_int(i), ref(ref_arg) 03515 { 03516 unsigned_flag= unsigned_arg; 03517 } 03518 type_conversion_status save_in_field(Field *field, bool no_conversions) 03519 { 03520 return ref->save_in_field(field, no_conversions); 03521 } 03522 Item *clone_item(); 03523 virtual Item *real_item() { return ref; } 03524 }; 03525 03526 03527 /* 03528 Similar to Item_int_with_ref, but to optimize comparing of temporal columns. 03529 */ 03530 class Item_temporal_with_ref :public Item_int_with_ref 03531 { 03532 private: 03533 enum_field_types cached_field_type; 03534 public: 03535 Item_temporal_with_ref(enum_field_types field_type_arg, 03536 uint8 decimals_arg, longlong i, Item *ref_arg, 03537 bool unsigned_flag): 03538 Item_int_with_ref(i, ref_arg, unsigned_flag), 03539 cached_field_type(field_type_arg) 03540 { 03541 decimals= decimals_arg; 03542 } 03543 enum_field_types field_type() const { return cached_field_type; } 03544 void print(String *str, enum_query_type query_type); 03545 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 03546 { 03547 DBUG_ASSERT(0); 03548 return true; 03549 } 03550 bool get_time(MYSQL_TIME *ltime) 03551 { 03552 DBUG_ASSERT(0); 03553 return true; 03554 } 03555 03556 }; 03557 03558 03559 /* 03560 Item_datetime_with_ref is used to optimize queries like: 03561 SELECT ... FROM t1 WHERE date_or_datetime_column = 20110101101010; 03562 The numeric constant is replaced to Item_datetime_with_ref 03563 by convert_constant_item(). 03564 */ 03565 class Item_datetime_with_ref :public Item_temporal_with_ref 03566 { 03567 private: 03568 enum_field_types cached_field_type; 03569 public: 03577 Item_datetime_with_ref(enum_field_types field_type_arg, 03578 uint8 decimals_arg, longlong i, Item *ref_arg): 03579 Item_temporal_with_ref(field_type_arg, decimals_arg, i, ref_arg, true), 03580 cached_field_type(field_type_arg) 03581 { 03582 } 03583 Item *clone_item(); 03584 longlong val_date_temporal() { return val_int(); } 03585 longlong val_time_temporal() 03586 { 03587 DBUG_ASSERT(0); 03588 return val_int(); 03589 } 03590 }; 03591 03592 03593 /* 03594 Item_time_with_ref is used to optimize queries like: 03595 SELECT ... FROM t1 WHERE time_column = 20110101101010; 03596 The numeric constant is replaced to Item_time_with_ref 03597 by convert_constant_item(). 03598 */ 03599 class Item_time_with_ref :public Item_temporal_with_ref 03600 { 03601 public: 03608 Item_time_with_ref(uint8 decimals_arg, longlong i, Item *ref_arg): 03609 Item_temporal_with_ref(MYSQL_TYPE_TIME, decimals_arg, i, ref_arg, 0) 03610 { 03611 } 03612 Item *clone_item(); 03613 longlong val_time_temporal() { return val_int(); } 03614 longlong val_date_temporal() 03615 { 03616 DBUG_ASSERT(0); 03617 return val_int(); 03618 } 03619 }; 03620 03621 03622 #ifdef MYSQL_SERVER 03623 #include "gstream.h" 03624 #include "spatial.h" 03625 #include "item_sum.h" 03626 #include "item_func.h" 03627 #include "item_row.h" 03628 #include "item_cmpfunc.h" 03629 #include "item_strfunc.h" 03630 #include "item_geofunc.h" 03631 #include "item_timefunc.h" 03632 #include "item_subselect.h" 03633 #include "item_xmlfunc.h" 03634 #include "item_create.h" 03635 #endif 03636 03657 class Item_copy :public Item 03658 { 03659 protected: 03660 03665 enum enum_field_types cached_field_type; 03666 03668 Item *item; 03669 03674 Item_result cached_result_type; 03675 03682 Item_copy(Item *i) 03683 { 03684 item= i; 03685 null_value=maybe_null=item->maybe_null; 03686 decimals=item->decimals; 03687 max_length=item->max_length; 03688 item_name= item->item_name; 03689 cached_field_type= item->field_type(); 03690 cached_result_type= item->result_type(); 03691 unsigned_flag= item->unsigned_flag; 03692 fixed= item->fixed; 03693 collation.set(item->collation); 03694 } 03695 03696 public: 03703 static Item_copy *create (Item *item); 03704 03712 virtual void copy() = 0; 03713 03714 Item *get_item() { return item; } 03716 enum Type type() const { return COPY_STR_ITEM; } 03717 enum_field_types field_type() const { return cached_field_type; } 03718 enum Item_result result_type () const { return cached_result_type; } 03719 03720 void make_field(Send_field *field) { item->make_field(field); } 03721 table_map used_tables() const { return (table_map) 1L; } 03722 bool const_item() const { return 0; } 03723 bool is_null() { return null_value; } 03724 03725 virtual void no_rows_in_result() 03726 { 03727 item->no_rows_in_result(); 03728 } 03729 03730 /* 03731 Override the methods below as pure virtual to make sure all the 03732 sub-classes implement them. 03733 */ 03734 03735 virtual String *val_str(String*) = 0; 03736 virtual my_decimal *val_decimal(my_decimal *) = 0; 03737 virtual double val_real() = 0; 03738 virtual longlong val_int() = 0; 03739 virtual bool get_date(MYSQL_TIME *ltime, uint fuzzydate)= 0; 03740 virtual bool get_time(MYSQL_TIME *ltime)= 0; 03741 virtual type_conversion_status save_in_field(Field *field, 03742 bool no_conversions) = 0; 03743 }; 03744 03750 class Item_copy_string : public Item_copy 03751 { 03752 public: 03753 Item_copy_string (Item *item) : Item_copy(item) {} 03754 03755 String *val_str(String*); 03756 my_decimal *val_decimal(my_decimal *); 03757 double val_real(); 03758 longlong val_int(); 03759 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 03760 bool get_time(MYSQL_TIME *ltime); 03761 void copy(); 03762 type_conversion_status save_in_field(Field *field, bool no_conversions); 03763 }; 03764 03765 03766 class Item_copy_int : public Item_copy 03767 { 03768 protected: 03769 longlong cached_value; 03770 public: 03771 Item_copy_int (Item *i) : Item_copy(i) {} 03772 type_conversion_status save_in_field(Field *field, bool no_conversions); 03773 03774 virtual String *val_str(String*); 03775 virtual my_decimal *val_decimal(my_decimal *); 03776 virtual double val_real() 03777 { 03778 return null_value ? 0.0 : (double) cached_value; 03779 } 03780 virtual longlong val_int() 03781 { 03782 return null_value ? LL(0) : cached_value; 03783 } 03784 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 03785 { 03786 return get_date_from_int(ltime, fuzzydate); 03787 } 03788 bool get_time(MYSQL_TIME *ltime) 03789 { 03790 return get_time_from_int(ltime); 03791 } 03792 virtual void copy(); 03793 }; 03794 03795 03796 class Item_copy_uint : public Item_copy_int 03797 { 03798 public: 03799 Item_copy_uint (Item *item) : Item_copy_int(item) 03800 { 03801 unsigned_flag= 1; 03802 } 03803 03804 String *val_str(String*); 03805 double val_real() 03806 { 03807 return null_value ? 0.0 : (double) (ulonglong) cached_value; 03808 } 03809 }; 03810 03811 03812 class Item_copy_float : public Item_copy 03813 { 03814 protected: 03815 double cached_value; 03816 public: 03817 Item_copy_float (Item *i) : Item_copy(i) {} 03818 type_conversion_status save_in_field(Field *field, bool no_conversions); 03819 03820 String *val_str(String*); 03821 my_decimal *val_decimal(my_decimal *); 03822 double val_real() 03823 { 03824 return null_value ? 0.0 : cached_value; 03825 } 03826 longlong val_int() 03827 { 03828 return (longlong) rint(val_real()); 03829 } 03830 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 03831 { 03832 return get_date_from_real(ltime, fuzzydate); 03833 } 03834 bool get_time(MYSQL_TIME *ltime) 03835 { 03836 return get_time_from_real(ltime); 03837 } 03838 void copy() 03839 { 03840 cached_value= item->val_real(); 03841 null_value= item->null_value; 03842 } 03843 }; 03844 03845 03846 class Item_copy_decimal : public Item_copy 03847 { 03848 protected: 03849 my_decimal cached_value; 03850 public: 03851 Item_copy_decimal (Item *i) : Item_copy(i) {} 03852 type_conversion_status save_in_field(Field *field, bool no_conversions); 03853 03854 String *val_str(String*); 03855 my_decimal *val_decimal(my_decimal *) 03856 { 03857 return null_value ? NULL: &cached_value; 03858 } 03859 double val_real(); 03860 longlong val_int(); 03861 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 03862 { 03863 return get_date_from_decimal(ltime, fuzzydate); 03864 } 03865 bool get_time(MYSQL_TIME *ltime) 03866 { 03867 return get_time_from_decimal(ltime); 03868 } 03869 void copy(); 03870 }; 03871 03872 03873 class Cached_item :public Sql_alloc 03874 { 03875 public: 03876 my_bool null_value; 03877 Cached_item() :null_value(0) {} 03878 virtual bool cmp(void)=0; 03879 virtual ~Cached_item(); /*line -e1509 */ 03880 }; 03881 03882 class Cached_item_str :public Cached_item 03883 { 03884 Item *item; 03885 uint32 value_max_length; 03886 String value,tmp_value; 03887 public: 03888 Cached_item_str(THD *thd, Item *arg); 03889 bool cmp(void); 03890 ~Cached_item_str(); // Deallocate String:s 03891 }; 03892 03893 03894 class Cached_item_real :public Cached_item 03895 { 03896 Item *item; 03897 double value; 03898 public: 03899 Cached_item_real(Item *item_par) :item(item_par),value(0.0) {} 03900 bool cmp(void); 03901 }; 03902 03903 class Cached_item_int :public Cached_item 03904 { 03905 Item *item; 03906 longlong value; 03907 public: 03908 Cached_item_int(Item *item_par) :item(item_par),value(0) {} 03909 bool cmp(void); 03910 }; 03911 03912 class Cached_item_temporal :public Cached_item 03913 { 03914 Item *item; 03915 longlong value; 03916 public: 03917 Cached_item_temporal(Item *item_par) :item(item_par), value(0) {} 03918 bool cmp(void); 03919 }; 03920 03921 03922 class Cached_item_decimal :public Cached_item 03923 { 03924 Item *item; 03925 my_decimal value; 03926 public: 03927 Cached_item_decimal(Item *item_par); 03928 bool cmp(void); 03929 }; 03930 03931 class Cached_item_field :public Cached_item 03932 { 03933 uchar *buff; 03934 Field *field; 03935 uint length; 03936 03937 public: 03938 #ifndef DBUG_OFF 03939 void dbug_print() 03940 { 03941 uchar *org_ptr; 03942 org_ptr= field->ptr; 03943 fprintf(DBUG_FILE, "new: "); 03944 field->dbug_print(); 03945 field->ptr= buff; 03946 fprintf(DBUG_FILE, ", old: "); 03947 field->dbug_print(); 03948 field->ptr= org_ptr; 03949 fprintf(DBUG_FILE, "\n"); 03950 } 03951 #endif 03952 Cached_item_field(Field *arg_field) : field(arg_field) 03953 { 03954 field= arg_field; 03955 /* TODO: take the memory allocation below out of the constructor. */ 03956 buff= (uchar*) sql_calloc(length=field->pack_length()); 03957 } 03958 bool cmp(void); 03959 }; 03960 03961 class Item_default_value : public Item_field 03962 { 03963 public: 03964 Item *arg; 03965 Item_default_value(Name_resolution_context *context_arg) 03966 :Item_field(context_arg, (const char *)NULL, (const char *)NULL, 03967 (const char *)NULL), 03968 arg(NULL) {} 03969 Item_default_value(Name_resolution_context *context_arg, Item *a) 03970 :Item_field(context_arg, (const char *)NULL, (const char *)NULL, 03971 (const char *)NULL), 03972 arg(a) {} 03973 enum Type type() const { return DEFAULT_VALUE_ITEM; } 03974 bool eq(const Item *item, bool binary_cmp) const; 03975 bool fix_fields(THD *, Item **); 03976 virtual void print(String *str, enum_query_type query_type); 03977 type_conversion_status save_in_field(Field *field_arg, bool no_conversions); 03978 table_map used_tables() const { return (table_map)0L; } 03979 Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); } 03980 03981 bool walk(Item_processor processor, bool walk_subquery, uchar *args) 03982 { 03983 if (arg && arg->walk(processor, walk_subquery, args)) 03984 return true; 03985 03986 return (this->*processor)(args); 03987 } 03988 03989 Item *transform(Item_transformer transformer, uchar *args); 03990 }; 03991 03992 /* 03993 Item_insert_value -- an implementation of VALUES() function. 03994 You can use the VALUES(col_name) function in the UPDATE clause 03995 to refer to column values from the INSERT portion of the INSERT 03996 ... UPDATE statement. In other words, VALUES(col_name) in the 03997 UPDATE clause refers to the value of col_name that would be 03998 inserted, had no duplicate-key conflict occurred. 03999 In all other places this function returns NULL. 04000 */ 04001 04002 class Item_insert_value : public Item_field 04003 { 04004 public: 04005 Item *arg; 04006 Item_insert_value(Name_resolution_context *context_arg, Item *a) 04007 :Item_field(context_arg, (const char *)NULL, (const char *)NULL, 04008 (const char *)NULL), 04009 arg(a) {} 04010 bool eq(const Item *item, bool binary_cmp) const; 04011 bool fix_fields(THD *, Item **); 04012 virtual void print(String *str, enum_query_type query_type); 04013 type_conversion_status save_in_field(Field *field_arg, bool no_conversions) 04014 { 04015 return Item_field::save_in_field(field_arg, no_conversions); 04016 } 04017 /* 04018 We use RAND_TABLE_BIT to prevent Item_insert_value from 04019 being treated as a constant and precalculated before execution 04020 */ 04021 table_map used_tables() const { return RAND_TABLE_BIT; } 04022 04023 bool walk(Item_processor processor, bool walk_subquery, uchar *args) 04024 { 04025 return arg->walk(processor, walk_subquery, args) || 04026 (this->*processor)(args); 04027 } 04028 }; 04029 04030 04031 class Table_triggers_list; 04032 04033 /* 04034 Represents NEW/OLD version of field of row which is 04035 changed/read in trigger. 04036 04037 Note: For this item main part of actual binding to Field object happens 04038 not during fix_fields() call (like for Item_field) but right after 04039 parsing of trigger definition, when table is opened, with special 04040 setup_field() call. On fix_fields() stage we simply choose one of 04041 two Field instances representing either OLD or NEW version of this 04042 field. 04043 */ 04044 class Item_trigger_field : public Item_field, 04045 private Settable_routine_parameter 04046 { 04047 public: 04048 /* Is this item represents row from NEW or OLD row ? */ 04049 enum row_version_type {OLD_ROW, NEW_ROW}; 04050 row_version_type row_version; 04051 /* Next in list of all Item_trigger_field's in trigger */ 04052 Item_trigger_field *next_trg_field; 04053 /* 04054 Next list of Item_trigger_field's in "sp_head:: 04055 m_list_of_trig_fields_item_lists". 04056 */ 04057 SQL_I_List<Item_trigger_field> *next_trig_field_list; 04058 /* Index of the field in the TABLE::field array */ 04059 uint field_idx; 04060 /* Pointer to Table_trigger_list object for table of this trigger */ 04061 Table_triggers_list *triggers; 04062 04063 Item_trigger_field(Name_resolution_context *context_arg, 04064 row_version_type row_ver_arg, 04065 const char *field_name_arg, 04066 ulong priv, const bool ro) 04067 :Item_field(context_arg, 04068 (const char *)NULL, (const char *)NULL, field_name_arg), 04069 row_version(row_ver_arg), next_trig_field_list(NULL), field_idx((uint)-1), 04070 original_privilege(priv), want_privilege(priv), table_grants(NULL), 04071 read_only (ro) 04072 {} 04073 void setup_field(THD *thd, TABLE *table, GRANT_INFO *table_grant_info); 04074 enum Type type() const { return TRIGGER_FIELD_ITEM; } 04075 bool eq(const Item *item, bool binary_cmp) const; 04076 bool fix_fields(THD *, Item **); 04077 virtual void print(String *str, enum_query_type query_type); 04078 table_map used_tables() const { return (table_map)0L; } 04079 Field *get_tmp_table_field() { return 0; } 04080 Item *copy_or_same(THD *thd) { return this; } 04081 Item *get_tmp_table_item(THD *thd) { return copy_or_same(thd); } 04082 void cleanup(); 04083 04084 private: 04085 void set_required_privilege(bool rw); 04086 bool set_value(THD *thd, sp_rcontext *ctx, Item **it); 04087 04088 public: 04089 Settable_routine_parameter *get_settable_routine_parameter() 04090 { 04091 return (read_only ? 0 : this); 04092 } 04093 04094 bool set_value(THD *thd, Item **it) 04095 { 04096 return set_value(thd, NULL, it); 04097 } 04098 04099 private: 04100 /* 04101 'want_privilege' holds privileges required to perform operation on 04102 this trigger field (SELECT_ACL if we are going to read it and 04103 UPDATE_ACL if we are going to update it). It is initialized at 04104 parse time but can be updated later if this trigger field is used 04105 as OUT or INOUT parameter of stored routine (in this case 04106 set_required_privilege() is called to appropriately update 04107 want_privilege and cleanup() is responsible for restoring of 04108 original want_privilege once parameter's value is updated). 04109 */ 04110 ulong original_privilege; 04111 ulong want_privilege; 04112 GRANT_INFO *table_grants; 04113 /* 04114 Trigger field is read-only unless it belongs to the NEW row in a 04115 BEFORE INSERT of BEFORE UPDATE trigger. 04116 */ 04117 bool read_only; 04118 }; 04119 04120 04121 class Item_cache: public Item_basic_constant 04122 { 04123 protected: 04124 Item *example; 04125 table_map used_table_map; 04131 Field *cached_field; 04132 enum enum_field_types cached_field_type; 04133 /* 04134 TRUE <=> cache holds value of the last stored item (i.e actual value). 04135 store() stores item to be cached and sets this flag to FALSE. 04136 On the first call of val_xxx function if this flag is set to FALSE the 04137 cache_value() will be called to actually cache value of saved item. 04138 cache_value() will set this flag to TRUE. 04139 */ 04140 bool value_cached; 04141 public: 04142 Item_cache(): 04143 example(0), used_table_map(0), cached_field(0), 04144 cached_field_type(MYSQL_TYPE_STRING), 04145 value_cached(0) 04146 { 04147 fixed= 1; 04148 null_value= 1; 04149 } 04150 Item_cache(enum_field_types field_type_arg): 04151 example(0), used_table_map(0), cached_field(0), 04152 cached_field_type(field_type_arg), 04153 value_cached(0) 04154 { 04155 fixed= 1; 04156 null_value= 1; 04157 } 04158 04159 void set_used_tables(table_map map) { used_table_map= map; } 04160 04161 virtual table_map resolved_used_tables() const 04162 { 04163 return example ? example->resolved_used_tables() : used_table_map; 04164 } 04165 04166 virtual bool allocate(uint i) { return 0; } 04167 virtual bool setup(Item *item) 04168 { 04169 example= item; 04170 max_length= item->max_length; 04171 decimals= item->decimals; 04172 collation.set(item->collation); 04173 unsigned_flag= item->unsigned_flag; 04174 if (item->type() == FIELD_ITEM) 04175 { 04176 cached_field= ((Item_field *)item)->field; 04177 if (cached_field->table) 04178 used_table_map= cached_field->table->map; 04179 } 04180 return 0; 04181 }; 04182 enum Type type() const { return CACHE_ITEM; } 04183 enum_field_types field_type() const { return cached_field_type; } 04184 static Item_cache* get_cache(const Item *item); 04185 static Item_cache* get_cache(const Item* item, const Item_result type); 04186 table_map used_tables() const { return used_table_map; } 04187 virtual void keep_array() {} 04188 virtual void print(String *str, enum_query_type query_type); 04189 bool eq_def(Field *field) 04190 { 04191 return cached_field ? cached_field->eq_def (field) : FALSE; 04192 } 04193 bool eq(const Item *item, bool binary_cmp) const 04194 { 04195 return this == item; 04196 } 04202 bool has_value() 04203 { 04204 return (value_cached || cache_value()) && !null_value; 04205 } 04206 04212 Field* field() { return cached_field; } 04213 04214 virtual void store(Item *item); 04215 virtual bool cache_value()= 0; 04216 bool basic_const_item() const 04217 { return MY_TEST(example && example->basic_const_item());} 04218 bool walk (Item_processor processor, bool walk_subquery, uchar *argument); 04219 virtual void clear() { null_value= TRUE; value_cached= FALSE; } 04220 bool is_null() { return value_cached ? null_value : example->is_null(); } 04221 Item_result result_type() const 04222 { 04223 if (!example) 04224 return INT_RESULT; 04225 return Field::result_merge_type(example->field_type()); 04226 } 04227 }; 04228 04229 04230 class Item_cache_int: public Item_cache 04231 { 04232 protected: 04233 longlong value; 04234 public: 04235 Item_cache_int(): Item_cache(), 04236 value(0) {} 04237 Item_cache_int(enum_field_types field_type_arg): 04238 Item_cache(field_type_arg), value(0) {} 04239 04240 virtual void store(Item *item){ Item_cache::store(item); } 04241 void store(Item *item, longlong val_arg); 04242 double val_real(); 04243 longlong val_int(); 04244 longlong val_time_temporal() { return val_int(); } 04245 longlong val_date_temporal() { return val_int(); } 04246 String* val_str(String *str); 04247 my_decimal *val_decimal(my_decimal *); 04248 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 04249 { 04250 return get_date_from_int(ltime, fuzzydate); 04251 } 04252 bool get_time(MYSQL_TIME *ltime) 04253 { 04254 return get_time_from_int(ltime); 04255 } 04256 enum Item_result result_type() const { return INT_RESULT; } 04257 bool cache_value(); 04258 }; 04259 04260 04261 class Item_cache_real: public Item_cache 04262 { 04263 double value; 04264 public: 04265 Item_cache_real(): Item_cache(), 04266 value(0) {} 04267 04268 double val_real(); 04269 longlong val_int(); 04270 String* val_str(String *str); 04271 my_decimal *val_decimal(my_decimal *); 04272 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 04273 { 04274 return get_date_from_real(ltime, fuzzydate); 04275 } 04276 bool get_time(MYSQL_TIME *ltime) 04277 { 04278 return get_time_from_real(ltime); 04279 } 04280 enum Item_result result_type() const { return REAL_RESULT; } 04281 bool cache_value(); 04282 }; 04283 04284 04285 class Item_cache_decimal: public Item_cache 04286 { 04287 protected: 04288 my_decimal decimal_value; 04289 public: 04290 Item_cache_decimal(): Item_cache() {} 04291 04292 double val_real(); 04293 longlong val_int(); 04294 String* val_str(String *str); 04295 my_decimal *val_decimal(my_decimal *); 04296 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 04297 { 04298 return get_date_from_decimal(ltime, fuzzydate); 04299 } 04300 bool get_time(MYSQL_TIME *ltime) 04301 { 04302 return get_time_from_decimal(ltime); 04303 } 04304 enum Item_result result_type() const { return DECIMAL_RESULT; } 04305 bool cache_value(); 04306 }; 04307 04308 04309 class Item_cache_str: public Item_cache 04310 { 04311 char buffer[STRING_BUFFER_USUAL_SIZE]; 04312 String *value, value_buff; 04313 bool is_varbinary; 04314 04315 public: 04316 Item_cache_str(const Item *item) : 04317 Item_cache(item->field_type()), value(0), 04318 is_varbinary(item->type() == FIELD_ITEM && 04319 cached_field_type == MYSQL_TYPE_VARCHAR && 04320 !((const Item_field *) item)->field->has_charset()) 04321 { 04322 collation.set(const_cast<DTCollation&>(item->collation)); 04323 } 04324 double val_real(); 04325 longlong val_int(); 04326 String* val_str(String *); 04327 my_decimal *val_decimal(my_decimal *); 04328 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 04329 { 04330 return get_date_from_string(ltime, fuzzydate); 04331 } 04332 bool get_time(MYSQL_TIME *ltime) 04333 { 04334 return get_time_from_string(ltime); 04335 } 04336 enum Item_result result_type() const { return STRING_RESULT; } 04337 const CHARSET_INFO *charset() const { return value->charset(); }; 04338 type_conversion_status save_in_field(Field *field, bool no_conversions); 04339 bool cache_value(); 04340 }; 04341 04342 class Item_cache_row: public Item_cache 04343 { 04344 Item_cache **values; 04345 uint item_count; 04346 bool save_array; 04347 public: 04348 Item_cache_row() 04349 :Item_cache(), values(0), item_count(2), 04350 save_array(0) {} 04351 04352 /* 04353 'allocate' used only in row transformer, to preallocate space for row 04354 cache. 04355 */ 04356 bool allocate(uint num); 04357 /* 04358 'setup' is needed only by row => it not called by simple row subselect 04359 (only by IN subselect (in subselect optimizer)) 04360 */ 04361 bool setup(Item *item); 04362 void store(Item *item); 04363 void illegal_method_call(const char *); 04364 void make_field(Send_field *) 04365 { 04366 illegal_method_call((const char*)"make_field"); 04367 }; 04368 double val_real() 04369 { 04370 illegal_method_call((const char*)"val"); 04371 return 0; 04372 }; 04373 longlong val_int() 04374 { 04375 illegal_method_call((const char*)"val_int"); 04376 return 0; 04377 }; 04378 String *val_str(String *) 04379 { 04380 illegal_method_call((const char*)"val_str"); 04381 return 0; 04382 }; 04383 my_decimal *val_decimal(my_decimal *val) 04384 { 04385 illegal_method_call((const char*)"val_decimal"); 04386 return 0; 04387 }; 04388 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 04389 { 04390 illegal_method_call((const char *) "get_date"); 04391 return true; 04392 } 04393 bool get_time(MYSQL_TIME *ltime) 04394 { 04395 illegal_method_call((const char *) "get_time"); 04396 return true; 04397 } 04398 04399 enum Item_result result_type() const { return ROW_RESULT; } 04400 04401 uint cols() { return item_count; } 04402 Item *element_index(uint i) { return values[i]; } 04403 Item **addr(uint i) { return (Item **) (values + i); } 04404 bool check_cols(uint c); 04405 bool null_inside(); 04406 void bring_value(); 04407 void keep_array() { save_array= 1; } 04408 void cleanup() 04409 { 04410 DBUG_ENTER("Item_cache_row::cleanup"); 04411 Item_cache::cleanup(); 04412 if (save_array) 04413 memset(values, 0, item_count*sizeof(Item**)); 04414 else 04415 values= 0; 04416 DBUG_VOID_RETURN; 04417 } 04418 bool cache_value(); 04419 }; 04420 04421 04422 class Item_cache_datetime: public Item_cache 04423 { 04424 protected: 04425 String str_value; 04426 longlong int_value; 04427 bool str_value_cached; 04428 public: 04429 Item_cache_datetime(enum_field_types field_type_arg): 04430 Item_cache(field_type_arg), int_value(0), str_value_cached(0) 04431 { 04432 cmp_context= STRING_RESULT; 04433 } 04434 04435 void store(Item *item, longlong val_arg); 04436 void store(Item *item); 04437 double val_real(); 04438 longlong val_int(); 04439 longlong val_time_temporal(); 04440 longlong val_date_temporal(); 04441 String* val_str(String *str); 04442 my_decimal *val_decimal(my_decimal *); 04443 bool get_date(MYSQL_TIME *ltime, uint fuzzydate); 04444 bool get_time(MYSQL_TIME *ltime); 04445 enum Item_result result_type() const { return STRING_RESULT; } 04446 /* 04447 In order to avoid INT <-> STRING conversion of a DATETIME value 04448 two cache_value functions are introduced. One (cache_value) caches STRING 04449 value, another (cache_value_int) - INT value. Thus this cache item 04450 completely relies on the ability of the underlying item to do the 04451 correct conversion. 04452 */ 04453 bool cache_value_int(); 04454 bool cache_value(); 04455 void clear() { Item_cache::clear(); str_value_cached= FALSE; } 04456 }; 04457 04458 04459 /* 04460 Item_type_holder used to store type. name, length of Item for UNIONS & 04461 derived tables. 04462 04463 Item_type_holder do not need cleanup() because its time of live limited by 04464 single SP/PS execution. 04465 */ 04466 class Item_type_holder: public Item 04467 { 04468 protected: 04469 TYPELIB *enum_set_typelib; 04470 enum_field_types fld_type; 04471 Field::geometry_type geometry_type; 04472 04473 void get_full_info(Item *item); 04474 04475 /* It is used to count decimal precision in join_types */ 04476 int prev_decimal_int_part; 04477 public: 04478 Item_type_holder(THD*, Item*); 04479 04480 Item_result result_type() const; 04481 enum_field_types field_type() const { return fld_type; }; 04482 enum Type type() const { return TYPE_HOLDER; } 04483 double val_real(); 04484 longlong val_int(); 04485 my_decimal *val_decimal(my_decimal *); 04486 String *val_str(String*); 04487 bool get_date(MYSQL_TIME *ltime, uint fuzzydate) 04488 { 04489 DBUG_ASSERT(0); 04490 return true; 04491 } 04492 bool get_time(MYSQL_TIME *ltime) 04493 { 04494 DBUG_ASSERT(0); 04495 return true; 04496 } 04497 bool join_types(THD *thd, Item *); 04498 Field *make_field_by_type(TABLE *table); 04499 static uint32 display_length(Item *item); 04500 static enum_field_types get_real_type(Item *); 04501 Field::geometry_type get_geometry_type() const { return geometry_type; }; 04502 }; 04503 04504 04505 class st_select_lex; 04506 void mark_select_range_as_dependent(THD *thd, 04507 st_select_lex *last_select, 04508 st_select_lex *current_sel, 04509 Field *found_field, Item *found_item, 04510 Item_ident *resolved_item); 04511 04512 extern Cached_item *new_Cached_item(THD *thd, Item *item, 04513 bool use_result_field); 04514 extern Item_result item_cmp_type(Item_result a,Item_result b); 04515 extern void resolve_const_item(THD *thd, Item **ref, Item *cmp_item); 04516 extern int stored_field_cmp_to_item(THD *thd, Field *field, Item *item); 04517 04518 extern const String my_null_string; 04519 04520 #endif /* ITEM_INCLUDED */