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