forked from trdtnguyen/mysql-plnvm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathitem.h
5597 lines (4904 loc) · 177 KB
/
item.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef ITEM_INCLUDED
#define ITEM_INCLUDED
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
#include "field.h" // Derivation
#include "parse_tree_node_base.h" // Parse_tree_node
#include "sql_array.h" // Bounds_checked_array
#include "template_utils.h" // pointer_cast
#include "trigger_def.h" // enum_trigger_variable_type
#include "table_trigger_field_support.h" // Table_trigger_field_support
#include "mysql/service_parser.h"
class user_var_entry;
class Json_wrapper;
typedef Bounds_checked_array<Item*> Ref_ptr_array;
void item_init(void); /* Init item functions */
/**
Default condition filtering (selectivity) values used by
get_filtering_effect() and friends when better estimates
(statistics) are not available for a predicate.
*/
/**
For predicates that are always satisfied. Must be 1.0 or the filter
calculation logic will break down.
*/
#define COND_FILTER_ALLPASS 1.0f
/// Filtering effect for equalities: col1 = col2
#define COND_FILTER_EQUALITY 0.1f
/// Filtering effect for inequalities: col1 > col2
#define COND_FILTER_INEQUALITY 0.3333f
/// Filtering effect for between: col1 BETWEEN a AND b
#define COND_FILTER_BETWEEN 0.1111f
/**
Value is out-of-date, will need recalculation.
This is used by post-greedy-search logic which changes the access method and thus
makes obsolete the filtering value calculated by best_access_path(). For
example, test_if_skip_sort_order().
*/
#define COND_FILTER_STALE -1.0f
/**
A special subcase of the above:
- if this is table/index/range scan, and
- rows_fetched is how many rows we will examine, and
- rows_fetched is less than the number of rows in the table (as determined
by test_if_cheaper_ordering() and test_if_skip_sort_order()).
Unlike the ordinary case where rows_fetched:
- is set by calculate_scan_cost(), and
- is how many rows pass the constant condition (so, less than we will
examine), and
- the actual rows_fetched to show in EXPLAIN is the number of rows in the
table (== rows which we will examine), and
- the constant condition's effect has to be moved to filter_effect for
EXPLAIN.
*/
#define COND_FILTER_STALE_NO_CONST -2.0f
static inline uint32
char_to_byte_length_safe(uint32 char_length_arg, uint32 mbmaxlen_arg)
{
ulonglong tmp= ((ulonglong) char_length_arg) * mbmaxlen_arg;
return (tmp > UINT_MAX32) ? (uint32) UINT_MAX32 : (uint32) tmp;
}
/*
"Declared Type Collation"
A combination of collation and its derivation.
Flags for collation aggregation modes:
MY_COLL_ALLOW_SUPERSET_CONV - allow conversion to a superset
MY_COLL_ALLOW_COERCIBLE_CONV - allow conversion of a coercible value
(i.e. constant).
MY_COLL_ALLOW_CONV - allow any kind of conversion
(combination of the above two)
MY_COLL_ALLOW_NUMERIC_CONV - if all items were numbers, convert to
@@character_set_connection
MY_COLL_DISALLOW_NONE - don't allow return DERIVATION_NONE
(e.g. when aggregating for comparison)
MY_COLL_CMP_CONV - combination of MY_COLL_ALLOW_CONV
and MY_COLL_DISALLOW_NONE
*/
#define MY_COLL_ALLOW_SUPERSET_CONV 1
#define MY_COLL_ALLOW_COERCIBLE_CONV 2
#define MY_COLL_DISALLOW_NONE 4
#define MY_COLL_ALLOW_NUMERIC_CONV 8
#define MY_COLL_ALLOW_CONV (MY_COLL_ALLOW_SUPERSET_CONV | MY_COLL_ALLOW_COERCIBLE_CONV)
#define MY_COLL_CMP_CONV (MY_COLL_ALLOW_CONV | MY_COLL_DISALLOW_NONE)
class DTCollation {
public:
const CHARSET_INFO *collation;
enum Derivation derivation;
uint repertoire;
void set_repertoire_from_charset(const CHARSET_INFO *cs)
{
repertoire= cs->state & MY_CS_PUREASCII ?
MY_REPERTOIRE_ASCII : MY_REPERTOIRE_UNICODE30;
}
DTCollation()
{
collation= &my_charset_bin;
derivation= DERIVATION_NONE;
repertoire= MY_REPERTOIRE_UNICODE30;
}
DTCollation(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
{
collation= collation_arg;
derivation= derivation_arg;
set_repertoire_from_charset(collation_arg);
}
void set(const DTCollation &dt)
{
collation= dt.collation;
derivation= dt.derivation;
repertoire= dt.repertoire;
}
void set(const CHARSET_INFO *collation_arg, Derivation derivation_arg)
{
collation= collation_arg;
derivation= derivation_arg;
set_repertoire_from_charset(collation_arg);
}
void set(const CHARSET_INFO *collation_arg,
Derivation derivation_arg,
uint repertoire_arg)
{
collation= collation_arg;
derivation= derivation_arg;
repertoire= repertoire_arg;
}
void set_numeric()
{
collation= &my_charset_numeric;
derivation= DERIVATION_NUMERIC;
repertoire= MY_REPERTOIRE_NUMERIC;
}
void set(const CHARSET_INFO *collation_arg)
{
collation= collation_arg;
set_repertoire_from_charset(collation_arg);
}
void set(Derivation derivation_arg)
{ derivation= derivation_arg; }
void set_repertoire(uint repertoire_arg)
{ repertoire= repertoire_arg; }
bool aggregate(DTCollation &dt, uint flags= 0);
bool set(DTCollation &dt1, DTCollation &dt2, uint flags= 0)
{ set(dt1); return aggregate(dt2, flags); }
const char *derivation_name() const
{
switch(derivation)
{
case DERIVATION_NUMERIC: return "NUMERIC";
case DERIVATION_IGNORABLE: return "IGNORABLE";
case DERIVATION_COERCIBLE: return "COERCIBLE";
case DERIVATION_IMPLICIT: return "IMPLICIT";
case DERIVATION_SYSCONST: return "SYSCONST";
case DERIVATION_EXPLICIT: return "EXPLICIT";
case DERIVATION_NONE: return "NONE";
default: return "UNKNOWN";
}
}
};
/**
Class used as argument to Item::walk() together with mark_field_in_map()
*/
class Mark_field
{
public:
Mark_field(TABLE *table, enum_mark_columns mark) :
table(table), mark(mark)
{}
Mark_field(enum_mark_columns mark) :
table(NULL), mark(mark)
{}
TABLE *const table;
const enum_mark_columns mark;
};
/**
Class used as argument to Item::walk() together with used_tables_for_level()
*/
class Used_tables
{
public:
explicit Used_tables(st_select_lex *select) :
select(select), used_tables(0)
{}
st_select_lex *const select; ///< Level for which data is accumulated
table_map used_tables; ///< Accumulated used tables data
};
/*************************************************************************/
/**
Storage for name strings.
Enpowers Simple_cstring with allocation routines from the sql_strmake family.
This class must stay as small as possible as we often
pass it into functions using call-by-value evaluation.
Don't add new members or virual methods into this class!
*/
class Name_string: public Simple_cstring
{
private:
void set_or_copy(const char *str, size_t length, bool is_null_terminated)
{
if (is_null_terminated)
set(str, length);
else
copy(str, length);
}
public:
Name_string(): Simple_cstring() {}
/*
Please do NOT add constructor Name_string(const char *str) !
It will involve hidden strlen() call, which can affect
performance negatively. Use Name_string(str, len) instead.
*/
Name_string(const char *str, size_t length):
Simple_cstring(str, length) {}
Name_string(const LEX_STRING str): Simple_cstring(str) {}
Name_string(const char *str, size_t length, bool is_null_terminated):
Simple_cstring()
{
set_or_copy(str, length, is_null_terminated);
}
Name_string(const LEX_STRING str, bool is_null_terminated):
Simple_cstring()
{
set_or_copy(str.str, str.length, is_null_terminated);
}
/**
Allocate space using sql_strmake() or sql_strmake_with_convert().
*/
void copy(const char *str, size_t length, const CHARSET_INFO *cs);
/**
Variants for copy(), for various argument combinations.
*/
void copy(const char *str, size_t length)
{
copy(str, length, system_charset_info);
}
void copy(const char *str)
{
copy(str, (str ? strlen(str) : 0), system_charset_info);
}
void copy(const LEX_STRING lex)
{
copy(lex.str, lex.length);
}
void copy(const LEX_STRING *lex)
{
copy(lex->str, lex->length);
}
void copy(const Name_string str)
{
copy(str.ptr(), str.length());
}
/**
Compare name to another name in C string, case insensitively.
*/
bool eq(const char *str) const
{
DBUG_ASSERT(str && ptr());
return my_strcasecmp(system_charset_info, ptr(), str) == 0;
}
bool eq_safe(const char *str) const
{
return is_set() && str && eq(str);
}
/**
Compare name to another name in Name_string, case insensitively.
*/
bool eq(const Name_string name) const
{
return eq(name.ptr());
}
bool eq_safe(const Name_string name) const
{
return is_set() && name.is_set() && eq(name);
}
};
#define NAME_STRING(x) Name_string(C_STRING_WITH_LEN(x))
extern const Name_string null_name_string;
/**
Storage for Item names.
Adds "autogenerated" flag and warning functionality to Name_string.
*/
class Item_name_string: public Name_string
{
private:
bool m_is_autogenerated; /* indicates if name of this Item
was autogenerated or set by user */
public:
Item_name_string(): Name_string(), m_is_autogenerated(true)
{ }
Item_name_string(const Name_string name)
:Name_string(name), m_is_autogenerated(true)
{ }
/**
Set m_is_autogenerated flag to the given value.
*/
void set_autogenerated(bool is_autogenerated)
{
m_is_autogenerated= is_autogenerated;
}
/**
Return the auto-generated flag.
*/
bool is_autogenerated() const { return m_is_autogenerated; }
using Name_string::copy;
/**
Copy name together with autogenerated flag.
Produce a warning if name was cut.
*/
void copy(const char *str_arg, size_t length_arg, const CHARSET_INFO *cs_arg,
bool is_autogenerated_arg);
};
/*************************************************************************/
/*
A framework to easily handle different return types for hybrid items
(hybrid item is an item whose operand can be of any type, e.g. integer,
real, decimal).
*/
struct Hybrid_type_traits;
struct Hybrid_type
{
longlong integer;
double real;
/*
Use two decimal buffers interchangeably to speed up += operation
which has no native support in decimal library.
Hybrid_type+= arg is implemented as dec_buf[1]= dec_buf[0] + arg.
The third decimal is used as a handy temporary storage.
*/
my_decimal dec_buf[3];
int used_dec_buf_no;
/*
Traits moved to a separate class to
a) be able to easily change object traits in runtime
b) they work as a differentiator for the union above
*/
const Hybrid_type_traits *traits;
Hybrid_type() {}
/* XXX: add traits->copy() when needed */
Hybrid_type(const Hybrid_type &rhs) :traits(rhs.traits) {}
};
/* Hybryd_type_traits interface + default implementation for REAL_RESULT */
struct Hybrid_type_traits
{
virtual Item_result type() const { return REAL_RESULT; }
virtual void
fix_length_and_dec(Item *item, Item *arg) const;
/* Hybrid_type operations. */
virtual void set_zero(Hybrid_type *val) const { val->real= 0.0; }
virtual void add(Hybrid_type *val, Field *f) const
{ val->real+= f->val_real(); }
virtual void div(Hybrid_type *val, ulonglong u) const
{ val->real/= ulonglong2double(u); }
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
{ return (longlong) rint(val->real); }
virtual double val_real(Hybrid_type *val) const { return val->real; }
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const;
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
static const Hybrid_type_traits *instance();
Hybrid_type_traits() {}
virtual ~Hybrid_type_traits() {}
};
struct Hybrid_type_traits_decimal: public Hybrid_type_traits
{
virtual Item_result type() const { return DECIMAL_RESULT; }
virtual void
fix_length_and_dec(Item *arg, Item *item) const;
/* Hybrid_type operations. */
virtual void set_zero(Hybrid_type *val) const;
virtual void add(Hybrid_type *val, Field *f) const;
virtual void div(Hybrid_type *val, ulonglong u) const;
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const;
virtual double val_real(Hybrid_type *val) const;
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
{ return &val->dec_buf[val->used_dec_buf_no]; }
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const;
static const Hybrid_type_traits_decimal *instance();
Hybrid_type_traits_decimal() {};
};
struct Hybrid_type_traits_integer: public Hybrid_type_traits
{
virtual Item_result type() const { return INT_RESULT; }
virtual void
fix_length_and_dec(Item *arg, Item *item) const;
/* Hybrid_type operations. */
virtual void set_zero(Hybrid_type *val) const
{ val->integer= 0; }
virtual void add(Hybrid_type *val, Field *f) const
{ val->integer+= f->val_int(); }
virtual void div(Hybrid_type *val, ulonglong u) const
{ val->integer/= (longlong) u; }
virtual longlong val_int(Hybrid_type *val, bool unsigned_flag) const
{ return val->integer; }
virtual double val_real(Hybrid_type *val) const
{ return (double) val->integer; }
virtual my_decimal *val_decimal(Hybrid_type *val, my_decimal *buf) const
{
int2my_decimal(E_DEC_FATAL_ERROR, val->integer, 0, &val->dec_buf[2]);
return &val->dec_buf[2];
}
virtual String *val_str(Hybrid_type *val, String *buf, uint8 decimals) const
{ buf->set(val->integer, &my_charset_bin); return buf;}
static const Hybrid_type_traits_integer *instance();
Hybrid_type_traits_integer() {};
};
/*
Instances of Name_resolution_context store the information necesary for
name resolution of Items and other context analysis of a query made in
fix_fields().
This structure is a part of SELECT_LEX, a pointer to this structure is
assigned when an item is created (which happens mostly during parsing
(sql_yacc.yy)), but the structure itself will be initialized after parsing
is complete
TODO: move subquery of INSERT ... SELECT and CREATE ... SELECT to
separate SELECT_LEX which allow to remove tricks of changing this
structure before and after INSERT/CREATE and its SELECT to make correct
field name resolution.
*/
struct Name_resolution_context: Sql_alloc
{
/*
The name resolution context to search in when an Item cannot be
resolved in this context (the context of an outer select)
*/
Name_resolution_context *outer_context;
/// Link to next name res context with the same query block as the base
Name_resolution_context *next_context;
/*
List of tables used to resolve the items of this context. Usually these
are tables from the FROM clause of SELECT statement. The exceptions are
INSERT ... SELECT and CREATE ... SELECT statements, where SELECT
subquery is not moved to a separate SELECT_LEX. For these types of
statements we have to change this member dynamically to ensure correct
name resolution of different parts of the statement.
*/
TABLE_LIST *table_list;
/*
In most cases the two table references below replace 'table_list' above
for the purpose of name resolution. The first and last name resolution
table references allow us to search only in a sub-tree of the nested
join tree in a FROM clause. This is needed for NATURAL JOIN, JOIN ... USING
and JOIN ... ON.
*/
TABLE_LIST *first_name_resolution_table;
/*
Last table to search in the list of leaf table references that begins
with first_name_resolution_table.
*/
TABLE_LIST *last_name_resolution_table;
/*
SELECT_LEX item belong to, in case of merged VIEW it can differ from
SELECT_LEX where item was created, so we can't use table_list/field_list
from there
*/
st_select_lex *select_lex;
/*
Processor of errors caused during Item name resolving, now used only to
hide underlying tables in errors about views (i.e. it substitute some
errors for views)
*/
bool view_error_handler;
TABLE_LIST *view_error_handler_arg;
/**
When TRUE, items are resolved in this context against
SELECT_LEX::item_list, SELECT_lex::group_list and
this->table_list. If FALSE, items are resolved only against
this->table_list.
@see st_select_lex::item_list, st_select_lex::group_list
*/
bool resolve_in_select_list;
/*
Security context of this name resolution context. It's used for views
and is non-zero only if the view is defined with SQL SECURITY DEFINER.
*/
Security_context *security_ctx;
Name_resolution_context()
:outer_context(NULL), next_context(NULL),
table_list(NULL), select_lex(NULL),
view_error_handler_arg(NULL), security_ctx(NULL)
{}
void init()
{
resolve_in_select_list= FALSE;
view_error_handler= false;
first_name_resolution_table= NULL;
last_name_resolution_table= NULL;
}
void resolve_in_table_list_only(TABLE_LIST *tables)
{
table_list= first_name_resolution_table= tables;
resolve_in_select_list= FALSE;
}
};
/*
Store and restore the current state of a name resolution context.
*/
class Name_resolution_context_state
{
private:
TABLE_LIST *save_table_list;
TABLE_LIST *save_first_name_resolution_table;
TABLE_LIST *save_next_name_resolution_table;
bool save_resolve_in_select_list;
TABLE_LIST *save_next_local;
public:
Name_resolution_context_state() {} /* Remove gcc warning */
public:
/* Save the state of a name resolution context. */
void save_state(Name_resolution_context *context, TABLE_LIST *table_list)
{
save_table_list= context->table_list;
save_first_name_resolution_table= context->first_name_resolution_table;
save_resolve_in_select_list= context->resolve_in_select_list;
save_next_local= table_list->next_local;
save_next_name_resolution_table= table_list->next_name_resolution_table;
}
/* Restore a name resolution context from saved state. */
void restore_state(Name_resolution_context *context, TABLE_LIST *table_list)
{
table_list->next_local= save_next_local;
table_list->next_name_resolution_table= save_next_name_resolution_table;
context->table_list= save_table_list;
context->first_name_resolution_table= save_first_name_resolution_table;
context->resolve_in_select_list= save_resolve_in_select_list;
}
TABLE_LIST *get_first_name_resolution_table()
{
return save_first_name_resolution_table;
}
};
/*
This enum is used to report information about monotonicity of function
represented by Item* tree.
Monotonicity is defined only for Item* trees that represent table
partitioning expressions (i.e. have no subselects/user vars/PS parameters
etc etc). An Item* tree is assumed to have the same monotonicity properties
as its correspoinding function F:
[signed] longlong F(field1, field2, ...) {
put values of field_i into table record buffer;
return item->val_int();
}
NOTE
At the moment function monotonicity is not well defined (and so may be
incorrect) for Item trees with parameters/return types that are different
from INT_RESULT, may be NULL, or are unsigned.
It will be possible to address this issue once the related partitioning bugs
(BUG#16002, BUG#15447, BUG#13436) are fixed.
The NOT_NULL enums are used in TO_DAYS, since TO_DAYS('2001-00-00') returns
NULL which puts those rows into the NULL partition, but
'2000-12-31' < '2001-00-00' < '2001-01-01'. So special handling is needed
for this (see Bug#20577).
*/
typedef enum monotonicity_info
{
NON_MONOTONIC, /* none of the below holds */
MONOTONIC_INCREASING, /* F() is unary and (x < y) => (F(x) <= F(y)) */
MONOTONIC_INCREASING_NOT_NULL, /* But only for valid/real x and y */
MONOTONIC_STRICT_INCREASING,/* F() is unary and (x < y) => (F(x) < F(y)) */
MONOTONIC_STRICT_INCREASING_NOT_NULL /* But only for valid/real x and y */
} enum_monotonicity_info;
/**
A type for SQL-like 3-valued Booleans: true/false/unknown.
*/
class Bool3
{
public:
/// @returns an instance set to "FALSE"
static const Bool3 false3() { return Bool3(v_FALSE); }
/// @returns an instance set to "UNKNOWN"
static const Bool3 unknown3() { return Bool3(v_UNKNOWN); }
/// @returns an instance set to "TRUE"
static const Bool3 true3() { return Bool3(v_TRUE); }
bool is_true() const { return m_val == v_TRUE; }
bool is_unknown() const { return m_val == v_UNKNOWN; }
bool is_false() const { return m_val == v_FALSE; }
private:
enum value { v_FALSE, v_UNKNOWN, v_TRUE };
/// This is private; instead, use false3()/etc.
Bool3(value v) : m_val(v) {}
value m_val;
/*
No operator to convert Bool3 to bool (or int) - intentionally: how
would you map UNKNOWN3 to true/false?
It is because we want to block such conversions that Bool3 is a class
instead of a plain enum.
*/
};
/*************************************************************************/
class sp_rcontext;
class Settable_routine_parameter
{
public:
/*
Set required privileges for accessing the parameter.
SYNOPSIS
set_required_privilege()
rw if 'rw' is true then we are going to read and set the
parameter, so SELECT and UPDATE privileges might be
required, otherwise we only reading it and SELECT
privilege might be required.
*/
Settable_routine_parameter() {}
virtual ~Settable_routine_parameter() {}
virtual void set_required_privilege(bool rw) {};
/*
Set parameter value.
SYNOPSIS
set_value()
thd thread handle
ctx context to which parameter belongs (if it is local
variable).
it item which represents new value
RETURN
FALSE if parameter value has been set,
TRUE if error has occured.
*/
virtual bool set_value(THD *thd, sp_rcontext *ctx, Item **it)= 0;
virtual void set_out_param_info(Send_field *info) {}
virtual const Send_field *get_out_param_info() const
{ return NULL; }
};
typedef bool (Item::*Item_processor) (uchar *arg);
/*
Analyzer function
SYNOPSIS
argp in/out IN: Analysis parameter
OUT: Parameter to be passed to the transformer
RETURN
TRUE Invoke the transformer
FALSE Don't do it
*/
typedef bool (Item::*Item_analyzer) (uchar **argp);
typedef Item* (Item::*Item_transformer) (uchar *arg);
typedef void (*Cond_traverser) (const Item *item, void *arg);
class Item : public Parse_tree_node
{
typedef Parse_tree_node super;
Item(const Item &); /* Prevent use of these */
void operator=(Item &);
/* Cache of the result of is_expensive(). */
int8 is_expensive_cache;
virtual bool is_expensive_processor(uchar *arg) { return false; }
protected:
/**
Sets the result value of the function an empty string, using the current
character set. No memory is allocated.
@retval A pointer to the str_value member.
*/
String *make_empty_result() {
str_value.set("", 0, collation.collation);
return &str_value;
}
public:
static void *operator new(size_t size) throw ()
{ return sql_alloc(size); }
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
static void operator delete(void *ptr,size_t size) { TRASH(ptr, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root) {}
enum Type {INVALID_ITEM= 0,
FIELD_ITEM, FUNC_ITEM, SUM_FUNC_ITEM, STRING_ITEM,
INT_ITEM, REAL_ITEM, NULL_ITEM, VARBIN_ITEM,
COPY_STR_ITEM, FIELD_AVG_ITEM, DEFAULT_VALUE_ITEM,
PROC_ITEM,COND_ITEM, REF_ITEM, FIELD_STD_ITEM,
FIELD_VARIANCE_ITEM, INSERT_VALUE_ITEM,
SUBSELECT_ITEM, ROW_ITEM, CACHE_ITEM, TYPE_HOLDER,
PARAM_ITEM, TRIGGER_FIELD_ITEM, DECIMAL_ITEM,
XPATH_NODESET, XPATH_NODESET_CMP,
VIEW_FIXER_ITEM};
enum cond_result { COND_UNDEF,COND_OK,COND_TRUE,COND_FALSE };
enum traverse_order { POSTFIX, PREFIX };
/**
@todo
-# Move this away from the Item class. It is a property of the
visitor in what direction the traversal is done, not of the visitee.
-# Make this two booleans instead. There are two orthogonal flags here.
*/
enum enum_walk
{
WALK_PREFIX= 0x01,
WALK_POSTFIX= 0x02,
WALK_SUBQUERY= 0x04,
WALK_SUBQUERY_PREFIX= 0x05,
WALK_SUBQUERY_POSTFIX= 0x06
};
/* Reuse size, only used by SP local variable assignment, otherwize 0 */
uint rsize;
/*
str_values's main purpose is to be used to cache the value in
save_in_field
*/
String str_value;
Item_name_string item_name; /* Name from select */
Item_name_string orig_name; /* Original item name (if it was renamed)*/
/**
Intrusive list pointer for free list. If not null, points to the next
Item on some Query_arena's free list. For instance, stored procedures
have their own Query_arena's.
@see Query_arena::free_list
*/
Item *next;
uint32 max_length; /* Maximum length, in bytes */
/**
This member has several successive meanings, depending on the phase we're
in:
- during field resolution: it contains the index, in the "all_fields"
list, of the expression to which this field belongs; or a special
constant UNDEF_POS; see st_select_lex::cur_pos_in_all_fields and
match_exprs_for_only_full_group_by().
- when attaching conditions to tables: it says whether some condition
needs to be attached or can be omitted (for example because it is already
implemented by 'ref' access)
- when pushing index conditions: it says whether a condition uses only
indexed columns
- when creating an internal temporary table: it says how to store BIT
fields
- when we change DISTINCT to GROUP BY: it is used for book-keeping of
fields.
*/
int marker;
uint8 decimals;
/**
True if this item may be null.
For items that represent rows, it is true if one of the columns
may be null.
For items that represent scalar or row subqueries, it is true if
one of the returned columns could be null, or if the subquery
could return zero rows.
*/
my_bool maybe_null;
my_bool null_value; /* if item is null */
my_bool unsigned_flag;
my_bool with_sum_func;
my_bool fixed; /* If item fixed with fix_fields */
DTCollation collation;
Item_result cmp_context; /* Comparison context */
/*
If this item was created in runtime memroot,it cannot be used for
substitution in subquery transformation process
*/
bool runtime_item;
private:
/**
True if this is an expression from the select list of a derived table
which is actually used by outer query.
*/
bool derived_used;
protected:
my_bool with_subselect; /* If this item is a subselect or some
of its arguments is or contains a
subselect. Computed by fix_fields
and updated by update_used_tables. */
my_bool with_stored_program; /* If this item is a stored program
or some of its arguments is or
contains a stored program.
Computed by fix_fields and updated
by update_used_tables. */
/**
This variable is a cache of 'Needed tables are locked'. True if either
'No tables locks is needed' or 'Needed tables are locked'.
If tables are used, then it will be set to
current_thd->lex->is_query_tables_locked().
It is used when checking const_item()/can_be_evaluated_now().
*/
bool tables_locked_cache;
const bool is_parser_item; // true if allocated directly by the parser
/*
Checks if the items provided as parameter offend the deprecated behavior
on binary operations and if so, a warning will be sent.
@param a item to check
@param b item to check, may be NULL
*/
static void check_deprecated_bin_op(const Item *a, const Item *b);
public:
// alloc & destruct is done as start of select using sql_alloc
Item();
/**
Parse-time context-independent constructor.
This constructor and caller constructors of child classes must not
access/change thd->lex (including thd->lex->current_select(),
thd->m_parser_state etc structures).
If we need to finalize the construction of the object, then we move
all context-sensitive code to the itemize() virtual function.
The POS parameter marks this constructor and other context-independent
constructors of child classes for easy recognition/separation from other
(context-dependent) constructors.
*/
explicit Item(const POS &);
/*
Constructor used by Item_field, Item_ref & aggregate (sum) functions.
Used for duplicating lists in processing queries with temporary
tables
Also it used for Item_cond_and/Item_cond_or for creating
top AND/OR structure of WHERE clause to protect it of
optimisation changes in prepared statements
*/
Item(THD *thd, Item *item);
virtual ~Item()
{
#ifdef EXTRA_DEBUG
item_name.set(0);
#endif
} /*lint -e1509 */
private:
/*
Hide the contextualize*() functions: call/override the itemize()
in Item class tree instead.
Note: contextualize_() is an intermediate function. Remove it together
with Parse_tree_node::contextualize_().
*/
virtual bool contextualize(Parse_context *pc) { DBUG_ASSERT(0); return true; }
virtual bool contextualize_(Parse_context *pc) { DBUG_ASSERT(0); return true; }
protected:
/**
Helper function to skip itemize() for grammar-allocated items
@param [out] res pointer to "this"
@retval true can skip itemize()
@retval false can't skip: the item is allocated directly by the parser
*/
bool skip_itemize(Item **res)
{
*res= this;
return !is_parser_item;
}
public:
/**
The same as contextualize()/contextualize_() but with additional parameter
This function finalize the construction of Item objects (see the Item(POS)
constructor): we can access/change parser contexts from the itemize()
function.
@param pc current parse context
@param [out] res pointer to "this" or to a newly allocated
replacement object to use in the Item tree instead
@retval false success
@retval true syntax/OOM/etc error
*/
virtual bool itemize(Parse_context *pc, Item **res);
void rename(char *new_name);
void init_make_field(Send_field *tmp_field,enum enum_field_types type);
virtual void cleanup();
virtual void make_field(Send_field *field);
virtual Field *make_string_field(TABLE *table);
virtual bool fix_fields(THD *, Item **);
/**
Fix after tables have been moved from one select_lex level to the parent
level, e.g by semijoin conversion.
Basically re-calculate all attributes dependent on the tables.
@param parent_select select_lex that tables are moved to.
@param removed_select select_lex that tables are moved away from,
child of parent_select.
*/
virtual void fix_after_pullout(st_select_lex *parent_select,
st_select_lex *removed_select)
{};
/*