~drizzle-trunk/drizzle/development

390.1.2 by Monty Taylor
Fixed copyright headers in drizzled/
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2008 Sun Microsystems
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
1 by brian
clean slate
19
584.4.4 by Monty Taylor
Split out Name_resolution_context.
20
#ifndef DRIZZLED_ITEM_H
21
#define DRIZZLED_ITEM_H
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
22
584.4.1 by Monty Taylor
Split out DTCollation.
23
#include <drizzled/dtcollation.h>
584.1.14 by Monty Taylor
Removed field.h from common_includes.
24
#include <mysys/drizzle_time.h>
25
#include <drizzled/my_decimal.h>
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
26
#include <drizzled/sql_bitmap.h>
27
#include <drizzled/sql_list.h>
28
#include <drizzled/sql_alloc.h>
798.2.29 by Brian Aker
Detangle more of the session object
29
#include <drizzled/table.h>
584.4.1 by Monty Taylor
Split out DTCollation.
30
1 by brian
clean slate
31
class Protocol;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
32
class TableList;
1 by brian
clean slate
33
class Item_field;
584.4.4 by Monty Taylor
Split out Name_resolution_context.
34
class Name_resolution_context;
846 by Brian Aker
Removing on typedeffed class.
35
class Select_Lex;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
36
class Item_equal;
37
class user_var_entry;
38
class Item_sum;
39
class Item_in_subselect;
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
40
class SendField;
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
41
class Field;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
42
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
43
/**
44
  Dummy error processor used by default by Name_resolution_context.
45
46
  @note
47
    do nothing
48
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
49
void dummy_error_processor(Session *session, void *data);
1 by brian
clean slate
50
51
/*
52
  Analyzer function
53
    SYNOPSIS
54
      argp   in/out IN:  Analysis parameter
55
                    OUT: Parameter to be passed to the transformer
56
584.4.2 by Monty Taylor
Split out hybrid_type_traits.
57
     RETURN
163 by Brian Aker
Merge Monty's code.
58
      true   Invoke the transformer
59
      false  Don't do it
1 by brian
clean slate
60
61
*/
481 by Brian Aker
Remove all of uchar.
62
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
63
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
1 by brian
clean slate
64
typedef void (*Cond_traverser) (const Item *item, void *arg);
584.4.2 by Monty Taylor
Split out hybrid_type_traits.
65
typedef bool (Item::*Item_processor) (unsigned char *arg);
1 by brian
clean slate
66
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
67
/**
68
 * The Item class is the base class for all items in the parsed 
69
 * statement "tree" or Lex.  Each item represents something in the
70
 * execution plan.
71
 */
584.1.15 by Monty Taylor
The mega-patch from hell. Renamed sql_class to session (since that's what it is) and removed it and field and table from common_includes.
72
class Item: public Sql_alloc
1 by brian
clean slate
73
{
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
74
  /* Prevent use of these */
75
  Item(const Item &);
1 by brian
clean slate
76
  void operator=(Item &);
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
77
1 by brian
clean slate
78
  /* Cache of the result of is_expensive(). */
206 by Brian Aker
Removed final uint dead types.
79
  int8_t is_expensive_cache;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
80
  virtual bool is_expensive_processor(unsigned char *arg);
1 by brian
clean slate
81
82
public:
83
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
84
  enum Type 
85
  {
86
    FIELD_ITEM= 0,
608 by Brian Aker
Adding snowman test (plus a dead variable removal).
87
    FUNC_ITEM,
88
    SUM_FUNC_ITEM,
89
    STRING_ITEM,
90
    INT_ITEM,
91
    REAL_ITEM,
92
    NULL_ITEM,
93
    VARBIN_ITEM,
94
    COPY_STR_ITEM,
95
    FIELD_AVG_ITEM,
96
    DEFAULT_VALUE_ITEM,
97
    PROC_ITEM,
98
    COND_ITEM,
99
    REF_ITEM,
100
    FIELD_STD_ITEM,
101
    FIELD_VARIANCE_ITEM,
102
    INSERT_VALUE_ITEM,
103
    SUBSELECT_ITEM,
104
    ROW_ITEM, CACHE_ITEM,
105
    TYPE_HOLDER,
106
    PARAM_ITEM,
107
    DECIMAL_ITEM
108
  };
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
109
  enum traverse_order
110
  { 
111
    T_POSTFIX,
112
    T_PREFIX
113
  };
114
  enum cond_result
115
  {
116
    COND_UNDEF,
117
    COND_OK,
118
    COND_TRUE,
119
    COND_FALSE
120
  };
121
122
  /**
123
   *  str_values's main purpose is to be used to cache the value in
124
   *  save_in_field
125
   */
1 by brian
clean slate
126
  String str_value;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
127
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
128
  /** Name from select */
129
  char *name;
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
130
  /** Length of name */
131
  uint32_t name_length;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
132
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
133
  /** Original item name (if it was renamed) */
134
  char *orig_name;
1 by brian
clean slate
135
  Item *next;
203 by Brian Aker
Small cleanup around uint32 types (need to merge).
136
  uint32_t max_length;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
137
206 by Brian Aker
Removed final uint dead types.
138
  int8_t marker;
139
  uint8_t decimals;
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
140
  bool fixed; /**< If item fixed with fix_fields */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
141
  bool maybe_null; /**< True if item may be null */
142
  bool null_value; /**< True if item is null */
275 by Brian Aker
Full removal of my_bool from central server.
143
  bool unsigned_flag;
144
  bool with_sum_func;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
145
  bool is_autogenerated_name; /**< indicates whether name of this Item was autogenerated or set by user */
146
  /**
147
   * If this item is a subselect or some of its arguments is or contains a
148
   * subselect. Computed by fix_fields. 
149
   */
150
  bool with_subselect;
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
151
  DTCollation collation;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
152
  Item_result cmp_context; /**< Comparison context */
153
  /**
154
   * Constructor
155
   *
156
   * @note
157
   *
158
   * Alloc & destruct is done as start of select using sql_alloc
159
   */
1 by brian
clean slate
160
  Item();
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
161
  /**
162
   * Constructor used by Item_field, Item_ref & aggregate (sum) functions.
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
163
   * 
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
164
   * Used for duplicating lists in processing queries with temporary
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
165
   * tables.
166
   * 
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
167
   * Also it used for Item_cond_and/Item_cond_or for creating
168
   * top AND/OR structure of WHERE clause to protect it of
169
   * optimisation changes in prepared statements
170
   */
520.1.22 by Brian Aker
Second pass of thd cleanup
171
  Item(Session *session, Item *item);
1 by brian
clean slate
172
  virtual ~Item()
173
  {
174
#ifdef EXTRA_DEBUG
175
    name=0;
176
#endif
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
177
  }
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
178
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
179
  /**
180
   * Renames item (used for views, cleanup() return original name).
181
   *
182
   * @param new_name	new name of item;
183
   */
1 by brian
clean slate
184
  void rename(char *new_name);
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
185
  void init_make_field(SendField *tmp_field,enum enum_field_types type);
1 by brian
clean slate
186
  virtual void cleanup();
1052.2.4 by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards.
187
  virtual void make_field(SendField *field);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
188
  /**
189
    Create a field to hold a string value from an item.
190
191
    If max_length > CONVERT_IF_BIGGER_TO_BLOB create a blob @n
192
    If max_length > 0 create a varchar @n
193
    If max_length == 0 create a CHAR(0)
194
195
    @param table		Table for which the field is created
196
  */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
197
  Field *make_string_field(Table *table);
520.1.21 by Brian Aker
THD -> Session rename
198
  virtual bool fix_fields(Session *, Item **);
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
199
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
200
  /**
201
   * Fix after some tables has been pulled out. Basically re-calculate all
202
   * attributes that are dependent on the tables.
203
   */
846 by Brian Aker
Removing on typedeffed class.
204
  virtual void fix_after_pullout(Select_Lex *new_parent, Item **ref);
1 by brian
clean slate
205
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
206
  /**
207
   * Should be used in case where we are sure that we do not need
208
   * complete fix_fields() procedure.  
209
   */
210
  inline void quick_fix_field()
211
  {
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
212
    fixed= true;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
213
  }
214
215
  /**
216
   * Save value in field, but don't give any warnings.
217
   *
218
   * @note
219
   *
220
   * This is used to temporary store and retrieve a value in a column,
221
   * for example in opt_range to adjust the key value to fit the column.
222
   * Return: Function returns 1 on overflow and -1 on fatal errors
223
   */
1 by brian
clean slate
224
  int save_in_field_no_warnings(Field *field, bool no_conversions);
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
225
1 by brian
clean slate
226
  virtual int save_in_field(Field *field, bool no_conversions);
227
  virtual void save_org_in_field(Field *field)
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
228
  {
229
    (void) save_in_field(field, true);
230
  }
1 by brian
clean slate
231
  virtual int save_safe_in_field(Field *field)
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
232
  {
233
    return save_in_field(field, true);
234
  }
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
235
  /**
236
   * This is only called from items that is not of type item_field.
237
   */
1 by brian
clean slate
238
  virtual bool send(Protocol *protocol, String *str);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
239
  /**
240
    Compares this Item to another Item, returning true if Item's 
241
    are functionally equal.
242
243
    @details
244
245
    This function is called when:
246
    - Comparing items in the WHERE clause (when doing where optimization)
247
    - When trying to find an order_st BY/GROUP BY item in the SELECT part
248
  */
1 by brian
clean slate
249
  virtual bool eq(const Item *, bool binary_cmp) const;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
250
  virtual Item_result result_type() const
251
  {
252
    return REAL_RESULT;
253
  }
254
  virtual Item_result cast_to_int_type() const
255
  {
256
    return result_type();
257
  }
1 by brian
clean slate
258
  virtual enum_field_types string_field_type() const;
259
  virtual enum_field_types field_type() const;
260
  virtual enum Type type() const =0;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
261
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
262
  /**
263
   * Converts
264
   *  "func_arg $CMP$ const" half-interval
265
   * into
266
   *  "FUNC(func_arg) $CMP2$ const2"
267
   *
268
   * @details
269
   *
270
   * left_endp  false  <=> The interval is "x < const" or "x <= const"
271
   *            true   <=> The interval is "x > const" or "x >= const"
272
   *
273
   * incl_endp  IN   true <=> the comparison is '<' or '>'
274
   *                false <=> the comparison is '<=' or '>='
275
   *            OUT  The same but for the "F(x) $CMP$ F(const)" comparison
276
   *
277
   * This function is defined only for unary monotonic functions. The caller
278
   * supplies the source half-interval
279
   * 
280
   * x $CMP$ const
281
   *
282
   * The value of const is supplied implicitly as the value this item's
283
   * argument, the form of $CMP$ comparison is specified through the
284
   * function's arguments. The calle returns the result interval
285
   * 
286
   * F(x) $CMP2$ F(const)
287
   *
288
   * passing back F(const) as the return value, and the form of $CMP2$
289
   * through the out parameter. NULL values are assumed to be comparable and
290
   * be less than any non-NULL values.
291
   *
292
   * @retval
293
   *
294
   * The output range bound, which equal to the value of val_int()
295
   * - If the value of the function is NULL then the bound is the
296
   * smallest possible value of INT64_MIN
297
   */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
298
  virtual int64_t val_int_endpoint(bool left_endp, bool *incl_endp);
1 by brian
clean slate
299
300
  /* valXXX methods must return NULL or 0 or 0.0 if null_value is set. */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
301
  /**
302
   * Returns double precision floating point representation of item.
303
   *
304
   * @retval
305
   *
306
   * In case of NULL value return 0.0 and set null_value flag to true.
307
   * If value is not null null_value flag will be reset to false.
308
   */
1 by brian
clean slate
309
  virtual double val_real()=0;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
310
  /**
311
   * Returns integer representation of item.
312
   *
313
   * @retval
314
   * 
315
   * In case of NULL value return 0 and set null_value flag to true.
316
   * If value is not null null_value flag will be reset to false.
317
   */
152 by Brian Aker
longlong replacement
318
  virtual int64_t val_int()=0;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
319
  /**
320
   * This is just a shortcut to avoid the cast. You should still use
321
   * unsigned_flag to check the sign of the item.
322
   */
323
  inline uint64_t val_uint()
324
  {
325
    return (uint64_t) val_int();
326
  }
327
  /**
328
   * Return string representation of this item object.
329
   *
330
   * @param an allocated buffer this or any nested Item object can use to
331
   *        store return value of this method.
332
   *
333
   * @note
334
   *
335
   * Buffer passed via argument  should only be used if the item itself
336
   * doesn't have an own String buffer. In case when the item maintains
337
   * it's own string buffer, it's preferable to return it instead to
338
   * minimize number of mallocs/memcpys.
339
   *
340
   * The caller of this method can modify returned string, but only in case
341
   * when it was allocated on heap, (is_alloced() is true).  This allows
342
   * the caller to efficiently use a buffer allocated by a child without
343
   * having to allocate a buffer of it's own. The buffer, given to
344
   * val_str() as argument, belongs to the caller and is later used by the
345
   * caller at it's own choosing.
346
   *
347
   * A few implications from the above:
348
   *  - unless you return a string object which only points to your buffer
349
   *    but doesn't manages it you should be ready that it will be
350
   *    modified.
351
   *  - even for not allocated strings (is_alloced() == false) the caller
352
   *    can change charset (see Item_func_{typecast/binary}. XXX: is this
353
   *    a bug?
354
   *  - still you should try to minimize data copying and return internal
355
   *    object whenever possible.
356
   *
357
   * @retval
358
   *   In case of NULL value return 0 (NULL pointer) and set null_value flag
359
   *   to true.
360
   *   If value is not null null_value flag will be reset to false.
361
   */
1 by brian
clean slate
362
  virtual String *val_str(String *str)=0;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
363
  /**
364
   * Return decimal representation of item with fixed point.
365
   *
366
   * @param buffer which can be used by Item for returning value
367
   *        (but can be not)
368
   *
369
   * @note
370
   *
371
   * Returned value should not be changed if it is not the same which was
372
   * passed via argument.
373
   *
374
   * @retval
375
   *
376
   * Return pointer on my_decimal (it can be other then passed via argument)
377
   * if value is not NULL (null_value flag will be reset to false).
378
   * In case of NULL value it return 0 pointer and set null_value flag
379
   * to true.
380
   */
1 by brian
clean slate
381
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
382
  /**
383
   * Return boolean value of item.
384
   *
385
   * @retval
386
   *
387
   * false value is false or NULL
388
   * true value is true (not equal to 0)
389
   */
1 by brian
clean slate
390
  virtual bool val_bool();
391
  /* Helper functions, see item_sum.cc */
392
  String *val_string_from_real(String *str);
393
  String *val_string_from_int(String *str);
394
  String *val_string_from_decimal(String *str);
395
  my_decimal *val_decimal_from_real(my_decimal *decimal_value);
396
  my_decimal *val_decimal_from_int(my_decimal *decimal_value);
397
  my_decimal *val_decimal_from_string(my_decimal *decimal_value);
398
  my_decimal *val_decimal_from_date(my_decimal *decimal_value);
399
  my_decimal *val_decimal_from_time(my_decimal *decimal_value);
152 by Brian Aker
longlong replacement
400
  int64_t val_int_from_decimal();
1 by brian
clean slate
401
  double val_real_from_decimal();
402
403
  int save_time_in_field(Field *field);
404
  int save_date_in_field(Field *field);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
405
  /**
406
   * Stores a string value in field directly
407
   *
408
   * @details
409
   *
410
   * The method is used by Item_*::save_in_field implementations
411
   * when we don't need to calculate the value to store
412
   * 
413
   * @see Item_string::save_in_field() implementation for example
414
   *
415
   * @param Pointer to field where to store
416
   * @param Pointer to the string value to be stored
417
   *
418
   * @retval
419
   *  Nonzero value if error
420
   *
421
   */
1 by brian
clean slate
422
  int save_str_value_in_field(Field *field, String *result);
423
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
424
  virtual Field *get_tmp_table_field(void)
425
  {
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
426
    return NULL;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
427
  }
1 by brian
clean slate
428
  /* This is also used to create fields in CREATE ... SELECT: */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
429
  virtual Field *tmp_table_field(Table *t_arg);
430
  virtual const char *full_name(void) const;
1 by brian
clean slate
431
432
  /*
433
    *result* family of methods is analog of *val* family (see above) but
434
    return value of result_field of item if it is present. If Item have not
435
    result field, it return val(). This methods set null_value flag in same
436
    way as *val* methods do it.
437
  */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
438
  virtual double  val_result() 
439
  {
440
    return val_real();
441
  }
442
  virtual int64_t val_int_result()
443
  {
444
    return val_int();
445
  }
446
  virtual String *str_result(String* tmp)
447
  {
448
    return val_str(tmp);
449
  }
1 by brian
clean slate
450
  virtual my_decimal *val_decimal_result(my_decimal *val)
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
451
  {
452
    return val_decimal(val);
453
  }
454
  virtual bool val_bool_result()
455
  {
456
    return val_bool();
457
  }
458
  /**
459
   * Returns bit map of tables used by item
460
   */
461
  virtual table_map used_tables() const
462
  {
463
    return (table_map) 0L;
464
  }
465
  /**
1 by brian
clean slate
466
    Return table map of tables that can't be NULL tables (tables that are
467
    used in a context where if they would contain a NULL row generated
468
    by a LEFT or RIGHT join, the item would not be true).
469
    This expression is used on WHERE item to determinate if a LEFT JOIN can be
470
    converted to a normal join.
471
    Generally this function should return used_tables() if the function
472
    would return null if any of the arguments are null
473
    As this is only used in the beginning of optimization, the value don't
474
    have to be updated in update_used_tables()
475
  */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
476
  virtual table_map not_null_tables() const
477
  {
478
    return used_tables();
479
  }
480
  /**
1 by brian
clean slate
481
    Returns true if this is a simple constant item like an integer, not
482
    a constant expression. Used in the optimizer to propagate basic constants.
483
  */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
484
  virtual bool basic_const_item() const
485
  {
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
486
    return false;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
487
  }
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
488
  /* cloning of constant items (NULL if it is not const) */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
489
  virtual Item *clone_item()
490
  {
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
491
    return NULL;
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
492
  }
493
  virtual cond_result eq_cmp_result() const
494
  {
495
    return COND_OK;
496
  }
482 by Brian Aker
Remove uint.
497
  inline uint32_t float_length(uint32_t decimals_par) const
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
498
  {
499
    return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;
500
  }
482 by Brian Aker
Remove uint.
501
  virtual uint32_t decimal_precision() const;
584.1.14 by Monty Taylor
Removed field.h from common_includes.
502
  int decimal_int_part() const;
503
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
504
  /**
1 by brian
clean slate
505
    Returns true if this is constant (during query execution, i.e. its value
506
    will not change until next fix_fields) and its value is known.
507
  */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
508
  virtual bool const_item() const
509
  {
510
    return used_tables() == 0;
511
  }
512
  /**
1 by brian
clean slate
513
    Returns true if this is constant but its value may be not known yet.
514
    (Can be used for parameters of prep. stmts or of stored procedures.)
515
  */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
516
  virtual bool const_during_execution() const
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
517
  {
518
    return (used_tables() & ~PARAM_TABLE_BIT) == 0;
519
  }
1 by brian
clean slate
520
521
  /**
522
    This method is used for to:
523
      - to generate a view definition query (SELECT-statement);
524
      - to generate a SQL-query for EXPLAIN EXTENDED;
525
      - to generate a SQL-query to be shown in INFORMATION_SCHEMA;
526
      - debug.
527
528
    For more information about view definition query, INFORMATION_SCHEMA
529
    query and why they should be generated from the Item-tree, @see
530
    mysql_register_view().
531
  */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
532
  virtual void print(String *str, enum_query_type query_type);
1 by brian
clean slate
533
534
  void print_item_w_name(String *, enum_query_type query_type);
535
  virtual void update_used_tables() {}
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
536
  virtual void split_sum_func(Session *session, 
537
                              Item **ref_pointer_array,
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
538
                              List<Item> &fields);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
539
  /**
540
    Move SUM items out from item tree and replace with reference.
541
542
    @param session			Thread handler
543
    @param ref_pointer_array	Pointer to array of reference fields
544
    @param fields		All fields in select
545
    @param ref			Pointer to item
546
    @param skip_registered       <=> function be must skipped for registered
547
                                SUM items
548
549
    @note
550
      This is from split_sum_func() for items that should be split
551
552
      All found SUM items are added FIRST in the fields list and
553
      we replace the item with a reference.
554
555
      session->fatal_error() may be called if we are out of memory
556
  */
557
  void split_sum_func(Session *session, 
558
                      Item **ref_pointer_array,
779.3.18 by Monty Taylor
Cleaned up warnings up through innodb.
559
                      List<Item> &fields,
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
560
                      Item **ref, 
561
                      bool skip_registered);
584.4.9 by Monty Taylor
Renamed split_sum_func2 to split_sum_func. It's C++.
562
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
563
  /**
564
    Get the value of the function as a DRIZZLE_TIME structure.
565
    As a extra convenience the time structure is reset on error!
566
  */
482 by Brian Aker
Remove uint.
567
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
568
  /**
569
    Get time of first argument.
570
571
    As a extra convenience the time structure is reset on error!
572
  */
236.1.24 by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME.
573
  virtual bool get_time(DRIZZLE_TIME *ltime);
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
574
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
575
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
576
  /**
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
577
    The method allows to determine nullness of a complex expression
578
    without fully evaluating it, instead of calling val/result*() then
1 by brian
clean slate
579
    checking null_value. Used in Item_func_isnull/Item_func_isnotnull
580
    and Item_sum_count/Item_sum_count_distinct.
581
    Any new item which can be NULL must implement this method.
582
  */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
583
  virtual bool is_null();
1 by brian
clean slate
584
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
585
  /** Make sure the null_value member has a correct value. */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
586
  virtual void update_null_value ();
1 by brian
clean slate
587
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
588
  /**
1 by brian
clean slate
589
    Inform the item that there will be no distinction between its result
163 by Brian Aker
Merge Monty's code.
590
    being false or NULL.
1 by brian
clean slate
591
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
592
    @note
593
1 by brian
clean slate
594
      This function will be called for eg. Items that are top-level AND-parts
595
      of the WHERE clause. Items implementing this function (currently
596
      Item_cond_and and subquery-related item) enable special optimizations
597
      when they are "top level".
598
  */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
599
  virtual void top_level_item(void);
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
600
  /**
601
   * Sets field of temporary table for Item which can be switched on temporary
602
   * table during query processing (grouping and so on)
603
   */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
604
  virtual void set_result_field(Field *field);
605
  virtual bool is_result_field(void);
606
  virtual bool is_bool_func(void);
607
  virtual void save_in_result_field(bool no_conversions);
608
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
609
  /**
610
   * Sets value of aggregate function in case of no rows for grouping were found
611
   */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
612
  virtual void no_rows_in_result(void);
613
  virtual Item *copy_or_same(Session *session);
614
615
  virtual Item *copy_andor_structure(Session *session);
616
617
  virtual Item *real_item(void);
779.3.10 by Monty Taylor
Turned on -Wshadow.
618
  virtual const Item *real_item(void) const;
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
619
  virtual Item *get_tmp_table_item(Session *session);
1 by brian
clean slate
620
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
621
  static const CHARSET_INFO *default_charset();
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
622
  virtual const CHARSET_INFO *compare_collation();
1 by brian
clean slate
623
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
624
  virtual bool walk(Item_processor processor,
625
                    bool walk_subquery,
626
                    unsigned char *arg);
1 by brian
clean slate
627
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
628
  /**
629
    Traverse item tree possibly transforming it (replacing items).
630
631
    If you don't need to transform an item tree, but only traverse
632
    it, please use Item::walk() instead.
633
634
    @param transformer    functor that performs transformation of a subtree
635
    @param arg            opaque argument passed to the functor
636
637
    @return
638
      Returns pointer to the new subtree root.  Session::change_item_tree()
639
      should be called for it if transformation took place, i.e. if a
640
      pointer to newly allocated item is returned.
641
  */
481 by Brian Aker
Remove all of uchar.
642
  virtual Item* transform(Item_transformer transformer, unsigned char *arg);
1 by brian
clean slate
643
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
644
  /**
1 by brian
clean slate
645
    This function performs a generic "compilation" of the Item tree.
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
646
    The process of compilation is assumed to go as follows:
647
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
648
    @code
1 by brian
clean slate
649
    compile()
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
650
    {
1 by brian
clean slate
651
      if (this->*some_analyzer(...))
652
      {
653
        compile children if any;
654
        this->*some_transformer(...);
655
      }
656
    }
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
657
    @endcode
1 by brian
clean slate
658
659
    i.e. analysis is performed top-down while transformation is done
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
660
    bottom-up.
1 by brian
clean slate
661
  */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
662
  virtual Item* compile(Item_analyzer analyzer, 
663
                        unsigned char **arg_p,
664
                        Item_transformer transformer, 
665
                        unsigned char *arg_t);
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
666
667
  virtual void traverse_cond(Cond_traverser traverser,
668
                             void *arg,
669
                             traverse_order order);
670
671
  virtual bool remove_dependence_processor(unsigned char * arg);
672
  virtual bool remove_fixed(unsigned char * arg);
673
  virtual bool collect_item_field_processor(unsigned char * arg);
674
  virtual bool find_item_in_field_list_processor(unsigned char *arg);
675
  virtual bool change_context_processor(unsigned char *context);
676
  virtual bool reset_query_id_processor(unsigned char *query_id_arg);
677
  virtual bool register_field_in_read_map(unsigned char *arg);
678
  virtual bool subst_argument_checker(unsigned char **arg);
1 by brian
clean slate
679
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
680
  virtual Item *equal_fields_propagator(unsigned char * arg);
681
  virtual bool set_no_const_sub(unsigned char *arg);
682
  virtual Item *replace_equal_field(unsigned char * arg);
1 by brian
clean slate
683
684
  // Row emulation
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
685
  virtual uint32_t cols();
686
  virtual Item* element_index(uint32_t i);
687
  virtual Item** addr(uint32_t i);
482 by Brian Aker
Remove uint.
688
  virtual bool check_cols(uint32_t c);
1 by brian
clean slate
689
  // It is not row => null inside is impossible
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
690
  virtual bool null_inside();
1 by brian
clean slate
691
  // used in row subselects to get value of elements
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
692
  virtual void bring_value();
1 by brian
clean slate
693
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
694
  /**
695
    Create a field based on field_type of argument.
696
697
    For now, this is only used to create a field for
698
    IFNULL(x,something) and time functions
699
700
    @retval
701
      NULL  error
702
    @retval
703
      \#    Created field
704
  */
327.1.5 by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h
705
  Field *tmp_table_field_from_field_type(Table *table, bool fixed_length);
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
706
  virtual Item_field *filed_for_view_update();
1 by brian
clean slate
707
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
708
  virtual Item *neg_transformer(Session *session);
709
  virtual Item *update_value_transformer(unsigned char *select_arg);
264.2.6 by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code.
710
  virtual Item *safe_charset_converter(const CHARSET_INFO * const tocs);
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
711
  void delete_self();
1 by brian
clean slate
712
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
713
  /**
714
   * Returns true for Items representing DATE/TIME functions and DATE/TIME table fields.
715
   * Those Items have result_type()==STRING_RESULT (and not INT_RESULT), but
716
   * their values should be compared as integers (because the integer
717
   * representation is more precise than the string one).
718
   */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
719
  virtual bool result_as_int64_t();
1 by brian
clean slate
720
  bool is_datetime();
721
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
722
  /**
723
   * Tests whether an expression is expensive to compute. Used during
724
   * optimization to avoid computing expensive expressions during this
725
   * phase. Also used to force temp tables when sorting on expensive
726
   * functions.
727
   *
728
   * @todo
729
   * 
730
   * Normally we should have a method:
731
   * cost Item::execution_cost(),
732
   * where 'cost' is either 'double' or some structure of various cost
733
   * parameters.
734
   */
584.4.8 by Monty Taylor
Moved stuff from item.h to item.cc
735
  virtual bool is_expensive();
736
1 by brian
clean slate
737
  String *check_well_formed_result(String *str, bool send_error= 0);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
738
  /**
739
   * Compares two items using a given collation
740
   *
741
   * @details
742
   *
743
   *  This method works exactly as Item::eq if the collation cs coincides with
744
   *  the collation of the compared objects. Otherwise, first the collations that
745
   *  differ from cs are replaced for cs and then the items are compared by
746
   *  Item::eq. After the comparison the original collations of items are
747
   *  restored.
748
   *
749
   * @param Pointer to the item to compare with
750
   * @param Compare as binary?
751
   * @param Pointer to the collation to use when comparing strings
752
   *
753
   * @retval
754
   *  true if compared items has been detected as equal
755
   * @retval
756
   *  false otherwise
757
   */
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
758
  bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
1 by brian
clean slate
759
};
760
642.1.1 by Lee
move functions from item.cc/item.h to item directory
761
#include <drizzled/item/ident.h>
762
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
763
/**
764
  Mark item and Select_Lexs as dependent if item was resolved in
765
  outer SELECT.
766
767
  @param session             thread handler
768
  @param last            select from which current item depend
769
  @param current         current select
770
  @param resolved_item   item which was resolved in outer SELECT(for warning)
771
  @param mark_item       item which should be marked (can be differ in case of
772
                         substitution)
773
*/
656.1.6 by Monty Taylor
Merged in Eric's whitespace cleanup.
774
void mark_as_dependent(Session *session,
846 by Brian Aker
Removing on typedeffed class.
775
		       Select_Lex *last,
776
                       Select_Lex *current,
642.1.1 by Lee
move functions from item.cc/item.h to item directory
777
                       Item_ident *resolved_item,
778
                       Item_ident *mark_item);
779
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
780
/**
781
  Resolve a column reference in a sub-select.
782
783
  Resolve a column reference (usually inside a HAVING clause) against the
784
  SELECT and GROUP BY clauses of the query described by 'select'. The name
785
  resolution algorithm searches both the SELECT and GROUP BY clauses, and in
786
  case of a name conflict prefers GROUP BY column names over SELECT names. If
787
  both clauses contain different fields with the same names, a warning is
788
  issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no
789
  GROUP BY column is found, then a HAVING name is resolved as a possibly
790
  derived SELECT column. This extension is allowed only if the
791
  MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled.
792
793
  @param session     current thread
794
  @param ref     column reference being resolved
795
  @param select  the select that ref is resolved against
796
797
  @note
798
    The resolution procedure is:
799
    - Search for a column or derived column named col_ref_i [in table T_j]
800
    in the SELECT clause of Q.
801
    - Search for a column named col_ref_i [in table T_j]
802
    in the GROUP BY clause of Q.
803
    - If found different columns with the same name in GROUP BY and SELECT
804
    - issue a warning and return the GROUP BY column,
805
    - otherwise
806
    - if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error
807
    - else return the found SELECT column.
808
809
810
  @return
811
    - NULL - there was an error, and the error was already reported
812
    - not_found_item - the item was not resolved, no error was reported
813
    - resolved item - if the item was resolved
814
*/
815
Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select);
816
817
/**
818
  Mark range of selects and resolved identifier (field/reference)
819
  item as dependent.
820
821
  @param session             thread handler
822
  @param last_select     select where resolved_item was resolved
823
  @param current_sel     current select (select where resolved_item was placed)
824
  @param found_field     field which was found during resolving
825
  @param found_item      Item which was found during resolving (if resolved
826
                         identifier belongs to VIEW)
827
  @param resolved_item   Identifier which was resolved
828
829
  @note
830
    We have to mark all items between current_sel (including) and
831
    last_select (excluding) as dependend (select before last_select should
832
    be marked with actual table mask used by resolved item, all other with
833
    OUTER_REF_TABLE_BIT) and also write dependence information to Item of
834
    resolved identifier.
835
*/
520.1.22 by Brian Aker
Second pass of thd cleanup
836
void mark_select_range_as_dependent(Session *session,
846 by Brian Aker
Removing on typedeffed class.
837
                                    Select_Lex *last_select,
838
                                    Select_Lex *current_sel,
1 by brian
clean slate
839
                                    Field *found_field, Item *found_item,
840
                                    Item_ident *resolved_item);
841
520.1.22 by Brian Aker
Second pass of thd cleanup
842
extern void resolve_const_item(Session *session, Item **ref, Item *cmp_item);
1055.2.12 by Jay Pipes
Documentation and style cleanup on Item class
843
/**
844
  Return true if the value stored in the field is equal to the const
845
  item.
846
847
  We need to use this on the range optimizer because in some cases
848
  we can't store the value in the field without some precision/character loss.
849
*/
1 by brian
clean slate
850
extern bool field_is_equal_to_item(Field *field,Item *item);
489.1.8 by Monty Taylor
Split out Item_int_func and Item_func from Item_func. (don't think too hard about the second one)
851
575.4.7 by Monty Taylor
More header cleanup.
852
/**
853
  Create field for temporary table.
854
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
855
  @todo: 
856
  
857
   This is here for now because it needs the Item::Type. It should live
858
   in Field or Table once item.h is clean enough to actually include
859
575.4.7 by Monty Taylor
More header cleanup.
860
  @param session		Thread handler
861
  @param table		Temporary table
862
  @param item		Item to create a field for
863
  @param type		Type of item (normally item->type)
864
  @param copy_func	If set and item is a function, store copy of item
865
                       in this array
866
  @param from_field    if field will be created using other field as example,
867
                       pointer example field will be written here
868
  @param default_field	If field has a default value field, store it here
869
  @param group		1 if we are going to do a relative group by on result
870
  @param modify_item	1 if item->result_field should point to new item.
871
                       This is relevent for how fill_record() is going to
872
                       work:
873
                       If modify_item is 1 then fill_record() will update
874
                       the record in the original table.
875
                       If modify_item is 0 then fill_record() will update
876
                       the temporary table
877
  @param convert_blob_length If >0 create a varstring(convert_blob_length)
878
                             field instead of blob.
879
880
  @retval
881
    0			on error
882
  @retval
883
    new_created field
884
*/
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
885
Field *create_tmp_field(Session *session,
886
                        Table *table, 
887
                        Item *item,
575.4.7 by Monty Taylor
More header cleanup.
888
                        Item::Type type,
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
889
                        Item ***copy_func, 
890
                        Field **from_field,
575.4.7 by Monty Taylor
More header cleanup.
891
                        Field **def_field,
1055.2.11 by Jay Pipes
Adds documentation to Item class members and methods. Style and indentation cleanup in item.h
892
                        bool group, 
893
                        bool modify_item,
575.4.7 by Monty Taylor
More header cleanup.
894
                        bool table_cant_handle_bit_fields,
895
                        bool make_copy_field,
896
                        uint32_t convert_blob_length);
897
584.4.4 by Monty Taylor
Split out Name_resolution_context.
898
#endif /* DRIZZLED_ITEM_H */