~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/item.h

  • Committer: Monty Taylor
  • Date: 2008-11-15 18:39:51 UTC
  • mto: (584.1.7 devel)
  • mto: This revision was merged to the branch mainline in revision 588.
  • Revision ID: monty@inaugust.com-20081115183951-jo2v3abwdu24lnwq
Split out hybrid_type_traits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
class Item_field;
29
29
 
30
30
 
31
 
/*************************************************************************/
32
 
/*
33
 
  A framework to easily handle different return types for hybrid items
34
 
  (hybrid item is an item whose operand can be of any type, e.g. integer,
35
 
  real, decimal).
36
 
*/
37
 
 
38
 
struct Hybrid_type_traits;
39
 
 
40
 
struct Hybrid_type
41
 
{
42
 
  int64_t integer;
43
 
 
44
 
  double real;
45
 
  /*
46
 
    Use two decimal buffers interchangeably to speed up += operation
47
 
    which has no native support in decimal library.
48
 
    Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
49
 
    The third decimal is used as a handy temporary storage.
50
 
  */
51
 
  my_decimal dec_buf[3];
52
 
  int used_dec_buf_no;
53
 
 
54
 
  /*
55
 
    Traits moved to a separate class to
56
 
      a) be able to easily change object traits in runtime
57
 
      b) they work as a differentiator for the union above
58
 
  */
59
 
  const Hybrid_type_traits *traits;
60
 
 
61
 
  Hybrid_type() {}
62
 
  /* XXX: add traits->copy() when needed */
63
 
  Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
64
 
};
65
 
 
66
 
 
67
 
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
68
 
 
69
 
struct Hybrid_type_traits
70
 
{
71
 
  virtual Item_result type() const { return REAL_RESULT; }
72
 
 
73
 
  virtual void
74
 
  fix_length_and_dec(Item *item, Item *arg) const;
75
 
 
76
 
  /* Hybrid_type operations. */
77
 
  virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
78
 
  virtual void add(Hybrid_type *val, Field *f) const
79
 
  { val->real+= f->val_real(); }
80
 
  virtual void div(Hybrid_type *val, uint64_t u) const
81
 
  { val->real/= uint64_t2double(u); }
82
 
 
83
 
  virtual int64_t val_int(Hybrid_type *val,
84
 
                          bool unsigned_flag) const;
85
 
  virtual double val_real(Hybrid_type *val) const { return val->real; }
86
 
  virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
87
 
  virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
88
 
  static const Hybrid_type_traits *instance();
89
 
  Hybrid_type_traits() {}
90
 
  virtual ~Hybrid_type_traits() {}
91
 
};
92
 
 
93
 
 
94
 
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
95
 
{
96
 
  virtual Item_result type() const { return DECIMAL_RESULT; }
97
 
 
98
 
  virtual void
99
 
  fix_length_and_dec(Item *arg, Item *item) const;
100
 
 
101
 
  /* Hybrid_type operations. */
102
 
  virtual void set_zero(Hybrid_type *val) const;
103
 
  virtual void add(Hybrid_type *val, Field *f) const;
104
 
  virtual void div(Hybrid_type *val, uint64_t u) const;
105
 
 
106
 
  virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
107
 
  virtual double val_real(Hybrid_type *val) const;
108
 
  virtual my_decimal *val_decimal(Hybrid_type *val,
109
 
                                  my_decimal *buf __attribute__((unused))) const
110
 
  { return &val->dec_buf[val->used_dec_buf_no]; }
111
 
  virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
112
 
  static const Hybrid_type_traits_decimal *instance();
113
 
  Hybrid_type_traits_decimal() {};
114
 
};
115
 
 
116
 
 
117
 
struct Hybrid_type_traits_integer: public Hybrid_type_traits
118
 
{
119
 
  virtual Item_result type() const { return INT_RESULT; }
120
 
 
121
 
  virtual void
122
 
  fix_length_and_dec(Item *arg, Item *item) const;
123
 
 
124
 
  /* Hybrid_type operations. */
125
 
  virtual void set_zero(Hybrid_type *val) const
126
 
  { val->integer= 0; }
127
 
  virtual void add(Hybrid_type *val, Field *f) const
128
 
  { val->integer+= f->val_int(); }
129
 
  virtual void div(Hybrid_type *val, uint64_t u) const
130
 
  { val->integer/= (int64_t) u; }
131
 
 
132
 
  virtual int64_t val_int(Hybrid_type *val,
133
 
                           bool unsigned_flag __attribute__((unused))) const
134
 
  { return val->integer; }
135
 
  virtual double val_real(Hybrid_type *val) const
136
 
  { return (double) val->integer; }
137
 
  virtual my_decimal *val_decimal(Hybrid_type *val,
138
 
                                  my_decimal *buf __attribute__((unused))) const
139
 
  {
140
 
    int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
141
 
    return &val->dec_buf[2];
142
 
  }
143
 
  virtual String *val_str(Hybrid_type *val, String *buf,
144
 
                          uint8_t decimals __attribute__((unused))) const
145
 
  { buf->set(val->integer, &my_charset_bin); return buf;}
146
 
  static const Hybrid_type_traits_integer *instance();
147
 
  Hybrid_type_traits_integer() {};
148
 
};
149
 
 
150
 
 
151
31
void dummy_error_processor(Session *session, void *data);
152
32
 
153
33
void view_error_processor(Session *session, void *data);
297
177
};
298
178
 
299
179
 
300
 
/*
301
 
  This enum is used to report information about monotonicity of function
302
 
  represented by Item* tree.
303
 
  Monotonicity is defined only for Item* trees that represent table
304
 
  partitioning expressions (i.e. have no subselects/user vars/PS parameters
305
 
  etc etc). An Item* tree is assumed to have the same monotonicity properties
306
 
  as its correspoinding function F:
307
 
 
308
 
  [signed] int64_t F(field1, field2, ...) {
309
 
    put values of field_i into table record buffer;
310
 
    return item->val_int(); 
311
 
  }
312
 
 
313
 
  NOTE
314
 
  At the moment function monotonicity is not well defined (and so may be
315
 
  incorrect) for Item trees with parameters/return types that are different
316
 
  from INT_RESULT, may be NULL, or are unsigned.
317
 
  It will be possible to address this issue once the related partitioning bugs
318
 
  (BUG#16002, BUG#15447, BUG#13436) are fixed.
319
 
*/
320
 
 
321
 
typedef enum monotonicity_info 
322
 
{
323
 
   NON_MONOTONIC,              /* none of the below holds */
324
 
   MONOTONIC_INCREASING,       /* F() is unary and (x < y) => (F(x) <= F(y)) */
325
 
   MONOTONIC_STRICT_INCREASING /* F() is unary and (x < y) => (F(x) <  F(y)) */
326
 
} enum_monotonicity_info;
327
 
 
328
180
/*************************************************************************/
329
 
typedef bool (Item::*Item_processor) (unsigned char *arg);
330
181
/*
331
182
  Analyzer function
332
183
    SYNOPSIS
333
184
      argp   in/out IN:  Analysis parameter
334
185
                    OUT: Parameter to be passed to the transformer
335
186
 
336
 
    RETURN 
 
187
     RETURN
337
188
      true   Invoke the transformer
338
189
      false  Don't do it
339
190
 
341
192
typedef bool (Item::*Item_analyzer) (unsigned char **argp);
342
193
typedef Item* (Item::*Item_transformer) (unsigned char *arg);
343
194
typedef void (*Cond_traverser) (const Item *item, void *arg);
 
195
typedef bool (Item::*Item_processor) (unsigned char *arg);
344
196
 
345
197
 
346
198
class Item