-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathitem.h
1020 lines (915 loc) · 22.2 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_H
#define ITEM_H
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include "variant.hpp"
#include "mysql_com.h"
#include "sql_type_bool.h"
#include "sql_type_double.h"
#include "sql_type_int.h"
#include "sql_type_decimal.h"
#include "opt.h"
#include "vm.h"
using namespace std;
class Stat
{
public:
longlong sum_ll;
double sum_d;
double time_spent;
const char *method;
bool use_sum_d;
Stat()
:sum_ll(0), sum_d(0), time_spent(0), method(""), use_sum_d(false)
{ }
};
class StatAll
{
public:
Stat val_xxx;
Stat val_xxx_null;
Stat get_xxx;
Stat to_xxx_null;
StatAll(const Stat &a, const Stat &b, const Stat &c, const Stat &d)
:val_xxx(a),
val_xxx_null(b),
get_xxx(c),
to_xxx_null(d)
{ }
};
class MethodStat
{
public:
double val_xxx;
double val_xxx_null;
double get_xxx;
double to_xxx_null;
MethodStat(const StatAll &st)
:val_xxx(st.val_xxx.time_spent),
val_xxx_null(st.val_xxx_null.time_spent),
get_xxx(st.get_xxx.time_spent),
to_xxx_null(st.to_xxx_null.time_spent)
{ }
MethodStat(double a, double b, double c, double d)
:val_xxx(a), val_xxx_null(b), get_xxx(c), to_xxx_null(d)
{ }
MethodStat(): MethodStat(0, 0, 0, 0) { }
MethodStat operator+(const MethodStat &st) const
{
return MethodStat(val_xxx + st.val_xxx,
val_xxx_null + st.val_xxx_null,
get_xxx + st.get_xxx,
to_xxx_null + st.to_xxx_null);
}
MethodStat &operator+=(const MethodStat &st)
{
val_xxx+= st.val_xxx;
val_xxx_null+= st.val_xxx_null;
get_xxx+= st.get_xxx;
to_xxx_null+= st.to_xxx_null;
return *this;
}
bool is_empty() const
{
return
val_xxx == 0 &&
val_xxx_null == 0 &&
get_xxx == 0 &&
to_xxx_null == 0;
}
void print(const char *method) const;
void print_if(const char *method) const
{
if (!is_empty())
print(method);
}
};
class MethodStatByType
{
public:
MethodStat st_bool;
MethodStat st_int32;
MethodStat st_longlong;
MethodStat st_double;
MethodStat st_decimal;
MethodStatByType operator+=(const MethodStatByType &st)
{
st_bool+= st.st_bool;
st_int32+= st.st_int32;
st_longlong+= st.st_longlong;
st_double+= st.st_double;
st_decimal+= st.st_decimal;
return *this;
}
MethodStat total() const
{
MethodStat st;
st+= st_bool;
st+= st_int32;
st+= st_longlong;
st+= st_double;
st+= st_decimal;
return st;
}
void print() const;
};
class Item
{
char filler[0x7E];
public:
#ifdef HAVE_NULL_VALUE
bool null_value;
virtual bool val_bool()= 0;
virtual double val_real()= 0;
virtual longlong val_int()= 0;
virtual int32 val_int32()= 0;
virtual my_decimal *val_decimal(my_decimal *decimal_buffer)= 0;
Stat test_b_old(const Options &opt);
Stat test_d_old(const Options &opt);
Stat test_int32_old(const Options &opt);
Stat test_ll_old(const Options &opt);
Stat test_native_old(const Options &opt);
Stat test_dec_old(const Options &opt);
#endif
virtual ~Item() { }
virtual enum_field_types field_type() const= 0;
virtual void print(string *to)= 0;
virtual bool gen(VM *to) { return true; }
virtual bool val_bool_null(bool *null_value_arg)= 0;
virtual longlong val_int_null(bool *null_value_arg)= 0;
virtual int32 val_int32_null(bool *null_value_arg)= 0;
virtual double val_real_null(bool *null_value_arg)= 0;
virtual my_decimal val_decimal_null(bool *null_value_arg)= 0;
virtual bool get_bool(bool *to)= 0;
virtual bool get_longlong(longlong *to)= 0;
virtual bool get_int32(int32 *to)= 0;
virtual bool get_double(double *to)= 0;
virtual bool get_decimal(my_decimal *to)= 0;
virtual Bool_null to_bool_null()= 0;
virtual Longlong_null to_longlong_null()= 0;
virtual Int32_null to_int32_null()= 0;
virtual Double_null to_double_null()= 0;
virtual Decimal_null to_decimal_null()= 0;
Stat test_native_prm(const Options &opt);
Stat test_native_get(const Options &opt);
Stat test_native_new(const Options &opt);
Stat test_b_prm(const Options &opt);
Stat test_b_get(const Options &opt);
Stat test_b_new(const Options &opt);
Stat test_d_prm(const Options &opt);
Stat test_d_get(const Options &opt);
Stat test_d_new(const Options &opt);
Stat test_dec_prm(const Options &opt);
Stat test_dec_get(const Options &opt);
Stat test_dec_new(const Options &opt);
Stat test_int32_prm(const Options &opt);
Stat test_int32_get(const Options &opt);
Stat test_int32_new(const Options &opt);
Stat test_ll_prm(const Options &opt);
Stat test_ll_get(const Options &opt);
Stat test_ll_new(const Options &opt);
Stat test_b_vm(VM *vm, const Options &opt);
Stat test_ll_vm(VM *vm, const Options &opt);
Stat test_d_vm(VM *vm, const Options &opt);
Stat test_dec_vm(VM *vm, const Options &opt);
};
class Item_null: public Item
{
public:
Item_null()
{
#ifdef HAVE_NULL_VALUE
null_value= true;
#endif
}
enum_field_types field_type() const override { return MYSQL_TYPE_NULL; }
void print(string *to) override;
#ifdef HAVE_NULL_VALUE
bool val_bool() override
{
return false;
}
longlong val_int() override
{
return 0;
}
int32 val_int32() override
{
return 0;
}
double val_real() override
{
return 0e0;
}
my_decimal* val_decimal(my_decimal *decimal_buffer) override
{
decimal_make_zero(decimal_buffer);
return decimal_buffer;
}
#endif
bool val_bool_null(bool *null_value_arg) override
{
*null_value_arg= true;
return false;
}
longlong val_int_null(bool *null_value_arg) override
{
*null_value_arg= true;
return 0;
}
int32 val_int32_null(bool *null_value_arg) override
{
*null_value_arg= true;
return 0;
}
double val_real_null(bool *null_value_arg) override
{
*null_value_arg= true;
return 0e0;
}
my_decimal val_decimal_null(bool *null_value_arg) override
{
*null_value_arg= true;
return my_decimal();
}
bool get_bool(bool *to) override { return true; }
bool get_longlong(longlong *to) override { return true; }
bool get_int32(int32 *to) override { return true; }
bool get_double(double *to) override { return true; }
bool get_decimal(my_decimal *to) override { return true; }
Bool_null to_bool_null() override
{
return Bool_null();
}
Longlong_null to_longlong_null() override
{
return Longlong_null();
}
Int32_null to_int32_null() override
{
return Int32_null();
}
Double_null to_double_null() override
{
return Double_null();
}
Decimal_null to_decimal_null() override
{
return Decimal_null();
}
};
class Item_bool: public Item
{
Bool_null bnval;
bool val;
public:
Item_bool(bool val_arg)
:bnval(val_arg), val(val_arg)
{
#ifdef HAVE_NULL_VALUE
null_value= false;
#endif
}
enum_field_types field_type() const override { return MYSQL_TYPE_BOOL; }
void print(string *to) override;
#ifdef HAVE_NULL_VALUE
bool val_bool() override
{
return val;
}
longlong val_int() override
{
return val;
}
int32 val_int32() override
{
return val;
}
double val_real() override
{
return val;
}
my_decimal *val_decimal(my_decimal *decimal_buffer) override
{
ulonglong2decimal(val, decimal_buffer);
return decimal_buffer;
}
#endif
bool val_bool_null(bool *null_value_arg) override
{
*null_value_arg= false;
return val;
}
longlong val_int_null(bool *null_value_arg) override
{
*null_value_arg= false;
return val;
}
int32 val_int32_null(bool *null_value_arg) override
{
*null_value_arg= false;
return val;
}
double val_real_null(bool *null_value_arg) override
{
*null_value_arg= false;
return val;
}
my_decimal val_decimal_null(bool *null_value_arg) override
{
*null_value_arg= false;
return my_decimal((longlong)val);
}
bool get_bool(bool *to) override
{
*to= val;
return false;
}
bool get_longlong(longlong *to) override
{
*to= val;
return false;
}
bool get_int32(int32 *to) override
{
*to= val;
return false;
}
bool get_double(double *to) override
{
*to= val;
return false;
}
bool get_decimal(my_decimal *to) override
{
ulonglong2decimal((longlong)val, to);
return false;
}
Bool_null to_bool_null() override
{
return bnval;//Bool_null(val);
}
Longlong_null to_longlong_null() override
{
return Longlong_null(val);
}
Int32_null to_int32_null() override
{
return Int32_null(val);
}
Double_null to_double_null() override
{
return Double_null(val);
}
Decimal_null to_decimal_null() override
{
return Decimal_null((longlong)val);
}
};
class Item_int: public Item
{
longlong val;
public:
Item_int(longlong val_arg)
:val(val_arg)
{
#ifdef HAVE_NULL_VALUE
null_value= false;
#endif
}
enum_field_types field_type() const override { return MYSQL_TYPE_LONGLONG; }
void print(string *to) override;
#ifdef HAVE_NULL_VALUE
bool val_bool() override
{
return (bool) val;
}
longlong val_int() override
{
return val;
}
int32 val_int32() override
{
return (int32) val;
}
double val_real() override
{
return (double) val;
}
my_decimal *val_decimal(my_decimal *decimal_buffer) override
{
ulonglong2decimal(val, decimal_buffer);
return decimal_buffer;
}
#endif
bool val_bool_null(bool *null_value_arg) override
{
*null_value_arg= false;
return (bool) val;
}
longlong val_int_null(bool *null_value_arg) override
{
*null_value_arg= false;
return val;
}
int32 val_int32_null(bool *null_value_arg) override
{
*null_value_arg= false;
return val;
}
double val_real_null(bool *null_value_arg) override
{
*null_value_arg= false;
return (double) val;
}
my_decimal val_decimal_null(bool *null_value_arg) override
{
*null_value_arg= false;
return my_decimal((longlong)val);
}
bool get_bool(bool *to) override
{
*to= val;
return false;
}
bool get_longlong(longlong *to) override
{
*to= val;
return false;
}
bool get_int32(int32 *to) override
{
*to= (int32) val;
return false;
}
bool get_double(double *to) override
{
*to= val;
return false;
}
bool get_decimal(my_decimal *to) override
{
ulonglong2decimal((longlong)val, to);
return false;
}
Bool_null to_bool_null() override
{
return Bool_null((bool) val);
}
Longlong_null to_longlong_null() override
{
return Longlong_null(val);
}
Int32_null to_int32_null() override
{
return Int32_null(val);
}
Double_null to_double_null() override
{
return Double_null((double) val);
}
Decimal_null to_decimal_null() override
{
return Decimal_null((longlong) val);
}
};
class Item_real: public Item
{
double val;
public:
Item_real(double val_arg)
:val(val_arg)
{
#ifdef HAVE_NULL_VALUE
null_value= false;
#endif
}
enum_field_types field_type() const override { return MYSQL_TYPE_DOUBLE; }
void print(string *to) override;
#ifdef HAVE_NULL_VALUE
bool val_bool() override
{
return (bool) val;
}
double val_real() override
{
return val;
}
longlong val_int() override
{
return (longlong) val;
}
int32 val_int32() override
{
return (int32) val;
}
my_decimal *val_decimal(my_decimal *decimal_buffer) override
{
double2decimal(val, decimal_buffer);
return decimal_buffer;
}
#endif
bool val_bool_null(bool *null_value_arg) override
{
*null_value_arg= false;
return (bool) val;
}
double val_real_null(bool *null_value_arg) override
{
*null_value_arg= false;
return val;
}
longlong val_int_null(bool *null_value_arg) override
{
*null_value_arg= false;
return (longlong) val;
}
int32 val_int32_null(bool *null_value_arg) override
{
*null_value_arg= false;
return (int32) val;
}
my_decimal val_decimal_null(bool *null_value_arg) override
{
*null_value_arg= false;
return my_decimal(val);
}
bool get_bool(bool *to) override
{
*to= val;
return false;
}
bool get_longlong(longlong *to) override
{
*to= val;
return false;
}
bool get_int32(int32 *to) override
{
*to= (int32) val;
return false;
}
bool get_double(double *to) override
{
*to= val;
return false;
}
bool get_decimal(my_decimal *to) override
{
double2decimal((longlong)val, to);
return false;
}
Bool_null to_bool_null() override
{
return Bool_null((bool) val);
}
Double_null to_double_null() override
{
return Double_null((double)val);
}
Decimal_null to_decimal_null() override
{
return Decimal_null((longlong)val);
}
Longlong_null to_longlong_null() override
{
return Longlong_null((longlong) val);
}
Int32_null to_int32_null() override
{
return Int32_null((int32) val);
}
};
class Item_decimal: public Item
{
my_decimal val;
public:
Item_decimal(my_decimal &val_arg)
:val(val_arg)
{
#ifdef HAVE_NULL_VALUE
null_value= false;
#endif
}
Item_decimal(double dbl)
:val(dbl)
{
#ifdef HAVE_NULL_VALUE
null_value= false;
#endif
}
Item_decimal(longlong lng)
:val(lng)
{
#ifdef HAVE_NULL_VALUE
null_value= false;
#endif
}
enum_field_types field_type() const override { return MYSQL_TYPE_NEWDECIMAL; }
void print(string *to) override;
#ifdef HAVE_NULL_VALUE
bool val_bool() override
{
longlong res;
decimal2longlong(&val, &res);
return (bool) res;
}
double val_real() override
{
double res;
decimal2double(&val, &res);
return res;
}
longlong val_int() override
{
longlong res;
decimal2longlong(&val, &res);
return (longlong) res;
}
int32 val_int32() override
{
longlong res;
decimal2longlong(&val, &res);
return (int32) res;
}
my_decimal *val_decimal(my_decimal *decimal_buffer) override
{
return &val;
}
#endif
bool val_bool_null(bool *null_value_arg) override
{
*null_value_arg= false;
longlong res;
decimal2longlong(&val, &res);
return (bool) res;
}
double val_real_null(bool *null_value_arg) override
{
*null_value_arg= false;
double res;
decimal2double(&val, &res);
return res;
}
longlong val_int_null(bool *null_value_arg) override
{
*null_value_arg= false;
longlong res;
decimal2longlong(&val, &res);
return (longlong) res;
}
int32 val_int32_null(bool *null_value_arg) override
{
*null_value_arg= false;
longlong res;
decimal2longlong(&val, &res);
return (int32) res;
}
my_decimal val_decimal_null(bool *null_value_arg) override
{
*null_value_arg= false;
return my_decimal(val);
}
bool get_bool(bool *to) override
{
longlong res;
decimal2longlong(&val, &res);
*to= res;
return false;
}
bool get_longlong(longlong *to) override
{
decimal2longlong(&val, to);
return false;
}
bool get_int32(int32 *to) override
{
longlong res;
decimal2longlong(&val, &res);
*to= (int32) res;
return false;
}
bool get_double(double *to) override
{
decimal2double(&val, to);
return false;
}
bool get_decimal(my_decimal *to) override
{
(*to)= val;
return false;
}
Bool_null to_bool_null() override
{
longlong res;
decimal2longlong(&val, &res);
return Bool_null((bool) res);
}
Double_null to_double_null() override
{
double res;
decimal2double(&val, &res);
return Double_null((double)res);
}
Decimal_null to_decimal_null() override
{
return Decimal_null(val);
}
Longlong_null to_longlong_null() override
{
longlong res;
decimal2longlong(&val, &res);
return Longlong_null((longlong) res);
}
Int32_null to_int32_null() override
{
longlong res;
decimal2longlong(&val, &res);
return Int32_null((int32) res);
}
};
Item *generate_node(size_t depth_left,
std::vector<std::unique_ptr<Item>> &storage);
static inline std::pair<Item *, std::vector<std::unique_ptr<Item>>>
generate_tree(size_t max_depth)
{
assert(max_depth > 0);
std::vector<std::unique_ptr<Item>> storage;
Item *root= generate_node(max_depth, storage);
// std::string as_string;
// root->print(&as_string);
// std::cout << " " << as_string << '\n';
assert(!storage.empty());
return {root, std::move(storage)};
}
namespace variant
{
// variant is a 'tagged union'
// Somethig like enum + union { Type1 t1; Type2 t2; Type3, t3; ...}
// It's safe to write code like variant<int, std::string> because variant
// will always call a correct dtor and you won't have any memory leaks.
// See more at https://en.cppreference.com/w/cpp/utility/variant
struct Item_int;
struct Item_func_uminus;
struct Item_func_isnull;
struct Item_func_add;
// This is our polymorphic item class.
using Item= mpark::variant<Item_int, Item_func_uminus, Item_func_isnull, Item_func_add>;
struct Item_int
{
longlong val;
Item_int(longlong val) : val(val) {}
enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; }
Bool_null to_bool_null() { return Bool_null(static_cast<bool>(val)); }
Longlong_null to_longlong_null() { return Longlong_null(val); }
Int32_null to_int32_null() { return Int32_null(static_cast<int32>(val)); }
Double_null to_double_null() { return Double_null(val); }
Decimal_null to_decimal_null() { return Decimal_null(val); }
};
struct Item_func
{
Item *args[3];
uint arg_count;
Item_func(Item *a) : args{a, nullptr, nullptr}, arg_count(1) {}
Item_func(Item *a, Item *b) : args{a, b, nullptr}, arg_count(2) {}
Item_func(Item *a, Item *b, Item *c) : args{a, b, c}, arg_count(3) {}
uint argument_count() const { return arg_count; }
Item **arguments() { return args; }
};
struct Hybrid_field_type
{
enum_field_types m_field_type;
Hybrid_field_type(enum_field_types t) : m_field_type(t) {}
Hybrid_field_type(enum_field_types ta, enum_field_types tb)
{
if (ta == tb)
m_field_type= ta;
else if (ta == MYSQL_TYPE_NULL || tb == MYSQL_TYPE_NULL)
m_field_type= my_max(ta, tb);
else if (ta == MYSQL_TYPE_DOUBLE || tb == MYSQL_TYPE_DOUBLE)
m_field_type= MYSQL_TYPE_DOUBLE;
else if (ta == MYSQL_TYPE_LONGLONG || tb == MYSQL_TYPE_LONGLONG)
m_field_type= MYSQL_TYPE_LONGLONG;
else
m_field_type= MYSQL_TYPE_NEWDECIMAL;
}
Hybrid_field_type(enum_field_types ta, enum_field_types tb,
enum_field_types tc)
: Hybrid_field_type(Hybrid_field_type(ta, tb).m_field_type, tc)
{
}
};
struct Item_hybrid_func : Item_func, Hybrid_field_type
{
inline Item_hybrid_func(Item *a);
inline Item_hybrid_func(Item *a, Item *b);
inline Item_hybrid_func(Item *a, Item *b, Item *c);
};
struct Item_func_add : Item_hybrid_func
{
Item_func_add(Item *a, Item *b) : Item_hybrid_func(a, b) {}
enum_field_types field_type() const { return m_field_type; }
Bool_null to_bool_null();
Longlong_null to_longlong_null();
Int32_null to_int32_null();
Double_null to_double_null();
Decimal_null to_decimal_null();
};
struct Item_func_uminus : Item_hybrid_func
{
Item_func_uminus(Item *a) : Item_hybrid_func(a) {}
enum_field_types field_type() const { return m_field_type; }
Bool_null to_bool_null();
Longlong_null to_longlong_null();
Int32_null to_int32_null();
Double_null to_double_null();
Decimal_null to_decimal_null();
};
struct Item_func_isnull : Item_func
{
enum_field_types m_arg0_field_type;
inline Item_func_isnull(Item *a);
enum_field_types field_type() const { return MYSQL_TYPE_BOOL; }
Bool_null to_bool_null();
Longlong_null to_longlong_null()
{
Bool_null val= Item_func_isnull::to_bool_null();
return Longlong_null(val.value, val.is_null);
}
Int32_null to_int32_null()
{
Bool_null val= Item_func_isnull::to_bool_null();
return Int32_null(val.value, val.is_null);
}
Double_null to_double_null()
{
Bool_null val= Item_func_isnull::to_bool_null();
return Double_null(val.value, val.is_null);
}
Decimal_null to_decimal_null()
{
Bool_null val= Item_func_isnull::to_bool_null();
return Decimal_null((const longlong)val.value, val.is_null);
}
};
// This is a direct replacement for virtual function calls. A different kind of dispatcher.
#define SWITCH_CALL_RETURN(ITEM, METHOD) \
switch (ITEM.index()) \
{ \
case 0: \
return mpark::get<Item_int>(ITEM).METHOD(); \
case 1: \
return mpark::get<Item_func_uminus>(ITEM).METHOD(); \
case 2: \
return mpark::get<Item_func_isnull>(ITEM).METHOD(); \
case 3: \
return mpark::get<Item_func_add>(ITEM).METHOD(); \
default: \
__builtin_unreachable(); \
}
static inline enum_field_types field_type(Item &item)
{
SWITCH_CALL_RETURN(item, field_type);
};
static inline Bool_null to_bool_null(Item &item)
{
SWITCH_CALL_RETURN(item, to_bool_null);
};
static inline Longlong_null to_longlong_null(Item &item)
{
SWITCH_CALL_RETURN(item, to_longlong_null);
};
static inline Int32_null to_int32_null(Item &item)
{
SWITCH_CALL_RETURN(item, to_int32_null);
};
static inline Double_null to_double_null(Item &item)
{
SWITCH_CALL_RETURN(item, to_double_null);
};
static inline Decimal_null to_decimal_null(Item &item)
{
SWITCH_CALL_RETURN(item, to_decimal_null);
};
Item_hybrid_func::Item_hybrid_func(Item *a)
: Item_func(a), Hybrid_field_type(field_type(*a))
{
}