~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Padraig O'Sullivan
  • Date: 2009-12-17 04:48:59 UTC
  • mto: This revision was merged to the branch mainline in revision 1246.
  • Revision ID: osullivan.padraig@gmail.com-20091217044859-qorpkp4911zypfv3
Added some dtrace probes for tracing the optimizer.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
17
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
18
 */
19
19
 
20
 
 
21
 
 
22
20
#ifndef DRIZZLED_ITEM_H
23
21
#define DRIZZLED_ITEM_H
24
22
 
25
 
#include <drizzled/global_charset_info.h>
26
23
#include <drizzled/dtcollation.h>
 
24
#include <mysys/drizzle_time.h>
 
25
#include <drizzled/my_decimal.h>
 
26
#include <drizzled/sql_bitmap.h>
27
27
#include <drizzled/sql_list.h>
28
 
#include <drizzled/sql_string.h>
29
 
#include <drizzled/memory/sql_alloc.h>
30
 
#include <drizzled/item_result.h>
31
 
 
32
 
#include "drizzled/visibility.h"
33
 
 
34
 
namespace drizzled
35
 
{
36
 
 
37
 
class Field;
 
28
#include <drizzled/sql_alloc.h>
 
29
#include <drizzled/table.h>
 
30
 
 
31
class TableList;
 
32
class Item_field;
 
33
class Name_resolution_context;
 
34
class Select_Lex;
38
35
class Item_equal;
39
 
class Item_field;
40
 
class Item_ident;
 
36
class user_var_entry;
 
37
class Item_sum;
41
38
class Item_in_subselect;
42
 
class Item_sum;
43
 
class Select_Lex;
44
39
class SendField;
45
 
class Table;
46
 
class user_var_entry;
 
40
class Field;
47
41
 
48
 
namespace plugin { class Client; }
49
 
namespace type { class Time; }
50
 
namespace type { class Decimal; }
 
42
namespace drizzled
 
43
{
 
44
namespace plugin
 
45
{
 
46
class Client;
 
47
}
 
48
}
51
49
 
52
50
/**
53
51
  Dummy error processor used by default by Name_resolution_context.
78
76
 * statement "tree" or Lex.  Each item represents something in the
79
77
 * execution plan.
80
78
 */
81
 
class DRIZZLED_API Item : public memory::SqlAlloc
 
79
class Item: public Sql_alloc
82
80
{
83
81
  /* Prevent use of these */
84
82
  Item(const Item &);
113
111
    ROW_ITEM, CACHE_ITEM,
114
112
    TYPE_HOLDER,
115
113
    PARAM_ITEM,
116
 
    BOOLEAN_ITEM,
117
114
    DECIMAL_ITEM
118
115
  };
119
116
  enum traverse_order
137
134
 
138
135
  /** Name from select */
139
136
  char *name;
140
 
 
141
137
  /** Length of name */
142
138
  uint32_t name_length;
143
139
 
152
148
  bool maybe_null; /**< True if item may be null */
153
149
  bool null_value; /**< True if item is null */
154
150
  bool unsigned_flag;
155
 
 
156
 
  bool is_unsigned() const
157
 
  {
158
 
    return unsigned_flag;
159
 
  }
160
 
 
161
 
  virtual bool negative() const
162
 
  {
163
 
    return false;
164
 
  }
165
 
 
166
151
  bool with_sum_func;
167
152
  bool is_autogenerated_name; /**< indicates whether name of this Item was autogenerated or set by user */
168
 
 
169
153
  /**
170
154
   * If this item is a subselect or some of its arguments is or contains a
171
155
   * subselect. Computed by fix_fields.
173
157
  bool with_subselect;
174
158
  DTCollation collation;
175
159
  Item_result cmp_context; /**< Comparison context */
176
 
 
177
160
  /**
178
161
   * Constructor
179
162
   *
180
163
   * @note
181
164
   *
182
 
   * Alloc & destruct is done as start of select using memory::sql_alloc
 
165
   * Alloc & destruct is done as start of select using sql_alloc
183
166
   */
184
167
  Item();
185
 
 
186
168
  /**
187
169
   * Constructor used by Item_field, Item_ref & aggregate (sum) functions.
188
170
   *
194
176
   * optimisation changes in prepared statements
195
177
   */
196
178
  Item(Session *session, Item *item);
197
 
 
198
179
  virtual ~Item()
199
180
  {
200
181
#ifdef EXTRA_DEBUG
201
 
    name= NULL;
 
182
    name=0;
202
183
#endif
203
184
  }
204
 
 
205
 
  void set_name(const std::string &arg)
206
 
  {
207
 
    set_name(arg.c_str(), arg.length(), system_charset_info);
208
 
  }
209
 
 
210
 
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs= system_charset_info);
 
185
  void set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs);
211
186
  /**
212
187
   * Renames item (used for views, cleanup() return original name).
213
188
   *
244
219
    fixed= true;
245
220
  }
246
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 optimizer/range to adjust the key value to fit the column.
 
229
   * Return: Function returns 1 on overflow and -1 on fatal errors
 
230
   */
 
231
  int save_in_field_no_warnings(Field *field, bool no_conversions);
 
232
 
247
233
  virtual int save_in_field(Field *field, bool no_conversions);
248
234
  virtual void save_org_in_field(Field *field)
249
235
  {
256
242
  /**
257
243
   * This is only called from items that is not of type item_field.
258
244
   */
259
 
  virtual bool send(plugin::Client *client, String *str);
 
245
  virtual bool send(drizzled::plugin::Client *client, String *str);
260
246
  /**
261
247
    Compares this Item to another Item, returning true if Item's
262
248
    are functionally equal.
381
367
   *   If value is not null null_value flag will be reset to false.
382
368
   */
383
369
  virtual String *val_str(String *str)=0;
384
 
 
385
370
  /**
386
371
   * Return decimal representation of item with fixed point.
387
372
   *
395
380
   *
396
381
   * @retval
397
382
   *
398
 
   * Return pointer on type::Decimal (it can be other then passed via argument)
 
383
   * Return pointer on my_decimal (it can be other then passed via argument)
399
384
   * if value is not NULL (null_value flag will be reset to false).
400
385
   * In case of NULL value it return 0 pointer and set null_value flag
401
386
   * to true.
402
387
   */
403
 
  virtual type::Decimal *val_decimal(type::Decimal *decimal_buffer)= 0;
404
 
 
 
388
  virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
405
389
  /**
406
390
   * Return boolean value of item.
407
391
   *
411
395
   * true value is true (not equal to 0)
412
396
   */
413
397
  virtual bool val_bool();
414
 
 
415
398
  /* Helper functions, see item_sum.cc */
416
399
  String *val_string_from_real(String *str);
417
400
  String *val_string_from_int(String *str);
418
401
  String *val_string_from_decimal(String *str);
419
 
  type::Decimal *val_decimal_from_real(type::Decimal *decimal_value);
420
 
  type::Decimal *val_decimal_from_int(type::Decimal *decimal_value);
421
 
  type::Decimal *val_decimal_from_string(type::Decimal *decimal_value);
422
 
  type::Decimal *val_decimal_from_date(type::Decimal *decimal_value);
423
 
  type::Decimal *val_decimal_from_time(type::Decimal *decimal_value);
 
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);
424
407
  int64_t val_int_from_decimal();
425
408
  double val_real_from_decimal();
426
409
 
427
 
  bool save_time_in_field(Field *field);
428
 
  bool save_date_in_field(Field *field);
429
 
 
 
410
  int save_time_in_field(Field *field);
 
411
  int save_date_in_field(Field *field);
430
412
  /**
431
413
   * Stores a string value in field directly
432
414
   *
472
454
  {
473
455
    return val_str(tmp);
474
456
  }
475
 
  virtual type::Decimal *val_decimal_result(type::Decimal *val)
 
457
  virtual my_decimal *val_decimal_result(my_decimal *val)
476
458
  {
477
459
    return val_decimal(val);
478
460
  }
519
501
  {
520
502
    return COND_OK;
521
503
  }
522
 
  uint32_t float_length(uint32_t decimals_par) const;
 
504
  inline uint32_t float_length(uint32_t decimals_par) const
 
505
  {
 
506
    return decimals != NOT_FIXED_DEC ? (DBL_DIG+2+decimals_par) : DBL_DIG+8;
 
507
  }
523
508
  virtual uint32_t decimal_precision() const;
524
509
  int decimal_int_part() const;
525
510
 
549
534
 
550
535
    For more information about view definition query, INFORMATION_SCHEMA
551
536
    query and why they should be generated from the Item-tree, @see
552
 
    register_view().
 
537
    mysql_register_view().
553
538
  */
554
539
  virtual void print(String *str, enum_query_type query_type);
555
540
 
583
568
                      bool skip_registered);
584
569
 
585
570
  /**
586
 
    Get the value of the function as a type::Time structure.
 
571
    Get the value of the function as a DRIZZLE_TIME structure.
587
572
    As a extra convenience the time structure is reset on error!
588
573
  */
589
 
  virtual bool get_date(type::Time &ltime, uint32_t fuzzydate);
 
574
  virtual bool get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
590
575
  /**
591
576
    Get time of first argument.
592
577
 
593
578
    As a extra convenience the time structure is reset on error!
594
579
  */
595
 
  virtual bool get_time(type::Time &ltime);
596
 
  virtual bool get_date_result(type::Time &ltime,uint32_t fuzzydate);
 
580
  virtual bool get_time(DRIZZLE_TIME *ltime);
 
581
  virtual bool get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate);
597
582
 
598
583
  /**
599
584
    The method allows to determine nullness of a complex expression
695
680
  virtual bool collect_item_field_processor(unsigned char * arg);
696
681
  virtual bool find_item_in_field_list_processor(unsigned char *arg);
697
682
  virtual bool change_context_processor(unsigned char *context);
 
683
  virtual bool reset_query_id_processor(unsigned char *query_id_arg);
698
684
  virtual bool register_field_in_read_map(unsigned char *arg);
699
685
  virtual bool subst_argument_checker(unsigned char **arg);
700
686
 
701
 
  virtual bool cache_const_expr_analyzer(unsigned char **arg);
702
 
  virtual Item* cache_const_expr_transformer(unsigned char *arg);
703
 
 
704
687
  virtual Item *equal_fields_propagator(unsigned char * arg);
705
688
  virtual bool set_no_const_sub(unsigned char *arg);
706
689
  virtual Item *replace_equal_field(unsigned char * arg);
754
737
   * cost Item::execution_cost(),
755
738
   * where 'cost' is either 'double' or some structure of various cost
756
739
   * parameters.
757
 
   *
758
 
   *NOTE
759
 
   *   This function is now used to prevent evaluation of materialized IN
760
 
   *   subquery predicates before it is allowed. grep for
761
 
   *   DontEvaluateMaterializedSubqueryTooEarly to see the uses.
762
740
   */
763
741
  virtual bool is_expensive();
764
742
 
784
762
   *  false otherwise
785
763
   */
786
764
  bool eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs);
787
 
 
788
 
  inline uint32_t char_to_byte_length_safe(uint32_t char_length_arg, uint32_t mbmaxlen_arg)
789
 
  { 
790
 
    uint64_t tmp= ((uint64_t) char_length_arg) * mbmaxlen_arg;
791
 
    return (tmp > UINT32_MAX) ? (uint32_t) UINT32_MAX : (uint32_t) tmp;
792
 
  } 
793
 
 
794
 
  uint32_t max_char_length() const;
795
 
 
796
 
  void fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs);
797
 
  void fix_char_length(uint32_t max_char_length_arg);
798
 
  void fix_char_length_uint64_t(uint64_t max_char_length_arg);
799
 
  void fix_length_and_charset_datetime(uint32_t max_char_length_arg);
800
 
 
801
 
protected:
802
 
  Session &getSession()
803
 
  {
804
 
    return _session;
805
 
  }
806
 
 
807
 
private:
808
 
  Session &_session;
809
765
};
810
766
 
811
 
namespace display {
812
 
const std::string &type(Item::Type type);
813
 
} /* namespace display */
814
 
 
815
 
std::ostream& operator<<(std::ostream& output, const Item &item);
816
 
 
817
 
} /* namespace drizzled */
818
 
 
819
 
/** @TODO Why is this in the middle? */
820
767
#include <drizzled/item/ident.h>
821
768
 
822
 
namespace drizzled
823
 
{
824
 
 
825
769
/**
826
770
  Mark item and Select_Lexs as dependent if item was resolved in
827
771
  outer SELECT.
953
897
                        Field **def_field,
954
898
                        bool group,
955
899
                        bool modify_item,
 
900
                        bool table_cant_handle_bit_fields,
956
901
                        bool make_copy_field,
957
902
                        uint32_t convert_blob_length);
958
903
 
959
 
} /* namespace drizzled */
960
 
 
961
904
#endif /* DRIZZLED_ITEM_H */