@@ -747,6 +747,105 @@ static uint column_preamble_bits(const dd::Column *col_obj) {
747
747
return result;
748
748
}
749
749
750
+ static Field *make_field (const dd::Column &col_obj, TABLE_SHARE *share,
751
+ uchar *ptr, uchar *null_pos, size_t null_bit) {
752
+ auto field_type = dd_get_old_field_type (col_obj.type ());
753
+ auto field_length = col_obj.char_length ();
754
+ auto charset = get_charset (static_cast <uint >(col_obj.collation_id ()), MYF (0 ));
755
+
756
+ auto column_options = const_cast <dd::Properties *>(&col_obj.options ());
757
+
758
+ // Reconstruct auto_flags
759
+ auto auto_flags = static_cast <uint >(Field::NONE);
760
+
761
+ /*
762
+ The only value for DEFAULT and ON UPDATE options which we support
763
+ at this point is CURRENT_TIMESTAMP.
764
+ */
765
+ if (!col_obj.default_option ().empty ()) auto_flags |= Field::DEFAULT_NOW;
766
+ if (!col_obj.update_option ().empty ()) auto_flags |= Field::ON_UPDATE_NOW;
767
+
768
+ if (col_obj.is_auto_increment ()) auto_flags |= Field::NEXT_NUMBER;
769
+
770
+ /*
771
+ Columns can't have AUTO_INCREMENT and DEFAULT/ON UPDATE CURRENT_TIMESTAMP at
772
+ the same time.
773
+ */
774
+ DBUG_ASSERT (
775
+ !((auto_flags & (Field::DEFAULT_NOW | Field::ON_UPDATE_NOW)) != 0 &&
776
+ (auto_flags & Field::NEXT_NUMBER) != 0 ));
777
+
778
+ // Read Interval TYPELIB
779
+ TYPELIB *interval = nullptr ;
780
+
781
+ if (field_type == MYSQL_TYPE_ENUM || field_type == MYSQL_TYPE_SET) {
782
+ //
783
+ // Allocate space for interval (column elements)
784
+ //
785
+ size_t interval_parts = col_obj.elements_count ();
786
+
787
+ interval = (TYPELIB *)alloc_root (&share->mem_root , sizeof (TYPELIB));
788
+ interval->type_names = (const char **)alloc_root (
789
+ &share->mem_root , sizeof (char *) * (interval_parts + 1 ));
790
+ interval->type_names [interval_parts] = 0 ;
791
+
792
+ interval->type_lengths =
793
+ (uint *)alloc_root (&share->mem_root , sizeof (uint ) * interval_parts);
794
+ interval->count = interval_parts;
795
+ interval->name = NULL ;
796
+
797
+ //
798
+ // Iterate through all the column elements
799
+ //
800
+ for (const dd::Column_type_element *ce : col_obj.elements ()) {
801
+ // Read the enum/set element name
802
+ dd::String_type element_name = ce->name ();
803
+
804
+ uint pos = ce->index () - 1 ;
805
+ interval->type_lengths [pos] = static_cast <uint >(element_name.length ());
806
+ interval->type_names [pos] = strmake_root (
807
+ &share->mem_root , element_name.c_str (), element_name.length ());
808
+ }
809
+ }
810
+
811
+ // Column name
812
+ char *name = nullptr ;
813
+ dd::String_type s = col_obj.name ();
814
+ DBUG_ASSERT (!s.empty ());
815
+ name = strmake_root (&share->mem_root , s.c_str (), s.length ());
816
+ name[s.length ()] = ' \0 ' ;
817
+
818
+ uint decimals;
819
+ // Decimals
820
+ if (field_type == MYSQL_TYPE_DECIMAL || field_type == MYSQL_TYPE_NEWDECIMAL) {
821
+ DBUG_ASSERT (col_obj.is_numeric_scale_null () == false );
822
+ decimals = col_obj.numeric_scale ();
823
+ } else if (field_type == MYSQL_TYPE_FLOAT ||
824
+ field_type == MYSQL_TYPE_DOUBLE) {
825
+ decimals = col_obj.is_numeric_scale_null () ? NOT_FIXED_DEC
826
+ : col_obj.numeric_scale ();
827
+ } else
828
+ decimals = 0 ;
829
+
830
+ auto geom_type = Field::GEOM_GEOMETRY;
831
+ // Read geometry sub type
832
+ if (field_type == MYSQL_TYPE_GEOMETRY) {
833
+ uint32 sub_type;
834
+ column_options->get_uint32 (" geom_type" , &sub_type);
835
+ geom_type = static_cast <Field::geometry_type>(sub_type);
836
+ }
837
+
838
+ bool treat_bit_as_char = false ;
839
+ if (field_type == MYSQL_TYPE_BIT)
840
+ column_options->get_bool (" treat_bit_as_char" , &treat_bit_as_char);
841
+
842
+ return make_field (share, ptr, field_length, null_pos, null_bit, field_type,
843
+ charset, geom_type, auto_flags, interval, name,
844
+ col_obj.is_nullable (), col_obj.is_zerofill (),
845
+ col_obj.is_unsigned (), decimals, treat_bit_as_char, 0 ,
846
+ col_obj.srs_id ());
847
+ }
848
+
750
849
/* *
751
850
Add Field constructed according to column metadata from dd::Column
752
851
object to TABLE_SHARE.
@@ -758,12 +857,9 @@ static bool fill_column_from_dd(THD *thd, TABLE_SHARE *share,
758
857
uint field_nr) {
759
858
char *name = NULL ;
760
859
uchar auto_flags;
761
- size_t field_length;
762
860
enum_field_types field_type;
763
861
const CHARSET_INFO *charset = NULL ;
764
- Field::geometry_type geom_type = Field::GEOM_GEOMETRY;
765
862
Field *reg_field;
766
- uint decimals;
767
863
ha_storage_media field_storage;
768
864
column_format_type field_column_format;
769
865
@@ -783,9 +879,6 @@ static bool fill_column_from_dd(THD *thd, TABLE_SHARE *share,
783
879
// Type
784
880
field_type = dd_get_old_field_type (col_obj->type ());
785
881
786
- // Char length
787
- field_length = col_obj->char_length ();
788
-
789
882
// Reconstruct auto_flags
790
883
auto_flags = Field::NONE;
791
884
@@ -820,21 +913,13 @@ static bool fill_column_from_dd(THD *thd, TABLE_SHARE *share,
820
913
}
821
914
822
915
// Decimals
823
- if (field_type == MYSQL_TYPE_DECIMAL || field_type == MYSQL_TYPE_NEWDECIMAL) {
916
+ if (field_type == MYSQL_TYPE_DECIMAL || field_type == MYSQL_TYPE_NEWDECIMAL)
824
917
DBUG_ASSERT (col_obj->is_numeric_scale_null () == false );
825
- decimals = col_obj->numeric_scale ();
826
- } else if (field_type == MYSQL_TYPE_FLOAT ||
827
- field_type == MYSQL_TYPE_DOUBLE) {
828
- decimals = col_obj->is_numeric_scale_null () ? NOT_FIXED_DEC
829
- : col_obj->numeric_scale ();
830
- } else
831
- decimals = 0 ;
832
918
833
919
// Read geometry sub type
834
920
if (field_type == MYSQL_TYPE_GEOMETRY) {
835
921
uint32 sub_type;
836
922
column_options->get_uint32 (" geom_type" , &sub_type);
837
- geom_type = (Field::geometry_type)sub_type;
838
923
}
839
924
840
925
// Read values of storage media and column format options
@@ -910,11 +995,8 @@ static bool fill_column_from_dd(THD *thd, TABLE_SHARE *share,
910
995
//
911
996
// Create FIELD
912
997
//
913
- reg_field = make_field (share, rec_pos, (uint32)field_length, null_pos,
914
- null_bit_pos, field_type, charset, geom_type,
915
- auto_flags, interval, name, col_obj->is_nullable (),
916
- col_obj->is_zerofill (), col_obj->is_unsigned (),
917
- decimals, treat_bit_as_char, 0 , col_obj->srs_id ());
998
+
999
+ reg_field = make_field (*col_obj, share, rec_pos, null_pos, null_bit_pos);
918
1000
919
1001
reg_field->field_index = field_nr;
920
1002
reg_field->gcol_info = gcol_info;
0 commit comments