20
20
#ifndef drizzled_item_h
21
21
#define drizzled_item_h
23
#include <drizzled/dtcollation.h>
25
27
void item_init(void); /* Init item functions */
29
"Declared Type Collation"
30
A combination of collation and its derivation.
32
Flags for collation aggregation modes:
33
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
34
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
36
MY_COLL_ALLOW_CONV - allow any kind of conversion
37
(combination of the above two)
38
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
39
(e.g. when aggregating for comparison)
40
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
41
and MY_COLL_DISALLOW_NONE
44
#define MY_COLL_ALLOW_SUPERSET_CONV 1
45
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
46
#define MY_COLL_ALLOW_CONV 3
47
#define MY_COLL_DISALLOW_NONE 4
48
#define MY_COLL_CMP_CONV 7
52
const CHARSET_INFO *collation;
53
enum Derivation derivation;
56
void set_repertoire_from_charset(const CHARSET_INFO * const cs)
58
repertoire= cs->state & MY_CS_PUREASCII ?
59
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
63
collation= &my_charset_bin;
64
derivation= DERIVATION_NONE;
65
repertoire= MY_REPERTOIRE_UNICODE30;
67
DTCollation(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
69
collation= collation_arg;
70
derivation= derivation_arg;
71
set_repertoire_from_charset(collation_arg);
73
void set(DTCollation &dt)
75
collation= dt.collation;
76
derivation= dt.derivation;
77
repertoire= dt.repertoire;
79
void set(const CHARSET_INFO * const collation_arg, Derivation derivation_arg)
81
collation= collation_arg;
82
derivation= derivation_arg;
83
set_repertoire_from_charset(collation_arg);
85
void set(const CHARSET_INFO * const collation_arg,
86
Derivation derivation_arg,
87
uint32_t repertoire_arg)
89
collation= collation_arg;
90
derivation= derivation_arg;
91
repertoire= repertoire_arg;
93
void set(const CHARSET_INFO * const collation_arg)
95
collation= collation_arg;
96
set_repertoire_from_charset(collation_arg);
98
void set(Derivation derivation_arg)
99
{ derivation= derivation_arg; }
100
bool aggregate(DTCollation &dt, uint32_t flags= 0);
101
bool set(DTCollation &dt1, DTCollation &dt2, uint32_t flags= 0)
102
{ set(dt1); return aggregate(dt2, flags); }
103
const char *derivation_name() const
107
case DERIVATION_IGNORABLE: return "IGNORABLE";
108
case DERIVATION_COERCIBLE: return "COERCIBLE";
109
case DERIVATION_IMPLICIT: return "IMPLICIT";
110
case DERIVATION_SYSCONST: return "SYSCONST";
111
case DERIVATION_EXPLICIT: return "EXPLICIT";
112
case DERIVATION_NONE: return "NONE";
113
default: return "UNKNOWN";
118
/*************************************************************************/
120
A framework to easily handle different return types for hybrid items
121
(hybrid item is an item whose operand can be of any type, e.g. integer,
125
struct Hybrid_type_traits;
133
Use two decimal buffers interchangeably to speed up += operation
134
which has no native support in decimal library.
135
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
136
The third decimal is used as a handy temporary storage.
138
my_decimal dec_buf[3];
142
Traits moved to a separate class to
143
a) be able to easily change object traits in runtime
144
b) they work as a differentiator for the union above
146
const Hybrid_type_traits *traits;
149
/* XXX: add traits->copy() when needed */
150
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
154
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
156
struct Hybrid_type_traits
158
virtual Item_result type() const { return REAL_RESULT; }
161
fix_length_and_dec(Item *item, Item *arg) const;
163
/* Hybrid_type operations. */
164
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
165
virtual void add(Hybrid_type *val, Field *f) const
166
{ val->real+= f->val_real(); }
167
virtual void div(Hybrid_type *val, uint64_t u) const
168
{ val->real/= uint64_t2double(u); }
170
virtual int64_t val_int(Hybrid_type *val,
171
bool unsigned_flag) const;
172
virtual double val_real(Hybrid_type *val) const { return val->real; }
173
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
174
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
175
static const Hybrid_type_traits *instance();
176
Hybrid_type_traits() {}
177
virtual ~Hybrid_type_traits() {}
181
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
183
virtual Item_result type() const { return DECIMAL_RESULT; }
186
fix_length_and_dec(Item *arg, Item *item) const;
188
/* Hybrid_type operations. */
189
virtual void set_zero(Hybrid_type *val) const;
190
virtual void add(Hybrid_type *val, Field *f) const;
191
virtual void div(Hybrid_type *val, uint64_t u) const;
193
virtual int64_t val_int(Hybrid_type *val, bool unsigned_flag) const;
194
virtual double val_real(Hybrid_type *val) const;
195
virtual my_decimal *val_decimal(Hybrid_type *val,
196
my_decimal *buf __attribute__((unused))) const
197
{ return &val->dec_buf[val->used_dec_buf_no]; }
198
virtual String *val_str(Hybrid_type *val, String *buf, uint8_t decimals) const;
199
static const Hybrid_type_traits_decimal *instance();
200
Hybrid_type_traits_decimal() {};
204
struct Hybrid_type_traits_integer: public Hybrid_type_traits
206
virtual Item_result type() const { return INT_RESULT; }
209
fix_length_and_dec(Item *arg, Item *item) const;
211
/* Hybrid_type operations. */
212
virtual void set_zero(Hybrid_type *val) const
214
virtual void add(Hybrid_type *val, Field *f) const
215
{ val->integer+= f->val_int(); }
216
virtual void div(Hybrid_type *val, uint64_t u) const
217
{ val->integer/= (int64_t) u; }
219
virtual int64_t val_int(Hybrid_type *val,
220
bool unsigned_flag __attribute__((unused))) const
221
{ return val->integer; }
222
virtual double val_real(Hybrid_type *val) const
223
{ return (double) val->integer; }
224
virtual my_decimal *val_decimal(Hybrid_type *val,
225
my_decimal *buf __attribute__((unused))) const
227
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
228
return &val->dec_buf[2];
230
virtual String *val_str(Hybrid_type *val, String *buf,
231
uint8_t decimals __attribute__((unused))) const
232
{ buf->set(val->integer, &my_charset_bin); return buf;}
233
static const Hybrid_type_traits_integer *instance();
234
Hybrid_type_traits_integer() {};
238
31
void dummy_error_processor(Session *session, void *data);
388
This enum is used to report information about monotonicity of function
389
represented by Item* tree.
390
Monotonicity is defined only for Item* trees that represent table
391
partitioning expressions (i.e. have no subselects/user vars/PS parameters
392
etc etc). An Item* tree is assumed to have the same monotonicity properties
393
as its correspoinding function F:
395
[signed] int64_t F(field1, field2, ...) {
396
put values of field_i into table record buffer;
397
return item->val_int();
401
At the moment function monotonicity is not well defined (and so may be
402
incorrect) for Item trees with parameters/return types that are different
403
from INT_RESULT, may be NULL, or are unsigned.
404
It will be possible to address this issue once the related partitioning bugs
405
(BUG#16002, BUG#15447, BUG#13436) are fixed.
408
typedef enum monotonicity_info
410
NON_MONOTONIC, /* none of the below holds */
411
MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
412
MONOTONIC_STRICT_INCREASING /* F() is unary and (x < y) => (F(x) < F(y)) */
413
} enum_monotonicity_info;
415
180
/*************************************************************************/
416
typedef bool (Item::*Item_processor) (unsigned char *arg);
418
182
Analyzer function
420
184
argp in/out IN: Analysis parameter
421
185
OUT: Parameter to be passed to the transformer
424
188
true Invoke the transformer
425
189
false Don't do it