forked from kunpengcompute/mysql-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitem_func.h
3873 lines (3384 loc) · 123 KB
/
item_func.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_FUNC_INCLUDED
#define ITEM_FUNC_INCLUDED
/* Copyright (c) 2000, 2020, 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, version 2.0,
as published by the Free Software Foundation.
This program is also distributed with certain software (including
but not limited to OpenSSL) that is licensed under separate terms,
as designated in a particular file or component or in included license
documentation. The authors of MySQL hereby grant you an additional
permission to link the program and your derivative works with the
separately licensed software that they have included with MySQL.
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, version 2.0, 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 <limits.h>
#include <stddef.h>
#include <sys/types.h>
#include <cmath> // isfinite
#include <functional>
#include "decimal.h"
#include "field_types.h"
#include "ft_global.h"
#include "lex_string.h"
#include "m_ctype.h"
#include "my_alloc.h"
#include "my_base.h"
#include "my_compiler.h"
#include "my_dbug.h"
#include "my_inttypes.h"
#include "my_pointer_arithmetic.h"
#include "my_table_map.h"
#include "my_thread_local.h"
#include "my_time.h"
#include "mysql/service_mysql_alloc.h"
#include "mysql/udf_registration_types.h"
#include "mysql_com.h"
#include "mysql_time.h"
#include "mysqld_error.h"
#include "sql/enum_query_type.h"
#include "sql/field.h"
#include "sql/handler.h"
#include "sql/item.h" // Item_result_field
#include "sql/my_decimal.h" // str2my_decimal
#include "sql/parse_tree_node_base.h"
#include "sql/set_var.h" // enum_var_type
#include "sql/sql_const.h"
#include "sql/sql_udf.h" // udf_handler
#include "sql/table.h"
#include "sql/thr_malloc.h"
#include "sql_string.h"
#include "template_utils.h"
class Json_wrapper;
class PT_item_list;
class Protocol;
class SELECT_LEX;
class THD;
class sp_rcontext;
struct MY_BITMAP;
template <class T>
class List;
class QEP_TAB;
/* Function items used by mysql */
extern bool reject_geometry_args(uint arg_count, Item **args,
Item_result_field *me);
void unsupported_json_comparison(size_t arg_count, Item **args,
const char *msg);
class Item_func : public Item_result_field {
typedef Item_result_field super;
protected:
Item **args, *tmp_arg[2];
/**
Affects how to determine that NULL argument implies a NULL function return.
Default behaviour in this class is:
- if true, any NULL argument means the function returns NULL.
- if false, no such assumption is made and not_null_tables_cache is thus
set to 0.
null_on_null is true for all Item_func derived classes, except Item_func_sp,
all CASE derived functions and a few other functions.
RETURNS NULL ON NULL INPUT can be implemented for stored functions by
modifying this member in class Item_func_sp.
*/
bool null_on_null = true;
/*
Allowed numbers of columns in result (usually 1, which means scalar value)
0 means get this number from first argument
*/
uint allowed_arg_cols = 1;
/// Value used in calculation of result of used_tables()
table_map used_tables_cache;
/// Value used in calculation of result of not_null_tables()
table_map not_null_tables_cache;
public:
uint arg_count;
/*
When updating Functype with new spatial functions,
is_spatial_operator() should also be updated.
DD_INTERNAL_FUNC:
Some of the internal functions introduced for the INFORMATION_SCHEMA views
opens data-dictionary tables. DD_INTERNAL_FUNC is used for the such type
of functions.
*/
enum Functype {
UNKNOWN_FUNC,
EQ_FUNC,
EQUAL_FUNC,
NE_FUNC,
LT_FUNC,
LE_FUNC,
GE_FUNC,
GT_FUNC,
FT_FUNC,
MATCH_FUNC,
LIKE_FUNC,
ISNULL_FUNC,
ISNOTNULL_FUNC,
ISTRUTH_FUNC,
COND_AND_FUNC,
COND_OR_FUNC,
XOR_FUNC,
BETWEEN,
IN_FUNC,
MULT_EQUAL_FUNC,
INTERVAL_FUNC,
ISNOTNULLTEST_FUNC,
SP_EQUALS_FUNC,
SP_DISJOINT_FUNC,
SP_INTERSECTS_FUNC,
SP_TOUCHES_FUNC,
SP_CROSSES_FUNC,
SP_WITHIN_FUNC,
SP_CONTAINS_FUNC,
SP_COVEREDBY_FUNC,
SP_COVERS_FUNC,
SP_OVERLAPS_FUNC,
SP_STARTPOINT,
SP_ENDPOINT,
SP_EXTERIORRING,
SP_POINTN,
SP_GEOMETRYN,
SP_INTERIORRINGN,
NOT_FUNC,
NOT_ALL_FUNC,
NOW_FUNC,
TRIG_COND_FUNC,
SUSERVAR_FUNC,
GUSERVAR_FUNC,
COLLATE_FUNC,
EXTRACT_FUNC,
TYPECAST_FUNC,
FUNC_SP,
UDF_FUNC,
NEG_FUNC,
GSYSVAR_FUNC,
GROUPING_FUNC,
TABLE_FUNC,
DD_INTERNAL_FUNC,
PLUS_FUNC,
MINUS_FUNC,
MUL_FUNC,
DIV_FUNC,
CEILING_FUNC,
ROUND_FUNC,
TRUNCATE_FUNC,
SQRT_FUNC,
ABS_FUNC,
FLOOR_FUNC,
LOG_FUNC,
LN_FUNC,
LOG10_FUNC,
SIN_FUNC,
TAN_FUNC,
COS_FUNC,
COT_FUNC,
DEGREES_FUNC,
RADIANS_FUNC,
EXP_FUNC,
ASIN_FUNC,
ATAN_FUNC,
ACOS_FUNC,
MOD_FUNC,
IF_FUNC,
NULLIF_FUNC,
CASE_FUNC,
YEAR_FUNC,
MONTH_FUNC,
DAY_FUNC,
TO_DAYS_FUNC,
DATE_FUNC,
HOUR_FUNC,
MINUTE_FUNC,
SECOND_FUNC,
MICROSECOND_FUNC,
WEEK_FUNC,
WEEKDAY_FUNC,
DATEADD_FUNC,
TIMESTAMPDIFF_FUNC,
DATETIME_LITERAL,
GREATEST_FUNC,
COALESCE_FUNC,
LEAST_FUNC,
JSON_CONTAINS,
JSON_OVERLAPS,
MEMBER_OF_FUNC,
STRCMP_FUNC,
TRUE_FUNC
};
enum optimize_type {
OPTIMIZE_NONE,
OPTIMIZE_KEY,
OPTIMIZE_OP,
OPTIMIZE_NULL,
OPTIMIZE_EQUAL
};
enum Type type() const override { return FUNC_ITEM; }
virtual enum Functype functype() const { return UNKNOWN_FUNC; }
Item_func() : arg_count(0) { args = tmp_arg; }
explicit Item_func(const POS &pos) : super(pos), arg_count(0) {
args = tmp_arg;
}
Item_func(Item *a) : arg_count(1) {
args = tmp_arg;
args[0] = a;
set_accum_properties(a);
}
Item_func(const POS &pos, Item *a) : super(pos), arg_count(1) {
args = tmp_arg;
args[0] = a;
}
Item_func(Item *a, Item *b) : arg_count(2) {
args = tmp_arg;
args[0] = a;
args[1] = b;
m_accum_properties = 0;
add_accum_properties(a);
add_accum_properties(b);
}
Item_func(const POS &pos, Item *a, Item *b) : super(pos), arg_count(2) {
args = tmp_arg;
args[0] = a;
args[1] = b;
}
Item_func(Item *a, Item *b, Item *c) : arg_count(3) {
if ((args = (Item **)(*THR_MALLOC)->Alloc(sizeof(Item *) * 3))) {
args[0] = a;
args[1] = b;
args[2] = c;
m_accum_properties = 0;
add_accum_properties(a);
add_accum_properties(b);
add_accum_properties(c);
} else
arg_count = 0; // OOM
}
Item_func(const POS &pos, Item *a, Item *b, Item *c)
: super(pos), arg_count(3) {
if ((args = (Item **)(*THR_MALLOC)->Alloc(sizeof(Item *) * 3))) {
args[0] = a;
args[1] = b;
args[2] = c;
} else
arg_count = 0; // OOM
}
Item_func(Item *a, Item *b, Item *c, Item *d) : arg_count(4) {
if ((args = (Item **)(*THR_MALLOC)->Alloc(sizeof(Item *) * 4))) {
args[0] = a;
args[1] = b;
args[2] = c;
args[3] = d;
m_accum_properties = 0;
add_accum_properties(a);
add_accum_properties(b);
add_accum_properties(c);
add_accum_properties(d);
} else
arg_count = 0; // OOM
}
Item_func(const POS &pos, Item *a, Item *b, Item *c, Item *d)
: super(pos), arg_count(4) {
if ((args = (Item **)(*THR_MALLOC)->Alloc(sizeof(Item *) * 4))) {
args[0] = a;
args[1] = b;
args[2] = c;
args[3] = d;
} else
arg_count = 0; // OOM
}
Item_func(Item *a, Item *b, Item *c, Item *d, Item *e) : arg_count(5) {
if ((args = (Item **)(*THR_MALLOC)->Alloc(sizeof(Item *) * 5))) {
args[0] = a;
args[1] = b;
args[2] = c;
args[3] = d;
args[4] = e;
m_accum_properties = 0;
add_accum_properties(a);
add_accum_properties(b);
add_accum_properties(c);
add_accum_properties(d);
add_accum_properties(e);
} else
arg_count = 0; // OOM
}
Item_func(const POS &pos, Item *a, Item *b, Item *c, Item *d, Item *e)
: super(pos), arg_count(5) {
if ((args = (Item **)(*THR_MALLOC)->Alloc(sizeof(Item *) * 5))) {
args[0] = a;
args[1] = b;
args[2] = c;
args[3] = d;
args[4] = e;
} else
arg_count = 0; // OOM
}
Item_func(List<Item> &list) { set_arguments(list, false); }
Item_func(const POS &pos, PT_item_list *opt_list);
// Constructor used for Item_cond_and/or (see Item comment)
Item_func(THD *thd, Item_func *item);
bool itemize(Parse_context *pc, Item **res) override;
bool fix_fields(THD *, Item **ref) override;
bool fix_func_arg(THD *, Item **arg);
void fix_after_pullout(SELECT_LEX *parent_select,
SELECT_LEX *removed_select) override;
/**
Returns the pseudo tables depended upon in order to evaluate this
function expression. The default implementation returns the empty
set.
*/
virtual table_map get_initial_pseudo_tables() const { return 0; }
table_map used_tables() const override { return used_tables_cache; }
table_map not_null_tables() const override { return not_null_tables_cache; }
void update_used_tables() override;
void set_used_tables(table_map map) { used_tables_cache = map; }
bool eq(const Item *item, bool binary_cmp) const override;
virtual optimize_type select_optimize(const THD *) { return OPTIMIZE_NONE; }
virtual bool have_rev_func() const { return false; }
virtual Item *key_item() const { return args[0]; }
inline Item **arguments() const {
DBUG_ASSERT(argument_count() > 0);
return args;
}
/**
Copy arguments from list to args array
@param list function argument list
@param context_free true: for use in context-independent
constructors (Item_func(POS,...)) i.e. for use
in the parser
*/
void set_arguments(List<Item> &list, bool context_free);
inline uint argument_count() const { return arg_count; }
void split_sum_func(THD *thd, Ref_item_array ref_item_array,
List<Item> &fields) override;
void print(const THD *thd, String *str,
enum_query_type query_type) const override;
void print_op(const THD *thd, String *str, enum_query_type query_type) const;
void print_args(const THD *thd, String *str, uint from,
enum_query_type query_type) const;
virtual void fix_num_length_and_dec();
virtual bool is_deprecated() const { return false; }
bool get_arg0_date(MYSQL_TIME *ltime, my_time_flags_t fuzzy_date) {
return (null_value = args[0]->get_date(ltime, fuzzy_date));
}
inline bool get_arg0_time(MYSQL_TIME *ltime) {
return (null_value = args[0]->get_time(ltime));
}
bool is_null() override {
/*
TODO : Implement error handling for this function as
update_null_value() can return error.
*/
(void)update_null_value();
return null_value;
}
void signal_divide_by_null();
void signal_invalid_argument_for_log();
friend class udf_handler;
Field *tmp_table_field(TABLE *t_arg) override;
Item *get_tmp_table_item(THD *thd) override;
my_decimal *val_decimal(my_decimal *) override;
bool agg_arg_charsets(DTCollation &c, Item **items, uint nitems, uint flags,
int item_sep) {
return agg_item_charsets(c, func_name(), items, nitems, flags, item_sep);
}
/*
Aggregate arguments for string result, e.g: CONCAT(a,b)
- convert to @@character_set_connection if all arguments are numbers
- allow DERIVATION_NONE
*/
bool agg_arg_charsets_for_string_result(DTCollation &c, Item **items,
uint nitems, int item_sep = 1) {
return agg_item_charsets_for_string_result(c, func_name(), items, nitems,
item_sep);
}
/*
Aggregate arguments for comparison, e.g: a=b, a LIKE b, a RLIKE b
- don't convert to @@character_set_connection if all arguments are numbers
- don't allow DERIVATION_NONE
*/
bool agg_arg_charsets_for_comparison(DTCollation &c, Item **items,
uint nitems, int item_sep = 1) {
return agg_item_charsets_for_comparison(c, func_name(), items, nitems,
item_sep);
}
bool walk(Item_processor processor, enum_walk walk, uchar *arg) override;
Item *transform(Item_transformer transformer, uchar *arg) override;
Item *compile(Item_analyzer analyzer, uchar **arg_p,
Item_transformer transformer, uchar *arg_t) override;
void traverse_cond(Cond_traverser traverser, void *arg,
traverse_order order) override;
/**
Throw an error if the input double number is not finite, i.e. is either
+/-INF or NAN.
*/
inline double check_float_overflow(double value) {
return std::isfinite(value) ? value : raise_float_overflow();
}
/**
Throw an error if the input BIGINT value represented by the
(longlong value, bool unsigned flag) pair cannot be returned by the
function, i.e. is not compatible with this Item's unsigned_flag.
*/
inline longlong check_integer_overflow(longlong value, bool val_unsigned) {
if ((unsigned_flag && !val_unsigned && value < 0) ||
(!unsigned_flag && val_unsigned &&
(ulonglong)value > (ulonglong)LLONG_MAX))
return raise_integer_overflow();
return value;
}
/**
Throw an error if the error code of a DECIMAL operation is E_DEC_OVERFLOW.
*/
inline int check_decimal_overflow(int error) {
return (error == E_DEC_OVERFLOW) ? raise_decimal_overflow() : error;
}
bool has_timestamp_args() {
DBUG_ASSERT(fixed);
for (uint i = 0; i < arg_count; i++) {
if (args[i]->type() == Item::FIELD_ITEM &&
args[i]->data_type() == MYSQL_TYPE_TIMESTAMP)
return true;
}
return false;
}
bool has_date_args() {
DBUG_ASSERT(fixed);
for (uint i = 0; i < arg_count; i++) {
if (args[i]->type() == Item::FIELD_ITEM &&
(args[i]->data_type() == MYSQL_TYPE_DATE ||
args[i]->data_type() == MYSQL_TYPE_DATETIME))
return true;
}
return false;
}
bool has_time_args() {
DBUG_ASSERT(fixed);
for (uint i = 0; i < arg_count; i++) {
if (args[i]->type() == Item::FIELD_ITEM &&
(args[i]->data_type() == MYSQL_TYPE_TIME ||
args[i]->data_type() == MYSQL_TYPE_DATETIME))
return true;
}
return false;
}
bool has_datetime_args() {
DBUG_ASSERT(fixed);
for (uint i = 0; i < arg_count; i++) {
if (args[i]->type() == Item::FIELD_ITEM &&
args[i]->data_type() == MYSQL_TYPE_DATETIME)
return true;
}
return false;
}
/*
We assume the result of any function that has a TIMESTAMP argument to be
timezone-dependent, since a TIMESTAMP value in both numeric and string
contexts is interpreted according to the current timezone.
The only exception is UNIX_TIMESTAMP() which returns the internal
representation of a TIMESTAMP argument verbatim, and thus does not depend on
the timezone.
*/
bool check_valid_arguments_processor(uchar *) override {
return has_timestamp_args();
}
Item *gc_subst_transformer(uchar *arg) override;
/**
Does essentially the same as THD::change_item_tree, plus
maintains any necessary any invariants.
*/
virtual void replace_argument(THD *thd, Item **oldpp, Item *newp);
/**
Whether an arg of a JSON function can be cached to avoid repetitive
string->JSON conversion. This function returns true only for those args,
which are the source of JSON data. JSON path args are cached independently
and for them this function returns false. Same as for all other type of
args.
@param arg the arg to cache
@retval true arg can be cached
@retval false otherwise
*/
virtual enum_const_item_cache can_cache_json_arg(
Item *arg MY_ATTRIBUTE((unused))) {
return CACHE_NONE;
}
/// Whether this Item is an equi-join condition. If this Item is a compound
/// item (i.e. multiple condition AND'ed together), it will only return true
/// if the Item contains only equi-join conditions AND'ed together. This is
/// used to determine whether the condition can be used as a join condition
/// for hash join (join conditions in hash join must be equi-join conditions),
/// or if it should be placed as a filter after the join.
virtual bool contains_only_equi_join_condition() const { return false; }
bool ensure_multi_equality_fields_are_available_walker(uchar *) override;
protected:
/**
Whether or not an item should contribute to the filtering effect
(@see get_filtering_effect()). First it verifies that table
requirements are satisfied as follows:
1) The item must refer to a field in 'filter_for_table' in some
way. This reference may be indirect through any number of
intermediate items. For example, this item may be an
Item_cond_and which refers to an Item_func_eq which refers to
the field.
2) The item must not refer to other tables than those already
read and the table in 'filter_for_table'
Then it contines to other properties as follows:
Item_funcs represent "<operand1> OP <operand2> [OP ...]". If the
Item_func is to contribute to the filtering effect, then
1) one of the operands must be a field from 'filter_for_table' that is not
in 'fields_to_ignore', and
2) depending on the Item_func type filtering effect is calculated
for, one or all [1] of the other operand(s) must be an available
value, i.e.:
- a constant, or
- a constant subquery, or
- a field value read from a table in 'read_tables', or
- a second field in 'filter_for_table', or
- a function that only refers to constants or tables in
'read_tables', or
- special case: an implicit value like NULL in the case of
"field IS NULL". Such Item_funcs have arg_count==1.
[1] "At least one" for multiple equality (X = Y = Z = ...), "all"
for the rest (e.g. BETWEEN)
@param read_tables Tables earlier in the join sequence.
Predicates for table 'filter_for_table' that
rely on values from these tables can be part of
the filter effect.
@param filter_for_table The table we are calculating filter effect for
@param fields_to_ignore Columns that should be ignored.
@return Item_field that participates in the predicate if none of the
requirements are broken, NULL otherwise
@note: This function only applies to items doing comparison, i.e.
boolean predicates. Unfortunately, some of those items do not
inherit from Item_bool_func so the member function has to be
placed in Item_func.
*/
const Item_field *contributes_to_filter(
table_map read_tables, table_map filter_for_table,
const MY_BITMAP *fields_to_ignore) const;
/**
Named parameters are allowed in a parameter list
The syntax to name parameters in a function call is as follow:
<code>foo(expr AS named, expr named, expr AS "named", expr "named")</code>
where "AS" is optional.
Only UDF function support that syntax.
@return true if the function item can have named parameters
*/
virtual bool may_have_named_parameters() const { return false; }
virtual bool is_non_const_over_literals(uchar *) override { return false; }
bool check_function_as_value_generator(uchar *checker_args) override {
if (is_deprecated()) {
Check_function_as_value_generator_parameters *func_arg =
pointer_cast<Check_function_as_value_generator_parameters *>(
checker_args);
func_arg->banned_function_name = func_name();
return true;
}
return false;
}
};
class Item_real_func : public Item_func {
public:
Item_real_func() : Item_func() { set_data_type_double(); }
explicit Item_real_func(const POS &pos) : Item_func(pos) {
set_data_type_double();
}
Item_real_func(Item *a) : Item_func(a) { set_data_type_double(); }
Item_real_func(const POS &pos, Item *a) : Item_func(pos, a) {
set_data_type_double();
}
Item_real_func(Item *a, Item *b) : Item_func(a, b) { set_data_type_double(); }
Item_real_func(const POS &pos, Item *a, Item *b) : Item_func(pos, a, b) {
set_data_type_double();
}
Item_real_func(List<Item> &list) : Item_func(list) { set_data_type_double(); }
Item_real_func(const POS &pos, PT_item_list *list) : Item_func(pos, list) {
set_data_type_double();
}
String *val_str(String *str) override;
my_decimal *val_decimal(my_decimal *decimal_value) override;
longlong val_int() override {
DBUG_ASSERT(fixed);
return llrint_with_overflow_check(val_real());
}
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
return get_date_from_real(ltime, fuzzydate);
}
bool get_time(MYSQL_TIME *ltime) override {
return get_time_from_real(ltime);
}
enum Item_result result_type() const override { return REAL_RESULT; }
bool resolve_type(THD *) override { return false; }
};
class Item_func_numhybrid : public Item_func {
protected:
Item_result hybrid_type;
public:
Item_func_numhybrid(Item *a) : Item_func(a), hybrid_type(REAL_RESULT) {
collation.set_numeric();
}
Item_func_numhybrid(const POS &pos, Item *a)
: Item_func(pos, a), hybrid_type(REAL_RESULT) {
collation.set_numeric();
}
Item_func_numhybrid(Item *a, Item *b)
: Item_func(a, b), hybrid_type(REAL_RESULT) {
collation.set_numeric();
}
Item_func_numhybrid(const POS &pos, Item *a, Item *b)
: Item_func(pos, a, b), hybrid_type(REAL_RESULT) {
collation.set_numeric();
}
Item_func_numhybrid(List<Item> &list)
: Item_func(list), hybrid_type(REAL_RESULT) {
collation.set_numeric();
}
Item_func_numhybrid(const POS &pos, PT_item_list *list)
: Item_func(pos, list), hybrid_type(REAL_RESULT) {
collation.set_numeric();
}
enum Item_result result_type() const override { return hybrid_type; }
bool resolve_type(THD *thd) override;
void fix_num_length_and_dec() override;
virtual void set_numeric_type() = 0; // To be called from resolve_type()
double val_real() override;
longlong val_int() override;
my_decimal *val_decimal(my_decimal *) override;
String *val_str(String *str) override;
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
bool get_time(MYSQL_TIME *ltime) override;
/**
@brief Performs the operation that this functions implements when the
result type is INT.
@return The result of the operation.
*/
virtual longlong int_op() = 0;
/**
@brief Performs the operation that this functions implements when the
result type is REAL.
@return The result of the operation.
*/
virtual double real_op() = 0;
/**
@brief Performs the operation that this functions implements when the
result type is DECIMAL.
@param decimal_value A pointer where the DECIMAL value will be allocated.
@return
- 0 If the result is NULL
- The same pointer it was given, with the area initialized to the
result of the operation.
*/
virtual my_decimal *decimal_op(my_decimal *decimal_value) = 0;
/**
@brief Performs the operation that this functions implements when the
result type is a string type.
@return The result of the operation.
*/
virtual String *str_op(String *) = 0;
/**
@brief Performs the operation that this functions implements when the
result type is MYSQL_TYPE_DATE or MYSQL_TYPE_DATETIME.
@return The result of the operation.
*/
virtual bool date_op(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) = 0;
virtual bool time_op(MYSQL_TIME *ltime) = 0;
bool is_null() override {
/*
TODO : Implement error handling for this function as
update_null_value() can return error.
*/
(void)update_null_value();
return null_value;
}
};
/* function where type of result detected by first argument */
class Item_func_num1 : public Item_func_numhybrid {
public:
Item_func_num1(Item *a) : Item_func_numhybrid(a) {}
Item_func_num1(const POS &pos, Item *a) : Item_func_numhybrid(pos, a) {}
Item_func_num1(Item *a, Item *b) : Item_func_numhybrid(a, b) {}
Item_func_num1(const POS &pos, Item *a, Item *b)
: Item_func_numhybrid(pos, a, b) {}
void fix_num_length_and_dec() override;
void set_numeric_type() override;
String *str_op(String *) override {
DBUG_ASSERT(0);
return nullptr;
}
bool date_op(MYSQL_TIME *, my_time_flags_t) override {
DBUG_ASSERT(0);
return false;
}
bool time_op(MYSQL_TIME *) override {
DBUG_ASSERT(0);
return false;
}
};
/* Base class for operations like '+', '-', '*' */
class Item_num_op : public Item_func_numhybrid {
public:
Item_num_op(Item *a, Item *b) : Item_func_numhybrid(a, b) {}
Item_num_op(const POS &pos, Item *a, Item *b)
: Item_func_numhybrid(pos, a, b) {}
virtual void result_precision() = 0;
void print(const THD *thd, String *str,
enum_query_type query_type) const override {
print_op(thd, str, query_type);
}
void set_numeric_type() override;
String *str_op(String *) override {
DBUG_ASSERT(0);
return nullptr;
}
bool date_op(MYSQL_TIME *, my_time_flags_t) override {
DBUG_ASSERT(0);
return false;
}
bool time_op(MYSQL_TIME *) override {
DBUG_ASSERT(0);
return false;
}
};
class Item_int_func : public Item_func {
public:
Item_int_func() : Item_func() { set_data_type_longlong(); }
explicit Item_int_func(const POS &pos) : Item_func(pos) {
set_data_type_longlong();
}
Item_int_func(Item *a) : Item_func(a) { set_data_type_longlong(); }
Item_int_func(const POS &pos, Item *a) : Item_func(pos, a) {
set_data_type_longlong();
}
Item_int_func(Item *a, Item *b) : Item_func(a, b) {
set_data_type_longlong();
}
Item_int_func(const POS &pos, Item *a, Item *b) : Item_func(pos, a, b) {
set_data_type_longlong();
}
Item_int_func(Item *a, Item *b, Item *c) : Item_func(a, b, c) {
set_data_type_longlong();
}
Item_int_func(const POS &pos, Item *a, Item *b, Item *c)
: Item_func(pos, a, b, c) {
set_data_type_longlong();
}
Item_int_func(Item *a, Item *b, Item *c, Item *d) : Item_func(a, b, c, d) {
set_data_type_longlong();
}
Item_int_func(const POS &pos, Item *a, Item *b, Item *c, Item *d)
: Item_func(pos, a, b, c, d) {
set_data_type_longlong();
}
Item_int_func(List<Item> &list) : Item_func(list) {
set_data_type_longlong();
}
Item_int_func(const POS &pos, PT_item_list *opt_list)
: Item_func(pos, opt_list) {
set_data_type_longlong();
}
Item_int_func(THD *thd, Item_int_func *item) : Item_func(thd, item) {
set_data_type_longlong();
}
double val_real() override;
String *val_str(String *str) override;
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
return get_date_from_int(ltime, fuzzydate);
}
bool get_time(MYSQL_TIME *ltime) override { return get_time_from_int(ltime); }
enum Item_result result_type() const override { return INT_RESULT; }
bool resolve_type(THD *) override { return false; }
};
class Item_func_connection_id final : public Item_int_func {
typedef Item_int_func super;
longlong value;
public:
Item_func_connection_id(const POS &pos) : Item_int_func(pos) {}
bool itemize(Parse_context *pc, Item **res) override;
const char *func_name() const override { return "connection_id"; }
bool resolve_type(THD *thd) override;
bool fix_fields(THD *thd, Item **ref) override;
longlong val_int() override {
DBUG_ASSERT(fixed);
return value;
}
bool check_function_as_value_generator(uchar *checker_args) override {
Check_function_as_value_generator_parameters *func_arg =
pointer_cast<Check_function_as_value_generator_parameters *>(
checker_args);
func_arg->banned_function_name = func_name();
return ((func_arg->source == VGS_GENERATED_COLUMN) ||
(func_arg->source == VGS_CHECK_CONSTRAINT));
}
};
class Item_typecast_signed : public Item_int_func {
public:
Item_typecast_signed(const POS &pos, Item *a) : Item_int_func(pos, a) {
unsigned_flag = false;
}
const char *func_name() const override { return "cast_as_signed"; }
longlong val_int() override;
longlong val_int_from_str(int *error);
bool resolve_type(THD *thd) override;
void print(const THD *thd, String *str,
enum_query_type query_type) const override;
uint decimal_precision() const override {
return args[0]->decimal_precision();
}
enum Functype functype() const override { return TYPECAST_FUNC; }
};
class Item_typecast_unsigned final : public Item_typecast_signed {
public:
Item_typecast_unsigned(const POS &pos, Item *a)
: Item_typecast_signed(pos, a) {
unsigned_flag = true;
}
const char *func_name() const override { return "cast_as_unsigned"; }
longlong val_int() override;
void print(const THD *thd, String *str,
enum_query_type query_type) const override;
enum Functype functype() const override { return TYPECAST_FUNC; }
};
class Item_typecast_decimal final : public Item_func {
public:
Item_typecast_decimal(const POS &pos, Item *a, int len, int dec)
: Item_func(pos, a) {
set_data_type_decimal(len, dec);
}
String *val_str(String *str) override;
double val_real() override;
longlong val_int() override;
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override {
return get_date_from_decimal(ltime, fuzzydate);
}
bool get_time(MYSQL_TIME *ltime) override {
return get_time_from_decimal(ltime);
}
my_decimal *val_decimal(my_decimal *) override;
enum Item_result result_type() const override { return DECIMAL_RESULT; }
bool resolve_type(THD *) override { return false; }
const char *func_name() const override { return "cast_as_decimal"; }
enum Functype functype() const override { return TYPECAST_FUNC; }
void print(const THD *thd, String *str,
enum_query_type query_type) const override;
};
/**
Class used to implement CAST to floating-point data types.
*/
class Item_typecast_real final : public Item_func {
public:
Item_typecast_real(const POS &pos, Item *a, bool as_double)
: Item_func(pos, a) {
if (as_double)
set_data_type_double();
else
set_data_type_float();
}
Item_typecast_real(Item *a) : Item_func(a) { set_data_type_double(); }
String *val_str(String *str) override;
double val_real() override;
longlong val_int() override;
bool get_date(MYSQL_TIME *ltime, my_time_flags_t fuzzydate) override;
bool get_time(MYSQL_TIME *ltime) override;
my_decimal *val_decimal(my_decimal *decimal_value) override;
enum Item_result result_type() const override { return REAL_RESULT; }
bool resolve_type(THD *) override { return false; }
const char *func_name() const override { return "cast_as_real"; }
enum Functype functype() const override { return TYPECAST_FUNC; }
void print(const THD *thd, String *str,
enum_query_type query_type) const override;
};
class Item_func_additive_op : public Item_num_op {
public:
Item_func_additive_op(Item *a, Item *b) : Item_num_op(a, b) {}
Item_func_additive_op(const POS &pos, Item *a, Item *b)
: Item_num_op(pos, a, b) {}
void result_precision() override;
bool check_partition_func_processor(uchar *) override { return false; }
bool check_function_as_value_generator(uchar *) override { return false; }