~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Brian Aker
  • Date: 2008-11-18 23:19:19 UTC
  • mfrom: (584.1.16 devel)
  • Revision ID: brian@tangent.org-20081118231919-w9sr347dtiwhccml
Merge of Monty's work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
#ifndef drizzled_item_h
21
 
#define drizzled_item_h
 
20
#ifndef DRIZZLED_ITEM_H
 
21
#define DRIZZLED_ITEM_H
22
22
 
23
23
#include <drizzled/dtcollation.h>
 
24
#include <mysys/drizzle_time.h>
 
25
#include <drizzled/my_decimal.h>
 
26
#include <drizzled/sql_bitmap.h>
 
27
#include <drizzled/sql_list.h>
 
28
#include <drizzled/sql_alloc.h>
24
29
 
25
30
class Protocol;
26
 
struct TableList;
 
31
class TableList;
 
32
class Item_field;
 
33
class Name_resolution_context;
 
34
class st_select_lex;
 
35
class Item_equal;
 
36
class COND_EQUAL;
 
37
class user_var_entry;
 
38
class Item_sum;
 
39
class Item_in_subselect;
 
40
class Send_field;
 
41
class Field;
 
42
 
27
43
void item_init(void);                   /* Init item functions */
28
 
class Item_field;
29
44
 
30
45
 
31
46
void dummy_error_processor(Session *session, void *data);
32
 
 
33
47
void view_error_processor(Session *session, void *data);
34
48
 
35
 
/*
36
 
  Instances of Name_resolution_context store the information necesary for
37
 
  name resolution of Items and other context analysis of a query made in
38
 
  fix_fields().
39
 
 
40
 
  This structure is a part of SELECT_LEX, a pointer to this structure is
41
 
  assigned when an item is created (which happens mostly during  parsing
42
 
  (sql_yacc.yy)), but the structure itself will be initialized after parsing
43
 
  is complete
44
 
 
45
 
  TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
46
 
  separate SELECT_LEX which allow to remove tricks of changing this
47
 
  structure before and after INSERT/CREATE and its SELECT to make correct
48
 
  field name resolution.
49
 
*/
50
 
struct Name_resolution_context: Sql_alloc
51
 
{
52
 
  /*
53
 
    The name resolution context to search in when an Item cannot be
54
 
    resolved in this context (the context of an outer select)
55
 
  */
56
 
  Name_resolution_context *outer_context;
57
 
 
58
 
  /*
59
 
    List of tables used to resolve the items of this context.  Usually these
60
 
    are tables from the FROM clause of SELECT statement.  The exceptions are
61
 
    INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
62
 
    subquery is not moved to a separate SELECT_LEX.  For these types of
63
 
    statements we have to change this member dynamically to ensure correct
64
 
    name resolution of different parts of the statement.
65
 
  */
66
 
  TableList *table_list;
67
 
  /*
68
 
    In most cases the two table references below replace 'table_list' above
69
 
    for the purpose of name resolution. The first and last name resolution
70
 
    table references allow us to search only in a sub-tree of the nested
71
 
    join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
72
 
    and JOIN ... ON. 
73
 
  */
74
 
  TableList *first_name_resolution_table;
75
 
  /*
76
 
    Last table to search in the list of leaf table references that begins
77
 
    with first_name_resolution_table.
78
 
  */
79
 
  TableList *last_name_resolution_table;
80
 
 
81
 
  /*
82
 
    SELECT_LEX item belong to, in case of merged VIEW it can differ from
83
 
    SELECT_LEX where item was created, so we can't use table_list/field_list
84
 
    from there
85
 
  */
86
 
  st_select_lex *select_lex;
87
 
 
88
 
  /*
89
 
    Processor of errors caused during Item name resolving, now used only to
90
 
    hide underlying tables in errors about views (i.e. it substitute some
91
 
    errors for views)
92
 
  */
93
 
  void (*error_processor)(Session *, void *);
94
 
  void *error_processor_data;
95
 
 
96
 
  /*
97
 
    When true items are resolved in this context both against the
98
 
    SELECT list and this->table_list. If false, items are resolved
99
 
    only against this->table_list.
100
 
  */
101
 
  bool resolve_in_select_list;
102
 
 
103
 
  /*
104
 
    Security context of this name resolution context. It's used for views
105
 
    and is non-zero only if the view is defined with SQL SECURITY DEFINER.
106
 
  */
107
 
  Security_context *security_ctx;
108
 
 
109
 
  Name_resolution_context()
110
 
    :outer_context(0), table_list(0), select_lex(0),
111
 
    error_processor_data(0),
112
 
    security_ctx(0)
113
 
    {}
114
 
 
115
 
  void init()
116
 
  {
117
 
    resolve_in_select_list= false;
118
 
    error_processor= &dummy_error_processor;
119
 
    first_name_resolution_table= NULL;
120
 
    last_name_resolution_table= NULL;
121
 
  }
122
 
 
123
 
  void resolve_in_table_list_only(TableList *tables)
124
 
  {
125
 
    table_list= first_name_resolution_table= tables;
126
 
    resolve_in_select_list= false;
127
 
  }
128
 
 
129
 
  void process_error(Session *session)
130
 
  {
131
 
    (*error_processor)(session, error_processor_data);
132
 
  }
133
 
};
134
 
 
135
 
 
136
 
/*
137
 
  Store and restore the current state of a name resolution context.
138
 
*/
139
 
 
140
 
class Name_resolution_context_state
141
 
{
142
 
private:
143
 
  TableList *save_table_list;
144
 
  TableList *save_first_name_resolution_table;
145
 
  TableList *save_next_name_resolution_table;
146
 
  bool        save_resolve_in_select_list;
147
 
  TableList *save_next_local;
148
 
 
149
 
public:
150
 
  Name_resolution_context_state() {}          /* Remove gcc warning */
151
 
 
152
 
public:
153
 
  /* Save the state of a name resolution context. */
154
 
  void save_state(Name_resolution_context *context, TableList *table_list)
155
 
  {
156
 
    save_table_list=                  context->table_list;
157
 
    save_first_name_resolution_table= context->first_name_resolution_table;
158
 
    save_resolve_in_select_list=      context->resolve_in_select_list;
159
 
    save_next_local=                  table_list->next_local;
160
 
    save_next_name_resolution_table=  table_list->next_name_resolution_table;
161
 
  }
162
 
 
163
 
  /* Restore a name resolution context from saved state. */
164
 
  void restore_state(Name_resolution_context *context, TableList *table_list)
165
 
  {
166
 
    table_list->next_local=                save_next_local;
167
 
    table_list->next_name_resolution_table= save_next_name_resolution_table;
168
 
    context->table_list=                   save_table_list;
169
 
    context->first_name_resolution_table=  save_first_name_resolution_table;
170
 
    context->resolve_in_select_list=       save_resolve_in_select_list;
171
 
  }
172
 
 
173
 
  TableList *get_first_name_resolution_table()
174
 
  {
175
 
    return save_first_name_resolution_table;
176
 
  }
177
 
};
178
 
 
179
49
 
180
50
/*************************************************************************/
181
51
/*
195
65
typedef bool (Item::*Item_processor) (unsigned char *arg);
196
66
 
197
67
 
198
 
class Item
 
68
class Item: public Sql_alloc
199
69
{
200
 
  Item(const Item &);                   /* Prevent use of these */
 
70
  /* Prevent use of these */
 
71
  Item(const Item &);
201
72
  void operator=(Item &);
 
73
 
202
74
  /* Cache of the result of is_expensive(). */
203
75
  int8_t is_expensive_cache;
204
 
  virtual bool is_expensive_processor(unsigned char *arg __attribute__((unused)))
205
 
  { return 0; }
 
76
  virtual bool is_expensive_processor(unsigned char *arg);
206
77
 
207
78
public:
208
 
  static void *operator new(size_t size)
209
 
  { return sql_alloc(size); }
210
 
  static void *operator new(size_t size, MEM_ROOT *mem_root)
211
 
  { return alloc_root(mem_root, size); }
212
 
  static void operator delete(void *ptr __attribute__((unused)),
213
 
                              size_t size __attribute__((unused)))
214
 
  { TRASH(ptr, size); }
215
 
  static void operator delete(void *ptr __attribute__((unused)),
216
 
                              MEM_ROOT *mem_root __attribute__((unused)))
217
 
  {}
218
79
 
219
80
  enum Type {FIELD_ITEM= 0, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
220
 
             INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
221
 
             COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
222
 
             PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
223
 
             FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
 
81
             INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
 
82
             COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
 
83
             PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
 
84
             FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
224
85
             SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
225
86
             PARAM_ITEM, DECIMAL_ITEM,
226
87
             VIEW_FIXER_ITEM};
228
89
  enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
229
90
 
230
91
  enum traverse_order { POSTFIX, PREFIX };
231
 
  
 
92
 
232
93
  /* Reuse size, only used by SP local variable assignment, otherwize 0 */
233
94
  uint32_t rsize;
234
95
 
237
98
    save_in_field
238
99
  */
239
100
  String str_value;
240
 
  char * name;                  /* Name from select */
 
101
 
 
102
  /* Name from select */
 
103
  char * name;
 
104
 
241
105
  /* Original item name (if it was renamed)*/
242
106
  char * orig_name;
243
107
  Item *next;
244
108
  uint32_t max_length;
245
 
  uint32_t name_length;                     /* Length of name */
 
109
 
 
110
  /* Length of name */
 
111
  uint32_t name_length;
 
112
 
246
113
  int8_t marker;
247
114
  uint8_t decimals;
248
115
  bool maybe_null;                      /* If item may be null */
273
140
#ifdef EXTRA_DEBUG
274
141
    name=0;
275
142
#endif
276
 
  }             /*lint -e1509 */
277
 
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
 
143
  }
 
144
  void set_name(const char *str, uint32_t length,
 
145
                const CHARSET_INFO * const cs);
278
146
  void rename(char *new_name);
279
147
  void init_make_field(Send_field *tmp_field,enum enum_field_types type);
280
148
  virtual void cleanup();
281
149
  virtual void make_field(Send_field *field);
282
150
  Field *make_string_field(Table *table);
283
151
  virtual bool fix_fields(Session *, Item **);
 
152
 
284
153
  /*
285
154
    Fix after some tables has been pulled out. Basically re-calculate all
286
155
    attributes that are dependent on the tables.
287
156
  */
288
 
  virtual void fix_after_pullout(st_select_lex *new_parent __attribute__((unused)),
289
 
                                 Item **ref __attribute__((unused))) {};
 
157
  virtual void fix_after_pullout(st_select_lex *new_parent, Item **ref);
290
158
 
291
159
  /*
292
160
    should be used in case where we are sure that we do not need
293
 
    complete fix_fields() procedure.
294
 
  */
 
161
    complete fix_fields() procedure.  */
295
162
  inline void quick_fix_field() { fixed= 1; }
296
 
  /* Function returns 1 on overflow and -1 on fatal errors */
 
163
 
 
164
  /*
 
165
  Save value in field, but don't give any warnings
 
166
 
 
167
  NOTES
 
168
   This is used to temporary store and retrieve a value in a column,
 
169
   for example in opt_range to adjust the key value to fit the column.
 
170
  Return: Function returns 1 on overflow and -1 on fatal errors
 
171
  */
297
172
  int save_in_field_no_warnings(Field *field, bool no_conversions);
 
173
 
298
174
  virtual int save_in_field(Field *field, bool no_conversions);
299
175
  virtual void save_org_in_field(Field *field)
300
176
  { (void) save_in_field(field, 1); }
307
183
  virtual enum_field_types string_field_type() const;
308
184
  virtual enum_field_types field_type() const;
309
185
  virtual enum Type type() const =0;
310
 
  
 
186
 
311
187
  /*
312
188
    Return information about function monotonicity. See comment for
313
189
    enum_monotonicity_info for details. This function can only be called
317
193
  { return NON_MONOTONIC; }
318
194
 
319
195
  /*
320
 
    Convert "func_arg $CMP$ const" half-interval into "FUNC(func_arg) $CMP2$ const2"
 
196
    Convert:
 
197
      "func_arg $CMP$ const" half-interval
 
198
    into:
 
199
      "FUNC(func_arg) $CMP2$ const2"
321
200
 
322
201
    SYNOPSIS
323
202
      val_int_endpoint()
337
216
      The value of const is supplied implicitly as the value this item's
338
217
      argument, the form of $CMP$ comparison is specified through the
339
218
      function's arguments. The calle returns the result interval
340
 
         
 
219
 
341
220
         F(x) $CMP2$ F(const)
342
 
      
343
 
      passing back F(const) as the return value, and the form of $CMP2$ 
 
221
 
 
222
      passing back F(const) as the return value, and the form of $CMP2$
344
223
      through the out parameter. NULL values are assumed to be comparable and
345
224
      be less than any non-NULL values.
346
225
 
349
228
        - If the value of the function is NULL then the bound is the
350
229
          smallest possible value of INT64_MIN
351
230
  */
352
 
  virtual int64_t val_int_endpoint(bool left_endp __attribute__((unused)),
353
 
                                    bool *incl_endp __attribute__((unused)))
354
 
  { assert(0); return 0; }
 
231
  virtual int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
355
232
 
356
233
 
357
234
  /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
463
340
 
464
341
  virtual Field *get_tmp_table_field(void) { return 0; }
465
342
  /* This is also used to create fields in CREATE ... SELECT: */
466
 
  virtual Field *tmp_table_field(Table *t_arg __attribute__((unused)))
467
 
  { return 0; }
468
 
  virtual const char *full_name(void) const { return name ? name : "???"; }
 
343
  virtual Field *tmp_table_field(Table *t_arg);
 
344
  virtual const char *full_name(void) const;
469
345
 
470
346
  /*
471
347
    *result* family of methods is analog of *val* family (see above) but
505
381
  inline uint32_t float_length(uint32_t decimals_par) const
506
382
  { return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;}
507
383
  virtual uint32_t decimal_precision() const;
508
 
  inline int decimal_int_part() const
509
 
  { return my_decimal_int_part(decimal_precision(), decimals); }
510
 
  /* 
 
384
  int decimal_int_part() const;
 
385
 
 
386
  /*
511
387
    Returns true if this is constant (during query execution, i.e. its value
512
388
    will not change until next fix_fields) and its value is known.
513
389
  */
514
390
  virtual bool const_item() const { return used_tables() == 0; }
515
 
  /* 
 
391
  /*
516
392
    Returns true if this is constant but its value may be not known yet.
517
393
    (Can be used for parameters of prep. stmts or of stored procedures.)
518
394
  */
519
 
  virtual bool const_during_execution() const 
 
395
  virtual bool const_during_execution() const
520
396
  { return (used_tables() & ~PARAM_TABLE_BIT) == 0; }
521
397
 
522
398
  /**
530
406
    query and why they should be generated from the Item-tree, @see
531
407
    mysql_register_view().
532
408
  */
533
 
  virtual inline void print(String *str,
534
 
                            enum_query_type query_type __attribute__((unused)))
535
 
  {
536
 
    str->append(full_name());
537
 
  }
 
409
  virtual void print(String *str, enum_query_type query_type);
538
410
 
539
411
  void print_item_w_name(String *, enum_query_type query_type);
540
412
  virtual void update_used_tables() {}
541
 
  virtual void split_sum_func(Session *session __attribute__((unused)),
542
 
                              Item **ref_pointer_array __attribute__((unused)),
543
 
                              List<Item> &fields __attribute__((unused))) {}
 
413
  virtual void split_sum_func(Session *session, Item **ref_pointer_array,
 
414
                              List<Item> &fields);
 
415
 
544
416
  /* Called for items that really have to be split */
545
 
  void split_sum_func2(Session *session, Item **ref_pointer_array, List<Item> &fields,
546
 
                       Item **ref, bool skip_registered);
 
417
  void split_sum_func(Session *session, Item **ref_pointer_array,
 
418
                      List<Item> &fields,
 
419
                      Item **ref, bool skip_registered);
 
420
 
547
421
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
548
422
  virtual bool get_time(DRIZZLE_TIME *ltime);
549
 
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate)
550
 
  { return get_date(ltime,fuzzydate); }
 
423
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
 
424
 
551
425
  /*
552
 
    The method allows to determine nullness of a complex expression 
553
 
    without fully evaluating it, instead of calling val/result*() then 
 
426
    The method allows to determine nullness of a complex expression
 
427
    without fully evaluating it, instead of calling val/result*() then
554
428
    checking null_value. Used in Item_func_isnull/Item_func_isnotnull
555
429
    and Item_sum_count/Item_sum_count_distinct.
556
430
    Any new item which can be NULL must implement this method.
557
431
  */
558
 
  virtual bool is_null() { return 0; }
 
432
  virtual bool is_null();
559
433
 
560
434
  /*
561
435
   Make sure the null_value member has a correct value.
562
436
  */
563
 
  virtual void update_null_value () { (void) val_int(); }
 
437
  virtual void update_null_value ();
564
438
 
565
439
  /*
566
440
    Inform the item that there will be no distinction between its result
572
446
      Item_cond_and and subquery-related item) enable special optimizations
573
447
      when they are "top level".
574
448
  */
575
 
  virtual void top_level_item(void) {}
 
449
  virtual void top_level_item(void);
576
450
  /*
577
451
    set field of temporary table for Item which can be switched on temporary
578
452
    table during query processing (grouping and so on)
579
453
  */
580
 
  virtual void set_result_field(Field *field __attribute__((unused))) {}
581
 
  virtual bool is_result_field(void) { return 0; }
582
 
  virtual bool is_bool_func(void) { return 0; }
583
 
  virtual void save_in_result_field(bool no_conversions __attribute__((unused)))
584
 
  {}
 
454
  virtual void set_result_field(Field *field);
 
455
  virtual bool is_result_field(void);
 
456
  virtual bool is_bool_func(void);
 
457
  virtual void save_in_result_field(bool no_conversions);
 
458
 
585
459
  /*
586
460
    set value of aggregate function in case of no rows for grouping were found
587
461
  */
588
 
  virtual void no_rows_in_result(void) {}
589
 
  virtual Item *copy_or_same(Session *session __attribute__((unused)))
590
 
  { return this; }
591
 
  virtual Item *copy_andor_structure(Session *session  __attribute__((unused)))
592
 
  { return this; }
593
 
  virtual Item *real_item(void) { return this; }
594
 
  virtual Item *get_tmp_table_item(Session *session) { return copy_or_same(session); }
 
462
  virtual void no_rows_in_result(void);
 
463
  virtual Item *copy_or_same(Session *session);
 
464
 
 
465
  virtual Item *copy_andor_structure(Session *session);
 
466
 
 
467
  virtual Item *real_item(void);
 
468
  virtual Item *get_tmp_table_item(Session *session);
595
469
 
596
470
  static const CHARSET_INFO *default_charset();
597
 
  virtual const CHARSET_INFO *compare_collation() { return NULL; }
 
471
  virtual const CHARSET_INFO *compare_collation();
598
472
 
599
 
  virtual bool walk(Item_processor processor __attribute__((unused)),
600
 
                    bool walk_subquery __attribute__((unused)),
601
 
                    unsigned char *arg)
602
 
  {
603
 
    return (this->*processor)(arg);
604
 
  }
 
473
  virtual bool walk(Item_processor processor,
 
474
                    bool walk_subquery,
 
475
                    unsigned char *arg);
605
476
 
606
477
  virtual Item* transform(Item_transformer transformer, unsigned char *arg);
607
478
 
608
479
  /*
609
480
    This function performs a generic "compilation" of the Item tree.
610
 
    The process of compilation is assumed to go as follows: 
611
 
    
 
481
    The process of compilation is assumed to go as follows:
 
482
 
612
483
    compile()
613
 
    { 
 
484
    {
614
485
      if (this->*some_analyzer(...))
615
486
      {
616
487
        compile children if any;
619
490
    }
620
491
 
621
492
    i.e. analysis is performed top-down while transformation is done
622
 
    bottom-up.      
 
493
    bottom-up.
623
494
  */
624
495
  virtual Item* compile(Item_analyzer analyzer, unsigned char **arg_p,
625
 
                        Item_transformer transformer, unsigned char *arg_t)
626
 
  {
627
 
    if ((this->*analyzer) (arg_p))
628
 
      return ((this->*transformer) (arg_t));
629
 
    return 0;
630
 
  }
631
 
 
632
 
   virtual void traverse_cond(Cond_traverser traverser __attribute__((unused)),
633
 
                              void *arg,
634
 
                              traverse_order order __attribute__((unused)))
635
 
   {
636
 
     (*traverser)(this, arg);
637
 
   }
638
 
 
639
 
  virtual bool remove_dependence_processor(unsigned char * arg __attribute__((unused)))
640
 
  { return 0; }
641
 
  virtual bool remove_fixed(unsigned char * arg __attribute__((unused)))
642
 
  {
643
 
    fixed= 0;
644
 
    return 0;
645
 
  }
646
 
  virtual bool cleanup_processor(unsigned char *arg __attribute__((unused)));
647
 
  virtual bool collect_item_field_processor(unsigned char * arg __attribute__((unused)))
648
 
  { return 0; }
649
 
  virtual bool find_item_in_field_list_processor(unsigned char *arg __attribute__((unused)))
650
 
 { return 0; }
651
 
  virtual bool change_context_processor(unsigned char *context __attribute__((unused)))
652
 
  { return 0; }
653
 
  virtual bool reset_query_id_processor(unsigned char *query_id_arg __attribute__((unused)))
654
 
  { return 0; }
655
 
  virtual bool register_field_in_read_map(unsigned char *arg __attribute__((unused)))
656
 
  { return 0; }
 
496
                        Item_transformer transformer, unsigned char *arg_t);
 
497
 
 
498
  virtual void traverse_cond(Cond_traverser traverser,
 
499
                             void *arg,
 
500
                             traverse_order order);
 
501
 
 
502
  virtual bool remove_dependence_processor(unsigned char * arg);
 
503
  virtual bool remove_fixed(unsigned char * arg);
 
504
  virtual bool cleanup_processor(unsigned char *arg);
 
505
  virtual bool collect_item_field_processor(unsigned char * arg);
 
506
  virtual bool find_item_in_field_list_processor(unsigned char *arg);
 
507
  virtual bool change_context_processor(unsigned char *context);
 
508
  virtual bool reset_query_id_processor(unsigned char *query_id_arg);
 
509
  virtual bool register_field_in_read_map(unsigned char *arg);
 
510
 
657
511
  /*
658
512
    The next function differs from the previous one that a bitmap to be updated
659
513
    is passed as unsigned char *arg.
660
514
  */
661
 
  virtual bool register_field_in_bitmap(unsigned char *arg __attribute__((unused)))
662
 
  { return 0; }
663
 
  virtual bool subst_argument_checker(unsigned char **arg)
664
 
  {
665
 
    if (*arg)
666
 
      *arg= NULL;
667
 
    return true;
668
 
  }
 
515
  virtual bool register_field_in_bitmap(unsigned char *arg);
 
516
  virtual bool subst_argument_checker(unsigned char **arg);
669
517
 
670
518
  /*
671
519
    Check if an expression/function is allowed for a virtual column
676
524
      TRUE                           Function not accepted
677
525
      FALSE                          Function accepted
678
526
  */
679
 
  virtual bool check_vcol_func_processor(unsigned char *arg __attribute__((unused))) 
680
 
  { return true; }
681
 
 
682
 
  virtual Item *equal_fields_propagator(unsigned char * arg __attribute__((unused))) { return this; }
683
 
  virtual bool set_no_const_sub(unsigned char *arg __attribute__((unused))) { return false; }
684
 
  virtual Item *replace_equal_field(unsigned char * arg __attribute__((unused))) { return this; }
 
527
  virtual bool check_vcol_func_processor(unsigned char *arg);
 
528
  virtual Item *equal_fields_propagator(unsigned char * arg);
 
529
  virtual bool set_no_const_sub(unsigned char *arg);
 
530
  virtual Item *replace_equal_field(unsigned char * arg);
685
531
 
686
532
 
687
533
  /*
688
534
    For SP local variable returns pointer to Item representing its
689
535
    current value and pointer to current Item otherwise.
690
536
  */
691
 
  virtual Item *this_item(void) { return this; }
692
 
  virtual const Item *this_item(void) const { return this; }
 
537
  virtual Item *this_item(void);
 
538
  virtual const Item *this_item(void) const;
693
539
 
694
540
  /*
695
541
    For SP local variable returns address of pointer to Item representing its
696
542
    current value and pointer passed via parameter otherwise.
697
543
  */
698
 
  virtual Item **this_item_addr(Session *session __attribute__((unused)), Item **addr_arg) { return addr_arg; }
 
544
  virtual Item **this_item_addr(Session *session, Item **addr_arg);
699
545
 
700
546
  // Row emulation
701
 
  virtual uint32_t cols() { return 1; }
702
 
  virtual Item* element_index(uint32_t i __attribute__((unused))) { return this; }
703
 
  virtual Item** addr(uint32_t i __attribute__((unused))) { return 0; }
 
547
  virtual uint32_t cols();
 
548
  virtual Item* element_index(uint32_t i);
 
549
  virtual Item** addr(uint32_t i);
704
550
  virtual bool check_cols(uint32_t c);
705
551
  // It is not row => null inside is impossible
706
 
  virtual bool null_inside() { return 0; }
 
552
  virtual bool null_inside();
707
553
  // used in row subselects to get value of elements
708
 
  virtual void bring_value() {}
 
554
  virtual void bring_value();
709
555
 
710
556
  Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
711
 
  virtual Item_field *filed_for_view_update() { return 0; }
 
557
  virtual Item_field *filed_for_view_update();
712
558
 
713
 
  virtual Item *neg_transformer(Session *session __attribute__((unused))) { return NULL; }
714
 
  virtual Item *update_value_transformer(unsigned char *select_arg __attribute__((unused))) { return this; }
 
559
  virtual Item *neg_transformer(Session *session);
 
560
  virtual Item *update_value_transformer(unsigned char *select_arg);
715
561
  virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
716
 
  void delete_self()
717
 
  {
718
 
    cleanup();
719
 
    delete this;
720
 
  }
 
562
  void delete_self();
721
563
 
722
564
  /*
723
565
    result_as_int64_t() must return true for Items representing DATE/TIME
726
568
    their values should be compared as integers (because the integer
727
569
    representation is more precise than the string one).
728
570
  */
729
 
  virtual bool result_as_int64_t() { return false; }
 
571
  virtual bool result_as_int64_t();
730
572
  bool is_datetime();
731
573
 
732
574
  /*
740
582
    where 'cost' is either 'double' or some structure of various cost
741
583
    parameters.
742
584
  */
743
 
  virtual bool is_expensive()
744
 
  {
745
 
    if (is_expensive_cache < 0)
746
 
      is_expensive_cache= walk(&Item::is_expensive_processor, 0, (unsigned char*)0);
747
 
    return test(is_expensive_cache);
748
 
  }
 
585
  virtual bool is_expensive();
 
586
 
749
587
  String *check_well_formed_result(String *str, bool send_error= 0);
750
 
  bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs); 
 
588
  bool eq_by_collation(Item *item, bool binary_cmp,
 
589
                       const CHARSET_INFO * const cs);
 
590
 
751
591
};
752
592
 
753
593
 
776
616
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
777
617
};
778
618
 
779
 
#define NO_CACHED_FIELD_INDEX ((uint)(-1))
780
 
 
781
 
class st_select_lex;
782
619
class Item_ident :public Item
783
620
{
784
621
protected:
800
637
  bool alias_name_used; /* true if item was resolved against alias */
801
638
  /* 
802
639
    Cached value of index for this field in table->field array, used by prep. 
803
 
    stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX 
 
640
    stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX
804
641
    if index value is not known.
805
642
  */
806
643
  uint32_t cached_field_index;
841
678
  {}
842
679
 
843
680
  enum Type type() const { return FIELD_ITEM; }
844
 
  double val_real() { return field->val_real(); }
845
 
  int64_t val_int() { return field->val_int(); }
846
 
  String *val_str(String *str) { return field->val_str(str); }
847
 
  my_decimal *val_decimal(my_decimal *dec) { return field->val_decimal(dec); }
 
681
  double val_real();
 
682
  int64_t val_int();
 
683
  String *val_str(String *str);
 
684
  my_decimal *val_decimal(my_decimal *dec);
848
685
  void make_field(Send_field *tmp_field);
849
686
};
850
687
 
851
688
 
852
 
class Item_equal;
853
 
class COND_EQUAL;
854
 
class user_var_entry;
855
 
 
856
689
class Item_field :public Item_ident
857
690
{
858
691
protected:
906
739
  int save_in_field(Field *field,bool no_conversions);
907
740
  void save_org_in_field(Field *field);
908
741
  table_map used_tables() const;
909
 
  enum Item_result result_type () const
910
 
  {
911
 
    return field->result_type();
912
 
  }
913
 
  Item_result cast_to_int_type() const
914
 
  {
915
 
    return field->cast_to_int_type();
916
 
  }
917
 
  enum_field_types field_type() const
918
 
  {
919
 
    return field->type();
920
 
  }
 
742
  enum Item_result result_type () const;
 
743
  Item_result cast_to_int_type() const;
 
744
  enum_field_types field_type() const;
921
745
  enum_monotonicity_info get_monotonicity_info() const
922
746
  {
923
747
    return MONOTONIC_STRICT_INCREASING;
928
752
  bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
929
753
  bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
930
754
  bool get_time(DRIZZLE_TIME *ltime);
931
 
  bool is_null() { return field->is_null(); }
 
755
  bool is_null();
932
756
  void update_null_value();
933
757
  Item *get_tmp_table_item(Session *session);
934
758
  bool collect_item_field_processor(unsigned char * arg);
938
762
  bool check_vcol_func_processor(unsigned char *arg __attribute__((unused)))
939
763
  { return false; }
940
764
  void cleanup();
941
 
  bool result_as_int64_t()
942
 
  {
943
 
    return field->can_be_compared_as_int64_t();
944
 
  }
 
765
  bool result_as_int64_t();
945
766
  Item_equal *find_item_equal(COND_EQUAL *cond_equal);
946
767
  bool subst_argument_checker(unsigned char **arg);
947
768
  Item *equal_fields_propagator(unsigned char *arg);
948
769
  bool set_no_const_sub(unsigned char *arg);
949
770
  Item *replace_equal_field(unsigned char *arg);
950
 
  inline uint32_t max_disp_length() { return field->max_display_length(); }
 
771
  uint32_t max_disp_length();
951
772
  Item_field *filed_for_view_update() { return this; }
952
773
  Item *safe_charset_converter(const CHARSET_INFO * const tocs);
953
774
  int fix_outer_field(Session *session, Field **field, Item **reference);
1766
1587
  Item_field::fix_outer_field() functions.
1767
1588
*/
1768
1589
 
1769
 
class Item_sum;
1770
1590
class Item_outer_ref :public Item_direct_ref
1771
1591
{
1772
1592
public:
1810
1630
};
1811
1631
 
1812
1632
 
1813
 
class Item_in_subselect;
1814
 
 
1815
1633
 
1816
1634
/*
1817
1635
  An object of this class:
1876
1694
  virtual Item *real_item() { return ref; }
1877
1695
};
1878
1696
 
1879
 
#ifdef DRIZZLE_SERVER
1880
 
#include "item_sum.h"
1881
 
#include "item_func.h"
1882
 
#include "item_row.h"
1883
 
#include "item_cmpfunc.h"
1884
 
#include "item_strfunc.h"
1885
 
#include "item_timefunc.h"
1886
 
#include "item_subselect.h"
1887
 
#endif
1888
1697
 
1889
1698
class Item_copy_string :public Item
1890
1699
{
1930
1739
  bool const_item() const { return 0; }
1931
1740
  bool is_null() { return null_value; }
1932
1741
};
1933
 
 
1934
 
 
1935
 
class Cached_item :public Sql_alloc
1936
 
{
1937
 
public:
1938
 
  bool null_value;
1939
 
  Cached_item() :null_value(0) {}
1940
 
  virtual bool cmp(void)=0;
1941
 
  virtual ~Cached_item(); /*line -e1509 */
1942
 
};
1943
 
 
1944
 
class Cached_item_str :public Cached_item
1945
 
{
1946
 
  Item *item;
1947
 
  String value,tmp_value;
1948
 
public:
1949
 
  Cached_item_str(Session *session, Item *arg);
1950
 
  bool cmp(void);
1951
 
  ~Cached_item_str();                           // Deallocate String:s
1952
 
};
1953
 
 
1954
 
 
1955
 
class Cached_item_real :public Cached_item
1956
 
{
1957
 
  Item *item;
1958
 
  double value;
1959
 
public:
1960
 
  Cached_item_real(Item *item_par) :item(item_par),value(0.0) {}
1961
 
  bool cmp(void);
1962
 
};
1963
 
 
1964
 
class Cached_item_int :public Cached_item
1965
 
{
1966
 
  Item *item;
1967
 
  int64_t value;
1968
 
public:
1969
 
  Cached_item_int(Item *item_par) :item(item_par),value(0) {}
1970
 
  bool cmp(void);
1971
 
};
1972
 
 
1973
 
 
1974
 
class Cached_item_decimal :public Cached_item
1975
 
{
1976
 
  Item *item;
1977
 
  my_decimal value;
1978
 
public:
1979
 
  Cached_item_decimal(Item *item_par);
1980
 
  bool cmp(void);
1981
 
};
1982
 
 
1983
 
class Cached_item_field :public Cached_item
1984
 
{
1985
 
  unsigned char *buff;
1986
 
  Field *field;
1987
 
  uint32_t length;
1988
 
 
1989
 
public:
1990
 
  Cached_item_field(Field *arg_field) : field(arg_field)
1991
 
  {
1992
 
    field= arg_field;
1993
 
    /* TODO: take the memory allocation below out of the constructor. */
1994
 
    buff= (unsigned char*) sql_calloc(length=field->pack_length());
1995
 
  }
1996
 
  bool cmp(void);
1997
 
};
1998
 
 
1999
1742
class Item_default_value : public Item_field
2000
1743
{
2001
1744
public:
2114
1857
  table_map used_tables() const { return used_table_map; }
2115
1858
  virtual void keep_array() {}
2116
1859
  virtual void print(String *str, enum_query_type query_type);
2117
 
  bool eq_def(Field *field) 
2118
 
  { 
2119
 
    return cached_field ? cached_field->eq_def (field) : false;
2120
 
  }
 
1860
  bool eq_def(Field *field);
2121
1861
  bool eq(const Item *item,
2122
1862
          bool binary_cmp __attribute__((unused))) const
2123
1863
  {
2182
1922
  char buffer[STRING_BUFFER_USUAL_SIZE];
2183
1923
  String *value, value_buff;
2184
1924
  bool is_varbinary;
2185
 
  
 
1925
 
2186
1926
public:
2187
 
  Item_cache_str(const Item *item) :
2188
 
    Item_cache(), value(0),
2189
 
    is_varbinary(item->type() == FIELD_ITEM &&
2190
 
                 ((const Item_field *) item)->field->type() ==
2191
 
                   DRIZZLE_TYPE_VARCHAR &&
2192
 
                 !((const Item_field *) item)->field->has_charset())
2193
 
  {}
 
1927
  Item_cache_str(const Item *item);
2194
1928
  void store(Item *item);
2195
1929
  double val_real();
2196
1930
  int64_t val_int();
2201
1935
  int save_in_field(Field *field, bool no_conversions);
2202
1936
};
2203
1937
 
2204
 
class Item_cache_row: public Item_cache
2205
 
{
2206
 
  Item_cache  **values;
2207
 
  uint32_t item_count;
2208
 
  bool save_array;
2209
 
public:
2210
 
  Item_cache_row()
2211
 
    :Item_cache(), values(0), item_count(2), save_array(0) {}
2212
 
  
2213
 
  /*
2214
 
    'allocate' used only in row transformer, to preallocate space for row 
2215
 
    cache.
2216
 
  */
2217
 
  bool allocate(uint32_t num);
2218
 
  /*
2219
 
    'setup' is needed only by row => it not called by simple row subselect
2220
 
    (only by IN subselect (in subselect optimizer))
2221
 
  */
2222
 
  bool setup(Item *item);
2223
 
  void store(Item *item);
2224
 
  void illegal_method_call(const char *);
2225
 
  void make_field(Send_field *)
2226
 
  {
2227
 
    illegal_method_call((const char*)"make_field");
2228
 
  };
2229
 
  double val_real()
2230
 
  {
2231
 
    illegal_method_call((const char*)"val");
2232
 
    return 0;
2233
 
  };
2234
 
  int64_t val_int()
2235
 
  {
2236
 
    illegal_method_call((const char*)"val_int");
2237
 
    return 0;
2238
 
  };
2239
 
  String *val_str(String *)
2240
 
  {
2241
 
    illegal_method_call((const char*)"val_str");
2242
 
    return 0;
2243
 
  };
2244
 
  my_decimal *val_decimal(my_decimal *val __attribute__((unused)))
2245
 
  {
2246
 
    illegal_method_call((const char*)"val_decimal");
2247
 
    return 0;
2248
 
  };
2249
 
 
2250
 
  enum Item_result result_type() const { return ROW_RESULT; }
2251
 
  
2252
 
  uint32_t cols() { return item_count; }
2253
 
  Item *element_index(uint32_t i) { return values[i]; }
2254
 
  Item **addr(uint32_t i) { return (Item **) (values + i); }
2255
 
  bool check_cols(uint32_t c);
2256
 
  bool null_inside();
2257
 
  void bring_value();
2258
 
  void keep_array() { save_array= 1; }
2259
 
  void cleanup()
2260
 
  {
2261
 
    Item_cache::cleanup();
2262
 
    if (save_array)
2263
 
      memset(values, 0, item_count*sizeof(Item**));
2264
 
    else
2265
 
      values= 0;
2266
 
    return;
2267
 
  }
2268
 
};
2269
 
 
2270
 
 
2271
 
/*
2272
 
  Item_type_holder used to store type. name, length of Item for UNIONS &
2273
 
  derived tables.
2274
 
 
2275
 
  Item_type_holder do not need cleanup() because its time of live limited by
2276
 
  single SP/PS execution.
2277
 
*/
2278
 
class Item_type_holder: public Item
2279
 
{
2280
 
protected:
2281
 
  TYPELIB *enum_set_typelib;
2282
 
  enum_field_types fld_type;
2283
 
 
2284
 
  void get_full_info(Item *item);
2285
 
 
2286
 
  /* It is used to count decimal precision in join_types */
2287
 
  int prev_decimal_int_part;
2288
 
public:
2289
 
  Item_type_holder(Session*, Item*);
2290
 
 
2291
 
  Item_result result_type() const;
2292
 
  enum_field_types field_type() const { return fld_type; };
2293
 
  enum Type type() const { return TYPE_HOLDER; }
2294
 
  double val_real();
2295
 
  int64_t val_int();
2296
 
  my_decimal *val_decimal(my_decimal *);
2297
 
  String *val_str(String*);
2298
 
  bool join_types(Session *session, Item *);
2299
 
  Field *make_field_by_type(Table *table);
2300
 
  static uint32_t display_length(Item *item);
2301
 
  static enum_field_types get_real_type(Item *);
2302
 
};
2303
 
 
2304
 
 
2305
 
class st_select_lex;
 
1938
 
 
1939
 
2306
1940
void mark_select_range_as_dependent(Session *session,
2307
1941
                                    st_select_lex *last_select,
2308
1942
                                    st_select_lex *current_sel,
2309
1943
                                    Field *found_field, Item *found_item,
2310
1944
                                    Item_ident *resolved_item);
2311
1945
 
2312
 
extern Cached_item *new_Cached_item(Session *session, Item *item,
2313
 
                                    bool use_result_field);
2314
1946
extern void resolve_const_item(Session *session, Item **ref, Item *cmp_item);
2315
1947
extern bool field_is_equal_to_item(Field *field,Item *item);
2316
1948
 
2354
1986
                        bool make_copy_field,
2355
1987
                        uint32_t convert_blob_length);
2356
1988
 
2357
 
#endif
 
1989
#endif /* DRIZZLED_ITEM_H */