-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathfield.h
6060 lines (5666 loc) · 219 KB
/
field.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 FIELD_INCLUDED
#define FIELD_INCLUDED
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates.
Copyright (c) 2008, 2021, MariaDB Corporation.
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-1335 USA */
/*
Because of the function make_new_field() all field classes that have static
variables must declare the size_of() member function.
*/
#include "mysqld.h" /* system_charset_info */
#include "table.h" /* TABLE */
#include "sql_string.h" /* String */
#include "my_decimal.h" /* my_decimal */
#include "sql_error.h" /* Sql_condition */
#include "compat56.h"
#include "sql_type.h" /* Type_std_attributes */
#include "field_comp.h"
class Send_field;
class Copy_field;
class Protocol;
class Protocol_text;
class Create_field;
class Relay_log_info;
class Field;
class Column_statistics;
class Column_statistics_collected;
class Item_func;
class Item_bool_func;
class Item_equal;
class Virtual_tmp_table;
class Qualified_column_ident;
class Table_ident;
class SEL_ARG;
class RANGE_OPT_PARAM;
struct KEY_PART;
struct SORT_FIELD;
struct SORT_FIELD_ATTR;
enum enum_check_fields
{
CHECK_FIELD_IGNORE,
CHECK_FIELD_EXPRESSION,
CHECK_FIELD_WARN,
CHECK_FIELD_ERROR_FOR_NULL,
};
enum ignore_value_reaction
{
IGNORE_MEANS_ERROR,
IGNORE_MEANS_DEFAULT,
IGNORE_MEANS_FIELD_VALUE
};
ignore_value_reaction find_ignore_reaction(THD *thd);
enum enum_conv_type
{
CONV_TYPE_PRECISE,
CONV_TYPE_VARIANT,
CONV_TYPE_SUBSET_TO_SUPERSET,
CONV_TYPE_SUPERSET_TO_SUBSET,
CONV_TYPE_IMPOSSIBLE
};
/* Old 32 bit timestamp */
extern const uchar timestamp_old_bytes[7];
class Conv_param
{
uint16 m_table_def_flags;
public:
Conv_param(uint16 table_def_flags)
:m_table_def_flags(table_def_flags)
{ }
uint16 table_def_flags() const { return m_table_def_flags; }
};
class Conv_source: public Type_handler_hybrid_field_type
{
uint16 m_metadata;
CHARSET_INFO *m_cs;
public:
Conv_source(const Type_handler *h, uint16 metadata, CHARSET_INFO *cs)
:Type_handler_hybrid_field_type(h),
m_metadata(metadata),
m_cs(cs)
{
DBUG_ASSERT(cs);
}
uint16 metadata() const { return m_metadata; }
uint mbmaxlen() const { return m_cs->mbmaxlen; }
};
/*
Common declarations for Field and Item
*/
class Value_source
{
protected:
// Parameters for warning and note generation
class Warn_filter
{
bool m_want_warning_edom;
bool m_want_note_truncated_spaces;
public:
Warn_filter(bool want_warning_edom, bool want_note_truncated_spaces) :
m_want_warning_edom(want_warning_edom),
m_want_note_truncated_spaces(want_note_truncated_spaces)
{ }
Warn_filter(const THD *thd);
bool want_warning_edom() const
{ return m_want_warning_edom; }
bool want_note_truncated_spaces() const
{ return m_want_note_truncated_spaces; }
};
class Warn_filter_all: public Warn_filter
{
public:
Warn_filter_all() :Warn_filter(true, true) { }
};
class Converter_double_to_longlong
{
protected:
bool m_error;
longlong m_result;
public:
Converter_double_to_longlong(double nr, bool unsigned_flag);
longlong result() const { return m_result; }
bool error() const { return m_error; }
void push_warning(THD *thd, double nr, bool unsigned_flag);
};
class Converter_double_to_longlong_with_warn:
public Converter_double_to_longlong
{
public:
Converter_double_to_longlong_with_warn(THD *thd, double nr,
bool unsigned_flag)
:Converter_double_to_longlong(nr, unsigned_flag)
{
if (m_error)
push_warning(thd, nr, unsigned_flag);
}
Converter_double_to_longlong_with_warn(double nr, bool unsigned_flag)
:Converter_double_to_longlong(nr, unsigned_flag)
{
if (m_error)
push_warning(current_thd, nr, unsigned_flag);
}
};
// String-to-number converters
class Converter_string_to_number
{
protected:
char *m_end_of_num; // Where the low-level conversion routine stopped
int m_error; // The error code returned by the low-level routine
bool m_edom; // If EDOM-alike error happened during conversion
/**
Check string-to-number conversion and produce a warning if
- could not convert any digits (EDOM-alike error)
- found garbage at the end of the string
- found extra spaces at the end (a note)
See also Field_num::check_edom_and_truncation() for a similar function.
@param thd - the thread that will be used to generate warnings.
Can be NULL (which means current_thd will be used
if a warning is really necessary).
@param type - name of the data type
(e.g. "INTEGER", "DECIMAL", "DOUBLE")
@param cs - character set of the original string
@param str - the original string
@param end - the end of the string
@param allow_notes - tells if trailing space notes should be displayed
or suppressed.
Unlike Field_num::check_edom_and_truncation(), this function does not
distinguish between EDOM and truncation and reports the same warning for
both cases. Perhaps we should eventually print different warnings,
to make the explicit CAST work closer to the implicit cast in
Field_xxx::store().
*/
void check_edom_and_truncation(THD *thd, Warn_filter filter,
const char *type,
CHARSET_INFO *cs,
const char *str,
size_t length) const;
public:
int error() const { return m_error; }
};
class Converter_strntod: public Converter_string_to_number
{
double m_result;
public:
Converter_strntod(CHARSET_INFO *cs, const char *str, size_t length)
{
m_result= cs->strntod((char *) str, length, &m_end_of_num, &m_error);
// strntod() does not set an error if the input string was empty
m_edom= m_error !=0 || str == m_end_of_num;
}
double result() const { return m_result; }
};
class Converter_string_to_longlong: public Converter_string_to_number
{
protected:
longlong m_result;
public:
longlong result() const { return m_result; }
};
class Converter_strntoll: public Converter_string_to_longlong
{
public:
Converter_strntoll(CHARSET_INFO *cs, const char *str, size_t length)
{
m_result= cs->strntoll(str, length, 10, &m_end_of_num, &m_error);
/*
All non-zero errors means EDOM error.
strntoll() does not set an error if the input string was empty.
Check it here.
Notice the different with the same condition in Converter_strntoll10.
*/
m_edom= m_error != 0 || str == m_end_of_num;
}
};
class Converter_strtoll10: public Converter_string_to_longlong
{
public:
Converter_strtoll10(CHARSET_INFO *cs, const char *str, size_t length)
{
m_end_of_num= (char *) str + length;
m_result= cs->strtoll10(str, &m_end_of_num, &m_error);
/*
Negative error means "good negative number".
Only a positive m_error value means a real error.
strtoll10() sets error to MY_ERRNO_EDOM in case of an empty string,
so we don't have to additionally catch empty strings here.
*/
m_edom= m_error > 0;
}
};
class Converter_str2my_decimal: public Converter_string_to_number
{
public:
Converter_str2my_decimal(uint mask,
CHARSET_INFO *cs, const char *str, size_t length,
my_decimal *buf)
{
DBUG_ASSERT(length < UINT_MAX32);
m_error= str2my_decimal(mask, str, length, cs,
buf, (const char **) &m_end_of_num);
// E_DEC_TRUNCATED means a very minor truncation: '1e-100' -> 0
m_edom= m_error && m_error != E_DEC_TRUNCATED;
}
};
// String-to-number converters with automatic warning generation
class Converter_strntod_with_warn: public Converter_strntod
{
const char *m_data_type;
public:
Converter_strntod_with_warn(THD *thd, Warn_filter filter,
const char *data_type,
CHARSET_INFO *cs,
const char *str, size_t length)
:Converter_strntod(cs, str, length),
m_data_type(data_type)
{
check_edom_and_truncation(thd, filter, m_data_type, cs, str, length);
}
};
class Converter_strntoll_with_warn: public Converter_strntoll
{
public:
Converter_strntoll_with_warn(THD *thd, Warn_filter filter,
CHARSET_INFO *cs,
const char *str, size_t length)
:Converter_strntoll(cs, str, length)
{
check_edom_and_truncation(thd, filter, "INTEGER", cs, str, length);
}
};
class Converter_strtoll10_with_warn: public Converter_strtoll10
{
public:
Converter_strtoll10_with_warn(THD *thd, Warn_filter filter,
CHARSET_INFO *cs,
const char *str, size_t length)
:Converter_strtoll10(cs, str, length)
{
check_edom_and_truncation(thd, filter, "INTEGER", cs, str, length);
}
};
class Converter_str2my_decimal_with_warn: public Converter_str2my_decimal
{
public:
Converter_str2my_decimal_with_warn(THD *thd, Warn_filter filter,
uint mask, CHARSET_INFO *cs,
const char *str, size_t length,
my_decimal *buf)
:Converter_str2my_decimal(mask, cs, str, length, buf)
{
check_edom_and_truncation(thd, filter, "DECIMAL", cs, str, length);
}
};
// String-to-number conversion methods for the old code compatibility
longlong longlong_from_string_with_check(CHARSET_INFO *cs, const char *cptr,
const char *end) const
{
/*
TODO: Give error if we wanted a signed integer and we got an unsigned
one
Notice, longlong_from_string_with_check() honors thd->no_error, because
it's used to handle queries like this:
SELECT COUNT(@@basedir);
and is called when Item_func_get_system_var::update_null_value()
suppresses warnings and then calls val_int().
The other methods {double|decimal}_from_string_with_check() ignore
thd->no_errors, because they are not used for update_null_value()
and they always allow all kind of warnings.
*/
THD *thd= current_thd;
return Converter_strtoll10_with_warn(thd, Warn_filter(thd),
cs, cptr, end - cptr).result();
}
double double_from_string_with_check(CHARSET_INFO *cs, const char *cptr,
const char *end) const
{
return Converter_strntod_with_warn(NULL, Warn_filter_all(), "DOUBLE",
cs, cptr, end - cptr).result();
}
my_decimal *decimal_from_string_with_check(my_decimal *decimal_value,
CHARSET_INFO *cs,
const char *cptr,
const char *end)
{
Converter_str2my_decimal_with_warn(NULL, Warn_filter_all(),
E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
cs, cptr, end - cptr, decimal_value);
return decimal_value;
}
longlong longlong_from_hex_hybrid(const char *str, size_t length)
{
const char *end= str + length;
const char *ptr= end - MY_MIN(length, sizeof(longlong));
ulonglong value= 0;
for ( ; ptr != end ; ptr++)
value= (value << 8) + (ulonglong) (uchar) *ptr;
return (longlong) value;
}
longlong longlong_from_string_with_check(const String *str) const
{
return longlong_from_string_with_check(str->charset(),
str->ptr(), str->end());
}
double double_from_string_with_check(const String *str) const
{
return double_from_string_with_check(str->charset(),
str->ptr(), str->end());
}
my_decimal *decimal_from_string_with_check(my_decimal *decimal_value,
const String *str)
{
return decimal_from_string_with_check(decimal_value, str->charset(),
str->ptr(), str->end());
}
// End of String-to-number conversion methods
public:
/*
The enumeration Subst_constraint is currently used only in implementations
of the virtual function subst_argument_checker.
*/
enum Subst_constraint
{
ANY_SUBST, /* Any substitution for a field is allowed */
IDENTITY_SUBST /* Substitution for a field is allowed if any two
different values of the field type are not equal */
};
/*
Item context attributes.
Comparison functions pass their attributes to propagate_equal_fields().
For example, for string comparison, the collation of the comparison
operation is important inside propagate_equal_fields().
*/
class Context
{
/*
Which type of propagation is allowed:
- ANY_SUBST (loose equality, according to the collation), or
- IDENTITY_SUBST (strict binary equality).
*/
Subst_constraint m_subst_constraint;
/*
Comparison type.
Important only when ANY_SUBSTS.
*/
const Type_handler *m_compare_handler;
/*
Collation of the comparison operation.
Important only when ANY_SUBST.
*/
CHARSET_INFO *m_compare_collation;
public:
Context(Subst_constraint subst, const Type_handler *h, CHARSET_INFO *cs)
:m_subst_constraint(subst),
m_compare_handler(h),
m_compare_collation(cs)
{ DBUG_ASSERT(h == h->type_handler_for_comparison()); }
Subst_constraint subst_constraint() const { return m_subst_constraint; }
const Type_handler *compare_type_handler() const
{
DBUG_ASSERT(m_subst_constraint == ANY_SUBST);
return m_compare_handler;
}
CHARSET_INFO *compare_collation() const
{
DBUG_ASSERT(m_subst_constraint == ANY_SUBST);
return m_compare_collation;
}
};
class Context_identity: public Context
{ // Use this to request only exact value, no invariants.
public:
Context_identity()
:Context(IDENTITY_SUBST, &type_handler_long_blob, &my_charset_bin) { }
};
class Context_boolean: public Context
{ // Use this when an item is [a part of] a boolean expression
public:
Context_boolean()
:Context(ANY_SUBST, &type_handler_slonglong, &my_charset_bin) { }
};
};
#define STORAGE_TYPE_MASK 7
#define COLUMN_FORMAT_MASK 7
#define COLUMN_FORMAT_SHIFT 3
/* The length of the header part for each virtual column in the .frm file */
#define FRM_VCOL_OLD_HEADER_SIZE(b) (3 + MY_TEST(b))
#define FRM_VCOL_NEW_BASE_SIZE 16
#define FRM_VCOL_NEW_HEADER_SIZE 6
class Count_distinct_field;
struct ha_field_option_struct;
struct st_cache_field;
int field_conv(Field *to,Field *from);
int truncate_double(double *nr, uint field_length, decimal_digits_t dec,
bool unsigned_flag, double max_value);
inline uint get_enum_pack_length(int elements)
{
return elements < 256 ? 1 : 2;
}
inline uint get_set_pack_length(int elements)
{
uint len= (elements + 7) / 8;
return len > 4 ? 8 : len;
}
/**
Tests if field type is temporal and has date part,
i.e. represents DATE, DATETIME or TIMESTAMP types in SQL.
@param type Field type, as returned by field->type().
@retval true If field type is temporal type with date part.
@retval false If field type is not temporal type with date part.
*/
inline bool is_temporal_type_with_date(enum_field_types type)
{
switch (type)
{
case MYSQL_TYPE_DATE:
case MYSQL_TYPE_DATETIME:
case MYSQL_TYPE_TIMESTAMP:
return true;
case MYSQL_TYPE_DATETIME2:
case MYSQL_TYPE_TIMESTAMP2:
DBUG_ASSERT(0); // field->real_type() should not get to here.
return false;
default:
return false;
}
}
enum enum_vcol_info_type
{
VCOL_GENERATED_VIRTUAL, VCOL_GENERATED_STORED,
VCOL_DEFAULT, VCOL_CHECK_FIELD, VCOL_CHECK_TABLE,
VCOL_USING_HASH,
/* Additional types should be added here */
VCOL_GENERATED_VIRTUAL_INDEXED, // this is never written in .frm
/* Following is the highest value last */
VCOL_TYPE_NONE = 127 // Since the 0 value is already in use
};
static inline const char *vcol_type_name(enum_vcol_info_type type)
{
switch (type)
{
case VCOL_GENERATED_VIRTUAL:
case VCOL_GENERATED_VIRTUAL_INDEXED:
case VCOL_GENERATED_STORED:
return "GENERATED ALWAYS AS";
case VCOL_DEFAULT:
return "DEFAULT";
case VCOL_CHECK_FIELD:
case VCOL_CHECK_TABLE:
return "CHECK";
case VCOL_USING_HASH:
return "USING HASH";
case VCOL_TYPE_NONE:
return "UNTYPED";
}
return 0;
}
/*
Flags for Virtual_column_info. If none is set, the expression must be
a constant with no side-effects, so it's calculated at CREATE TABLE time,
stored in table->record[2], and not recalculated for every statement.
*/
#define VCOL_FIELD_REF 1
#define VCOL_NON_DETERMINISTIC 2
#define VCOL_SESSION_FUNC 4 /* uses session data, e.g. USER or DAYNAME */
#define VCOL_TIME_FUNC 8 /* safe for SBR */
#define VCOL_AUTO_INC 16
#define VCOL_IMPOSSIBLE 32
#define VCOL_NEXTVAL 64 /* NEXTVAL is not implemented for vcols */
#define VCOL_NOT_STRICTLY_DETERMINISTIC \
(VCOL_NON_DETERMINISTIC | VCOL_TIME_FUNC | VCOL_SESSION_FUNC)
/*
Virtual_column_info is the class to contain additional
characteristics that is specific for a virtual/computed
field such as:
- the defining expression that is evaluated to compute the value
of the field
- whether the field is to be stored in the database
- whether the field is used in a partitioning expression
*/
class Virtual_column_info: public Sql_alloc,
private Type_handler_hybrid_field_type
{
private:
enum_vcol_info_type vcol_type; /* Virtual column expression type */
/*
The following data is only updated by the parser and read
when a Create_field object is created/initialized.
*/
/* Flag indicating that the field used in a partitioning expression */
bool in_partitioning_expr;
public:
/* Flag indicating that the field is physically stored in the database */
bool utf8; /* Already in utf8 */
bool automatic_name;
bool if_not_exists;
Item *expr;
Lex_ident_column name; /* Name of constraint */
/* see VCOL_* (VCOL_FIELD_REF, ...) */
uint flags;
Virtual_column_info()
:Type_handler_hybrid_field_type(&type_handler_null),
vcol_type((enum_vcol_info_type)VCOL_TYPE_NONE),
in_partitioning_expr(FALSE),
utf8(TRUE), automatic_name(FALSE), expr(NULL), flags(0)
{
name.str= NULL;
name.length= 0;
};
Virtual_column_info* clone(THD *thd);
~Virtual_column_info() = default;
enum_vcol_info_type get_vcol_type() const
{
return vcol_type;
}
void set_vcol_type(enum_vcol_info_type v_type)
{
vcol_type= v_type;
}
const char *get_vcol_type_name() const
{
DBUG_ASSERT(vcol_type != VCOL_TYPE_NONE);
return vcol_type_name(vcol_type);
}
void set_handler(const Type_handler *handler)
{
/* Calling this function can only be done once. */
DBUG_ASSERT(type_handler() == &type_handler_null);
Type_handler_hybrid_field_type::set_handler(handler);
}
bool is_stored() const
{
/* after reading the row vcol value is already in the buffer */
return vcol_type == VCOL_GENERATED_STORED;
}
bool is_in_partitioning_expr() const
{
return in_partitioning_expr;
}
void mark_as_in_partitioning_expr()
{
in_partitioning_expr= TRUE;
}
bool need_refix() const
{
return flags & VCOL_SESSION_FUNC;
}
bool fix_expr(THD *thd);
bool fix_session_expr(THD *thd);
bool cleanup_session_expr();
bool fix_and_check_expr(THD *thd, TABLE *table);
inline bool is_equal(const Virtual_column_info* vcol) const;
/* Same as is_equal() but for comparing with different table */
bool is_equivalent(THD *thd, TABLE_SHARE *share, TABLE_SHARE *vcol_share,
const Virtual_column_info* vcol, bool &error) const;
inline void print(String*);
};
class Binlog_type_info
{
public:
enum binlog_sign_t
{
SIGN_SIGNED,
SIGN_UNSIGNED,
SIGN_NOT_APPLICABLE // for non-numeric types
};
/**
Retrieve the field metadata for fields.
*/
CHARSET_INFO *m_cs; // NULL if not relevant
const TYPELIB *m_enum_typelib; // NULL if not relevant
const TYPELIB *m_set_typelib; // NULL if not relevant
binlog_sign_t m_signedness;
uint16 m_metadata;
uint8 m_metadata_size;
uchar m_type_code; // according to Field::binlog_type()
uchar m_geom_type; // Non-geometry fields can return 0
Binlog_type_info(uchar type_code,
uint16 metadata,
uint8 metadata_size)
:m_cs(NULL),
m_enum_typelib(NULL),
m_set_typelib(NULL),
m_signedness(SIGN_NOT_APPLICABLE),
m_metadata(metadata),
m_metadata_size(metadata_size),
m_type_code(type_code),
m_geom_type(0)
{};
Binlog_type_info(uchar type_code, uint16 metadata,
uint8 metadata_size,
binlog_sign_t signedness)
: m_cs(NULL),
m_enum_typelib(NULL),
m_set_typelib(NULL),
m_signedness(signedness),
m_metadata(metadata),
m_metadata_size(metadata_size),
m_type_code(type_code),
m_geom_type(0)
{};
Binlog_type_info(uchar type_code, uint16 metadata,
uint8 metadata_size, CHARSET_INFO *cs)
:m_cs(cs),
m_enum_typelib(NULL),
m_set_typelib(NULL),
m_signedness(SIGN_NOT_APPLICABLE),
m_metadata(metadata),
m_metadata_size(metadata_size),
m_type_code(type_code),
m_geom_type(0)
{};
Binlog_type_info(uchar type_code, uint16 metadata,
uint8 metadata_size,
CHARSET_INFO *cs,
const TYPELIB *t_enum, const TYPELIB *t_set)
:m_cs(cs),
m_enum_typelib(t_enum),
m_set_typelib(t_set),
m_signedness(SIGN_NOT_APPLICABLE),
m_metadata(metadata),
m_metadata_size(metadata_size),
m_type_code(type_code),
m_geom_type(0)
{};
Binlog_type_info(uchar type_code, uint16 metadata,
uint8 metadata_size, CHARSET_INFO *cs,
uchar geom_type)
:m_cs(cs),
m_enum_typelib(NULL),
m_set_typelib(NULL),
m_signedness(SIGN_NOT_APPLICABLE),
m_metadata(metadata),
m_metadata_size(metadata_size),
m_type_code(type_code),
m_geom_type(geom_type)
{};
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
};
class Binlog_type_info_fixed_string: public Binlog_type_info
{
public:
Binlog_type_info_fixed_string(uchar type_code,
uint32 octet_length,
CHARSET_INFO *cs);
};
class Field: public Value_source
{
Field(const Item &); /* Prevent use of these */
void operator=(Field &);
protected:
int save_in_field_str(Field *to)
{
StringBuffer<MAX_FIELD_WIDTH> result(charset());
val_str(&result);
return to->store(result.ptr(), result.length(), charset());
}
void error_generated_column_function_is_not_allowed(THD *thd, bool error)
const;
static void do_field_eq(const Copy_field *copy);
static void do_field_int(const Copy_field *copy);
static void do_field_real(const Copy_field *copy);
static void do_field_string(const Copy_field *copy);
static void do_field_date(const Copy_field *copy);
static void do_field_temporal(const Copy_field *copy, date_mode_t fuzzydate);
static void do_field_datetime(const Copy_field *copy);
static void do_field_timestamp(const Copy_field *copy);
static void do_field_versioned_timestamp(const Copy_field *copy);
static void do_field_decimal(const Copy_field *copy);
public:
static void *operator new(size_t size, MEM_ROOT *mem_root) throw ()
{ return alloc_root(mem_root, size); }
static void *operator new(size_t size) throw ()
{
DBUG_ASSERT(size < UINT_MAX32);
return thd_alloc(current_thd, (uint) size);
}
static void operator delete(void *ptr_arg, size_t size) { TRASH_FREE(ptr_arg, size); }
static void operator delete(void *ptr, MEM_ROOT *mem_root)
{ DBUG_ASSERT(0); }
bool marked_for_read() const;
bool marked_for_write_or_computed() const;
/**
Used by System Versioning.
*/
virtual void set_max()
{ DBUG_ASSERT(0); }
virtual bool is_max()
{ DBUG_ASSERT(0); return false; }
uchar *ptr; // Position to field in record
/**
Byte where the @c NULL bit is stored inside a record. If this Field is a
@c NOT @c NULL field, this member is @c NULL.
*/
uchar *null_ptr;
/*
Note that you can use table->in_use as replacement for current_thd member
only inside of val_*() and store() members (e.g. you can't use it in cons)
*/
TABLE *table; // Pointer for table
TABLE *orig_table; // Pointer to original table
const char * const *table_name; // Pointer to alias in TABLE
Lex_ident_column field_name;
LEX_CSTRING comment;
/** reference to the list of options or NULL */
engine_option_value *option_list;
ha_field_option_struct *option_struct; /* structure with parsed options */
/* Field is part of the following keys */
key_map key_start, part_of_key, part_of_key_not_clustered;
/*
Bitmap of indexes that have records ordered by col1, ... this_field, ...
For example, INDEX (col(prefix_n)) is not present in col.part_of_sortkey.
*/
key_map part_of_sortkey;
/*
We use three additional unireg types for TIMESTAMP to overcome limitation
of current binary format of .frm file. We'd like to be able to support
NOW() as default and on update value for such fields but unable to hold
this info anywhere except unireg_check field. This issue will be resolved
in more clean way with transition to new text based .frm format.
See also comment for Field_timestamp::Field_timestamp().
*/
enum __attribute__((packed)) utype {
NONE=0,
NEXT_NUMBER=15, // AUTO_INCREMENT
TIMESTAMP_OLD_FIELD=18, // TIMESTAMP created before 4.1.3
TIMESTAMP_DN_FIELD=21, // TIMESTAMP DEFAULT NOW()
TIMESTAMP_UN_FIELD=22, // TIMESTAMP ON UPDATE NOW()
TIMESTAMP_DNUN_FIELD=23, // TIMESTAMP DEFAULT NOW() ON UPDATE NOW()
TMYSQL_COMPRESSED= 24, // Compatibility with TMySQL
};
enum imagetype { itRAW, itMBR};
static enum imagetype image_type(enum ha_key_alg alg)
{ return alg == HA_KEY_ALG_RTREE ? itMBR : itRAW; }
utype unireg_check;
field_visibility_t invisible;
uint32 field_length; // Length of field
uint32 flags;
field_index_t field_index; // field number in fields array
uchar null_bit; // Bit used to test null bit
/**
If true, this field was created in create_tmp_field_from_item from a NULL
value. This means that the type of the field is just a guess, and the type
may be freely coerced to another type.
@see create_tmp_field_from_item
@see Item_type_holder::get_real_type
*/
bool is_created_from_null_item;
/*
Selectivity of the range condition over this field.
When calculating this selectivity a range predicate
is taken into account only if:
- it is extracted from the WHERE clause
- it depends only on the table the field belongs to
*/
double cond_selectivity;
/*
The next field in the class of equal fields at the top AND level
of the WHERE clause
*/
Field *next_equal_field;
/*
This structure is used for statistical data on the column
that has been read from the statistical table column_stat
*/
Column_statistics *read_stats;
/*
This structure is used for statistical data on the column that
is collected by the function collect_statistics_for_table
*/
Column_statistics_collected *collected_stats;
/*
This is additional data provided for any computed(virtual) field,
default function or check constraint.
In particular it includes a pointer to the item by which this field
can be computed from other fields.
*/
Virtual_column_info *vcol_info, *check_constraint, *default_value;
Field(uchar *ptr_arg,uint32 length_arg,uchar *null_ptr_arg,
uchar null_bit_arg, utype unireg_check_arg,
const LEX_CSTRING *field_name_arg);
virtual ~Field() = default;
virtual Type_numeric_attributes type_numeric_attributes() const
{
return Type_numeric_attributes(field_length, decimals(), is_unsigned());
}
Type_std_attributes type_std_attributes() const
{
return Type_std_attributes(type_numeric_attributes(), dtcollation());
}
bool is_unsigned() const { return flags & UNSIGNED_FLAG; }
bool check_assignability_from(const Type_handler *from, bool ignore) const;
bool check_assignability_from(const Field *from, bool ignore) const
{
return check_assignability_from(from->type_handler(), ignore);
}
/**
Convenience definition of a copy function returned by
Field::get_copy_func()
*/
typedef void Copy_func(const Copy_field*);
virtual Copy_func *get_copy_func(const Field *from) const= 0;
virtual Copy_func *get_copy_func_to(const Field *to) const
{
return to->get_copy_func(this);
}
/* Store functions returns 1 on overflow and -1 on fatal error */
virtual int store_field(Field *from) { return from->save_in_field(this); }
virtual int save_in_field(Field *to)= 0;
/**
Check if it is possible just copy the value
of the field 'from' to the field 'this', e.g. for
INSERT INTO t1 (field1) SELECT field2 FROM t2;
@param from - The field to copy from
@retval true - it is possible to just copy value of 'from' to 'this'
@retval false - conversion is needed
*/
virtual bool memcpy_field_possible(const Field *from) const= 0;
virtual bool make_empty_rec_store_default_value(THD *thd, Item *item);
virtual void make_empty_rec_reset(THD *thd)
{
reset();
}
virtual int store(const char *to, size_t length,CHARSET_INFO *cs)=0;
/*
This is used by engines like CSV and Federated to signal the field
that the data is going to be in text (rather than binary) representation,
even if cs points to &my_charset_bin.
If a Field distinguishes between text and binary formats (e.g. INET6),
we cannot call store(str,length,&my_charset_bin),
to avoid "field" mis-interpreting the data format as binary.
*/
virtual int store_text(const char *to, size_t length, CHARSET_INFO *cs)
{
return store(to, length, cs);
}
virtual int store_binary(const char *to, size_t length)
{
return store(to, length, &my_charset_bin);
}
int store_binary(const uchar *to, size_t length)
{
return store_binary((const char*)(to), length);
}
virtual int store_hex_hybrid(const char *str, size_t length);
virtual int store(double nr)=0;
virtual int store(longlong nr, bool unsigned_val)=0;
virtual int store_decimal(const my_decimal *d)=0;
virtual int store_time_dec(const MYSQL_TIME *ltime, uint dec);
virtual int store_timestamp_dec(const my_timeval &ts, uint dec);
int store_timestamp(my_time_t timestamp, ulong sec_part)
{
struct my_timeval tmp;
tmp.tv_sec= (longlong) timestamp;
tmp.tv_usec= (long) sec_part;
return store_timestamp_dec(tmp, TIME_SECOND_PART_DIGITS);
}
/**
Store a value represented in native format
*/
virtual int store_native(const Native &value)
{
DBUG_ASSERT(0);
reset();
return 0;
}
int store_time(const MYSQL_TIME *ltime)