31
/*************************************************************************/
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,
38
struct Hybrid_type_traits;
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.
51
my_decimal dec_buf[3];
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
59
const Hybrid_type_traits *traits;
62
/* XXX: add traits->copy() when needed */
63
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
67
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
69
struct Hybrid_type_traits
71
virtual Item_result type() const { return REAL_RESULT; }
74
fix_length_and_dec(Item *item, Item *arg) const;
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); }
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() {}
94
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
96
virtual Item_result type() const { return DECIMAL_RESULT; }
99
fix_length_and_dec(Item *arg, Item *item) const;
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;
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() {};
117
struct Hybrid_type_traits_integer: public Hybrid_type_traits
119
virtual Item_result type() const { return INT_RESULT; }
122
fix_length_and_dec(Item *arg, Item *item) const;
124
/* Hybrid_type operations. */
125
virtual void set_zero(Hybrid_type *val) const
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; }
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
140
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
141
return &val->dec_buf[2];
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() {};
151
31
void dummy_error_processor(Session *session, void *data);
153
33
void view_error_processor(Session *session, void *data);
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:
308
[signed] int64_t F(field1, field2, ...) {
309
put values of field_i into table record buffer;
310
return item->val_int();
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.
321
typedef enum monotonicity_info
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;
328
180
/*************************************************************************/
329
typedef bool (Item::*Item_processor) (unsigned char *arg);
331
182
Analyzer function
333
184
argp in/out IN: Analysis parameter
334
185
OUT: Parameter to be passed to the transformer
337
188
true Invoke the transformer
338
189
false Don't do it