diff --git a/sql/field.h b/sql/field.h index 555ecf16ce4..499bf5e3c1f 100644 --- a/sql/field.h +++ b/sql/field.h @@ -828,10 +828,10 @@ public: utype unireg_check; field_visibility_t invisible; - uint32 field_length; // Length of field - uint32 flags; - uint16 field_index; // field number in fields array - uchar null_bit; // Bit used to test null bit + 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 diff --git a/sql/item.h b/sql/item.h index bb34ea316ea..273013c0a74 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3277,7 +3277,7 @@ public: } }; -#define NO_CACHED_FIELD_INDEX ((uint16) ~0) +#define NO_CACHED_FIELD_INDEX ((field_index_t) ~0U) class st_select_lex; @@ -3354,7 +3354,7 @@ public: stmts for speeding up their re-execution. Holds NO_CACHED_FIELD_INDEX if index value is not known. */ - uint16 cached_field_index; + field_index_t cached_field_index; /* Some Items resolved in another select should not be marked as dependency of the subquery where they are. During normal name resolution, we check @@ -6752,7 +6752,7 @@ public: enum __attribute__((packed)) row_version_type {OLD_ROW, NEW_ROW}; row_version_type row_version; /* Index of the field in the TABLE::field array */ - uint16 field_idx; + field_index_t field_idx; private: /* diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 0ecba16730b..b5a671b3f37 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -11670,8 +11670,8 @@ static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts) for (KEY_PART_INFO *kp= table_key->key_part; kp < key_part; kp++) { - uint16 fieldnr= param->table->key_info[keynr]. - key_part[kp - table_key->key_part].fieldnr - 1; + field_index_t fieldnr= (param->table->key_info[keynr]. + key_part[kp - table_key->key_part].fieldnr - 1); if (param->table->field[fieldnr]->key_length() != kp->length) return FALSE; } diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 8c9f2de9192..82ee92c27ba 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -6982,7 +6982,7 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, while ((column = column_iter++)) { - uint16 unused_field_idx= NO_CACHED_FIELD_INDEX; + field_index_t unused_field_idx= NO_CACHED_FIELD_INDEX; TABLE_LIST *dummy; Field *f=find_field_in_table_ref(thd, table_list, column->column.ptr(), column->column.length(), diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 0417244a01c..d9b305e7d74 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -6014,10 +6014,10 @@ find_field_in_natural_join(THD *thd, TABLE_LIST *table_ref, const char *name, si Field * find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length, - bool allow_rowid, uint16 *cached_field_index_ptr) + bool allow_rowid, field_index_t *cached_field_index_ptr) { Field *field; - uint16 cached_field_index= *cached_field_index_ptr; + field_index_t cached_field_index= *cached_field_index_ptr; DBUG_ENTER("find_field_in_table"); DBUG_PRINT("enter", ("table: '%s', field name: '%s'", table->alias.c_ptr(), name)); @@ -6113,7 +6113,7 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, ignored_tables_list_t ignored_tables, Item **ref, bool check_privileges, bool allow_rowid, - uint16 *cached_field_index_ptr, + field_index_t *cached_field_index_ptr, bool register_tree_change, TABLE_LIST **actual_table) { Field *fld; diff --git a/sql/sql_base.h b/sql/sql_base.h index 7a56d95bf2a..cafb5967480 100644 --- a/sql/sql_base.h +++ b/sql/sql_base.h @@ -205,11 +205,11 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list, const char *table_name, ignored_tables_list_t ignored_tables, Item **ref, bool check_privileges, bool allow_rowid, - uint16 *cached_field_index_ptr, + field_index_t *cached_field_index_ptr, bool register_tree_change, TABLE_LIST **actual_table); Field * find_field_in_table(THD *thd, TABLE *table, const char *name, size_t length, - bool allow_rowid, uint16 *cached_field_index_ptr); + bool allow_rowid, field_index_t *cached_field_index_ptr); Field * find_field_in_table_sef(TABLE *table, const char *name); Item ** find_item_in_list(Item *item, List &items, uint *counter, diff --git a/sql/structs.h b/sql/structs.h index d7568e02e29..fa0da6e0dbb 100644 --- a/sql/structs.h +++ b/sql/structs.h @@ -36,6 +36,9 @@ class Index_statistics; class THD; +/* Array index type for table.field[] */ +typedef uint16 field_index_t; + typedef struct st_date_time_format { uchar positions[8]; char time_separator; /* Separator between hour and minute */ @@ -82,10 +85,10 @@ typedef struct st_key_part_info { /* Info about a key part */ */ uint16 store_length; uint16 key_type; - uint16 fieldnr; /* Fieldnr begins counting from 1 */ + field_index_t fieldnr; /* Fieldnr begins counting from 1 */ uint16 key_part_flag; /* 0 or HA_REVERSE_SORT */ uint8 type; - uint8 null_bit; /* Position to null_bit */ + uint8 null_bit; /* Position to null_bit */ } KEY_PART_INFO ; class engine_option_value; diff --git a/sql/table.cc b/sql/table.cc index f62b7496ce7..125e4f81a1b 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -115,7 +115,8 @@ static bool fix_type_pointers(const char ***typelib_value_names, TYPELIB *point_to_type, uint types, char *names, size_t names_length); -static uint find_field(Field **fields, uchar *record, uint start, uint length); +static field_index_t find_field(Field **fields, uchar *record, uint start, + uint length); inline bool is_system_table_name(const char *name, size_t length); @@ -3002,10 +3003,10 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, { Field *field; if (new_field_pack_flag <= 1) - key_part->fieldnr= (uint16) find_field(share->field, - share->default_values, - (uint) key_part->offset, - (uint) key_part->length); + key_part->fieldnr= find_field(share->field, + share->default_values, + (uint) key_part->offset, + (uint) key_part->length); if (!key_part->fieldnr) goto err; @@ -4631,10 +4632,11 @@ fix_type_pointers(const char ***typelib_value_names, # field number +1 */ -static uint find_field(Field **fields, uchar *record, uint start, uint length) +static field_index_t find_field(Field **fields, uchar *record, uint start, + uint length) { Field **field; - uint i, pos; + field_index_t i, pos; pos= 0; for (field= fields, i=1 ; *field ; i++,field++) diff --git a/sql/table.h b/sql/table.h index 9c87f9809ff..1b8919f4e59 100644 --- a/sql/table.h +++ b/sql/table.h @@ -892,8 +892,8 @@ struct TABLE_SHARE */ struct period_info_t { - uint16 start_fieldno; - uint16 end_fieldno; + field_index_t start_fieldno; + field_index_t end_fieldno; Lex_ident name; Lex_ident constr_name; uint unique_keys; @@ -1909,14 +1909,14 @@ class IS_table_read_plan; constexpr uint frm_fieldno_size= 2; /** number of bytes used by key position number in frm */ constexpr uint frm_keyno_size= 2; -static inline uint16 read_frm_fieldno(const uchar *data) +static inline field_index_t read_frm_fieldno(const uchar *data) { return uint2korr(data); } -static inline void store_frm_fieldno(uchar *data, uint16 fieldno) +static inline void store_frm_fieldno(uchar *data, field_index_t fieldno) { int2store(data, fieldno); } static inline uint16 read_frm_keyno(const uchar *data) { return uint2korr(data); } -static inline void store_frm_keyno(uchar *data, uint16 fieldno) -{ int2store(data, fieldno); } +static inline void store_frm_keyno(uchar *data, uint16 keyno) +{ int2store(data, keyno); } static inline size_t extra2_str_size(size_t len) { return (len > 255 ? 3 : 1) + len; } diff --git a/sql/unireg.cc b/sql/unireg.cc index 51dd1fb6e8c..2726b9a68c2 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -133,8 +133,9 @@ static uchar *extra2_write_index_properties(uchar *pos, const KEY *keyinfo, return pos; } -static uint16 -get_fieldno_by_name(HA_CREATE_INFO *create_info, List &create_fields, +static field_index_t +get_fieldno_by_name(HA_CREATE_INFO *create_info, + List &create_fields, const Lex_ident &field_name) { List_iterator it(create_fields); @@ -142,17 +143,17 @@ get_fieldno_by_name(HA_CREATE_INFO *create_info, List &create_fiel DBUG_ASSERT(field_name); - for (unsigned field_no = 0; (sql_field = it++); ++field_no) + for (field_index_t field_no= 0; (sql_field = it++); ++field_no) { if (field_name.streq(sql_field->field_name)) { - DBUG_ASSERT(field_no <= uint16(~0U)); - return uint16(field_no); + DBUG_ASSERT(field_no < NO_CACHED_FIELD_INDEX); + return field_no; } } DBUG_ASSERT(0); /* Not Reachable */ - return 0; + return NO_CACHED_FIELD_INDEX; } static inline