diff options
Diffstat (limited to 'sql/table.h')
-rw-r--r-- | sql/table.h | 218 |
1 files changed, 159 insertions, 59 deletions
diff --git a/sql/table.h b/sql/table.h index a42feba68c4..15ab3590b5d 100644 --- a/sql/table.h +++ b/sql/table.h @@ -25,6 +25,7 @@ #ifndef MYSQL_CLIENT +#include "my_cpu.h" /* LF_BACKOFF() */ #include "hash.h" /* HASH */ #include "handler.h" /* row_type, ha_choice, handler */ #include "mysql_com.h" /* enum_field_types */ @@ -55,6 +56,9 @@ class Virtual_column_info; class Table_triggers_list; class TMP_TABLE_PARAM; class SEQUENCE; +class Range_rowid_filter_cost_info; +class derived_handler; +class Pushdown_derived; struct Name_resolution_context; /* @@ -361,9 +365,18 @@ enum field_visibility_t { INVISIBLE_FULL }; -#define INVISIBLE_MAX_BITS 3 +#define INVISIBLE_MAX_BITS 3 +#define HA_HASH_FIELD_LENGTH 8 +#define HA_HASH_KEY_LENGTH_WITHOUT_NULL 8 +#define HA_HASH_KEY_LENGTH_WITH_NULL 9 +int fields_in_hash_keyinfo(KEY *keyinfo); + +void setup_keyinfo_hash(KEY *key_info); + +void re_setup_keyinfo_hash(KEY *key_info); + /** Category of table found in the table share. */ @@ -410,28 +423,6 @@ enum enum_table_category TABLE_CATEGORY_SYSTEM=3, /** - Information schema tables. - These tables are an interface provided by the system - to inspect the system metadata. - These tables do *not* honor: - - LOCK TABLE t FOR READ/WRITE - - FLUSH TABLES WITH READ LOCK - - SET GLOBAL READ_ONLY = ON - as there is no point in locking explicitly - an INFORMATION_SCHEMA table. - Nothing is directly written to information schema tables. - Note that this value is not used currently, - since information schema tables are not shared, - but implemented as session specific temporary tables. - */ - /* - TODO: Fixing the performance issues of I_S will lead - to I_S tables in the table cache, which should use - this table type. - */ - TABLE_CATEGORY_INFORMATION=4, - - /** Log tables. These tables are an interface provided by the system to inspect the system logs. @@ -451,7 +442,33 @@ enum enum_table_category The server implementation perform writes. Log tables are cached in the table cache. */ - TABLE_CATEGORY_LOG=5, + TABLE_CATEGORY_LOG=4, + + /* + Types below are read only tables, not affected by FLUSH TABLES or + MDL locks. + */ + /** + Information schema tables. + These tables are an interface provided by the system + to inspect the system metadata. + These tables do *not* honor: + - LOCK TABLE t FOR READ/WRITE + - FLUSH TABLES WITH READ LOCK + - SET GLOBAL READ_ONLY = ON + as there is no point in locking explicitly + an INFORMATION_SCHEMA table. + Nothing is directly written to information schema tables. + Note that this value is not used currently, + since information schema tables are not shared, + but implemented as session specific temporary tables. + */ + /* + TODO: Fixing the performance issues of I_S will lead + to I_S tables in the table cache, which should use + this table type. + */ + TABLE_CATEGORY_INFORMATION=5, /** Performance schema tables. @@ -475,6 +492,7 @@ enum enum_table_category */ TABLE_CATEGORY_PERFORMANCE=6 }; + typedef enum enum_table_category TABLE_CATEGORY; TABLE_CATEGORY get_table_category(const LEX_CSTRING *db, @@ -811,6 +829,7 @@ struct TABLE_SHARE bool null_field_first; bool system; /* Set if system table (one record) */ bool not_usable_by_query_cache; + bool online_backup; /* Set if on-line backup supported */ /* This is used by log tables, for tables that have their own internal binary logging or for tables that doesn't support statement or row logging @@ -825,6 +844,8 @@ struct TABLE_SHARE bool vcols_need_refixing; bool has_update_default_function; bool can_do_row_logging; /* 1 if table supports RBR */ + bool long_unique_table; + ulong table_map_id; /* for row-based replication */ /* @@ -854,20 +875,38 @@ struct TABLE_SHARE /** System versioning support. - */ + */ + struct period_info_t + { + uint16 start_fieldno; + uint16 end_fieldno; + Lex_ident name; + Lex_ident constr_name; + Field *start_field(TABLE_SHARE *s) const + { + return s->field[start_fieldno]; + } + Field *end_field(TABLE_SHARE *s) const + { + return s->field[end_fieldno]; + } + }; vers_sys_type_t versioned; - uint16 row_start_field; - uint16 row_end_field; + period_info_t vers; + period_info_t period; + + bool init_period_from_extra2(period_info_t *period, const uchar *data, + const uchar *end); Field *vers_start_field() { - return field[row_start_field]; + return field[vers.start_fieldno]; } Field *vers_end_field() { - return field[row_end_field]; + return field[vers.end_fieldno]; } /** @@ -1082,8 +1121,12 @@ struct TABLE_SHARE /* frees the memory allocated in read_frm_image */ void free_frm_image(const uchar *frm); + + void set_overlapped_keys(); }; +/* not NULL, but cannot be dereferenced */ +#define UNUSABLE_TABLE_SHARE ((TABLE_SHARE*)1) /** Class is used as a BLOB field value storage for @@ -1155,6 +1198,8 @@ typedef Bitmap<MAX_FIELDS> Field_map; class SplM_opt_info; +struct vers_select_conds_t; + struct TABLE { TABLE() {} /* Remove gcc warning */ @@ -1180,6 +1225,9 @@ public: THD *in_use; /* Which thread uses this */ uchar *record[3]; /* Pointer to records */ + /* record buf to resolve hash collisions for long UNIQUE constraints */ + uchar *check_unique_buf; + handler *update_handler; /* Handler used in case of update */ uchar *write_row_record; /* Used as optimisation in THD::write_row */ uchar *insert_values; /* used by INSERT ... UPDATE */ @@ -1205,6 +1253,8 @@ public: key_map keys_in_use_for_group_by; /* Map of keys that can be used to calculate ORDER BY without sorting */ key_map keys_in_use_for_order_by; + /* Map of keys dependent on some constraint */ + key_map constraint_dependent_keys; KEY *key_info; /* data of keys in database */ Field **field; /* Pointer to fields */ @@ -1236,8 +1286,6 @@ public: MY_BITMAP cond_set; /* used to mark fields from sargable conditions*/ /* Active column sets */ MY_BITMAP *read_set, *write_set, *rpl_write_set; - /* Set if using virtual fields */ - MY_BITMAP *vcol_set, *def_vcol_set; /* On INSERT: fields that the user specified a value for */ MY_BITMAP has_value_set; @@ -1275,7 +1323,14 @@ public: and max #key parts that range access would use. */ ha_rows quick_rows[MAX_KEY]; + uint quick_key_parts[MAX_KEY]; + double quick_costs[MAX_KEY]; + /* + If there is a range access by i-th index then the cost of + index only access for it is stored in quick_index_only_costs[i] + */ + double quick_index_only_costs[MAX_KEY]; /* Bitmaps of key parts that =const for the duration of join execution. If @@ -1284,8 +1339,7 @@ public: */ key_part_map const_key_parts[MAX_KEY]; - uint quick_key_parts[MAX_KEY]; - uint quick_n_ranges[MAX_KEY]; + uint quick_n_ranges[MAX_KEY]; /* Estimate of number of records that satisfy SARGable part of the table @@ -1467,7 +1521,9 @@ public: void mark_columns_needed_for_delete(void); void mark_columns_needed_for_insert(void); void mark_columns_per_binlog_row_image(void); - bool mark_virtual_col(Field *field); + inline bool mark_column_with_deps(Field *field); + inline bool mark_virtual_column_with_deps(Field *field); + inline void mark_virtual_column_deps(Field *field); bool mark_virtual_columns_for_write(bool insert_fl); bool check_virtual_columns_marked_for_read(); bool check_virtual_columns_marked_for_write(); @@ -1489,39 +1545,21 @@ public: if (file) file->column_bitmaps_signal(); } - inline void column_bitmaps_set(MY_BITMAP *read_set_arg, - MY_BITMAP *write_set_arg, - MY_BITMAP *vcol_set_arg) - { - read_set= read_set_arg; - write_set= write_set_arg; - vcol_set= vcol_set_arg; - if (file) - file->column_bitmaps_signal(); - } inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg, MY_BITMAP *write_set_arg) { read_set= read_set_arg; write_set= write_set_arg; } - inline void column_bitmaps_set_no_signal(MY_BITMAP *read_set_arg, - MY_BITMAP *write_set_arg, - MY_BITMAP *vcol_set_arg) - { - read_set= read_set_arg; - write_set= write_set_arg; - vcol_set= vcol_set_arg; - } inline void use_all_columns() { column_bitmaps_set(&s->all_set, &s->all_set); } + inline void use_all_stored_columns(); inline void default_column_bitmaps() { read_set= &def_read_set; write_set= &def_write_set; - vcol_set= def_vcol_set; /* Note that this may be 0 */ rpl_write_set= 0; } /** Should this instance of the table be reopened? */ @@ -1615,6 +1653,23 @@ public: double get_materialization_cost(); // Now used only if is_splittable()==true void add_splitting_info_for_key_field(struct KEY_FIELD *key_field); + key_map with_impossible_ranges; + + /* Number of cost info elements for possible range filters */ + uint range_rowid_filter_cost_info_elems; + /* Pointer to the array of cost info elements for range filters */ + Range_rowid_filter_cost_info *range_rowid_filter_cost_info; + /* The array of pointers to cost info elements for range filters */ + Range_rowid_filter_cost_info **range_rowid_filter_cost_info_ptr; + + void init_cost_info_for_usable_range_rowid_filters(THD *thd); + void prune_range_rowid_filters(); + void trace_range_rowid_filters(THD *thd) const; + Range_rowid_filter_cost_info * + best_range_rowid_filter_for_partial_join(uint access_key_no, + double records, + double access_cost_factor); + /** System Versioning support */ @@ -1649,23 +1704,30 @@ public: Field *vers_start_field() const { DBUG_ASSERT(s && s->versioned); - return field[s->row_start_field]; + return field[s->vers.start_fieldno]; } Field *vers_end_field() const { DBUG_ASSERT(s && s->versioned); - return field[s->row_end_field]; + return field[s->vers.end_fieldno]; } ulonglong vers_start_id() const; ulonglong vers_end_id() const; + int update_generated_fields(); + int period_make_insert(Item *src, Field *dst); + int insert_portion_of_time(THD *thd, const vers_select_conds_t &period_conds, + ha_rows *rows_inserted); bool vers_check_update(List<Item> &items); int delete_row(); void vers_update_fields(); void vers_update_end(); + void find_constraint_correlated_indexes(); + void clone_handler_for_update(); + void delete_update_handler(); /** Number of additional fields used in versioned tables */ #define VERSIONING_FIELDS 2 @@ -1862,6 +1924,13 @@ class IS_table_read_plan; /** The threshold size a blob field buffer before it is freed */ #define MAX_TDC_BLOB_SIZE 65536 +/** number of bytes used by field positional indexes in frm */ +constexpr uint frm_fieldno_size= 2; +static inline uint16 read_frm_fieldno(const uchar *data) +{ return uint2korr(data); } +static inline void store_frm_fieldno(const uchar *data, uint16 fieldno) +{ int2store(data, fieldno); } + class select_unit; class TMP_TABLE_PARAM; @@ -1973,6 +2042,12 @@ struct vers_select_conds_t bool delete_history:1; Vers_history_point start; Vers_history_point end; + Lex_ident name; + + Item_field *field_start; + Item_field *field_end; + + const TABLE_SHARE::period_info_t *period; void empty() { @@ -1986,7 +2061,8 @@ struct vers_select_conds_t void init(vers_system_time_t _type, Vers_history_point _start= Vers_history_point(), - Vers_history_point _end= Vers_history_point()) + Vers_history_point _end= Vers_history_point(), + Lex_ident _name= "SYSTEM_TIME") { type= _type; orig_type= _type; @@ -1995,6 +2071,13 @@ struct vers_select_conds_t type == SYSTEM_TIME_BEFORE); start= _start; end= _end; + name= _name; + } + + void set_all() + { + type= SYSTEM_TIME_ALL; + name= "SYSTEM_TIME"; } void print(String *str, enum_query_type query_type) const; @@ -2102,6 +2185,7 @@ struct TABLE_LIST init_one_table(&table_arg->s->db, &table_arg->s->table_name, NULL, lock_type); table= table_arg; + vers_conditions.name= table->s->vers.name; } inline void init_one_table_for_prelocking(const LEX_CSTRING *db_arg, @@ -2282,6 +2366,15 @@ struct TABLE_LIST TABLE_LIST * next_with_rec_ref; bool is_derived_with_recursive_reference; bool block_handle_derived; + /* The interface employed to materialize the table by a foreign engine */ + derived_handler *dt_handler; + /* The text of the query specifying the derived table */ + LEX_CSTRING derived_spec; + /* + The object used to organize execution of the query that specifies + the derived table by a foreign engine + */ + Pushdown_derived *pushdown_derived; ST_SCHEMA_TABLE *schema_table; /* Information_schema table */ st_select_lex *schema_select_lex; /* @@ -2542,6 +2635,12 @@ struct TABLE_LIST /* System Versioning */ vers_select_conds_t vers_conditions; + vers_select_conds_t period_conditions; + + bool has_period() const + { + return period_conditions.is_set(); + } my_bool for_insert_data; @@ -2746,8 +2845,9 @@ struct TABLE_LIST return false; } void set_lock_type(THD* thd, enum thr_lock_type lock); - void check_pushable_cond_for_table(Item *cond); - Item *build_pushable_cond_for_table(THD *thd, Item *cond); + + derived_handler *find_derived_handler(THD *thd); + TABLE_LIST *get_first_table(); void remove_join_columns() { @@ -3125,7 +3225,7 @@ extern LEX_CSTRING INFORMATION_SCHEMA_NAME; extern LEX_CSTRING MYSQL_SCHEMA_NAME; /* table names */ -extern LEX_CSTRING MYSQL_USER_NAME, MYSQL_DB_NAME, MYSQL_PROC_NAME; +extern LEX_CSTRING MYSQL_PROC_NAME; inline bool is_infoschema_db(const LEX_CSTRING *name) { |