diff options
Diffstat (limited to 'sql/table.h')
-rw-r--r-- | sql/table.h | 787 |
1 files changed, 716 insertions, 71 deletions
diff --git a/sql/table.h b/sql/table.h index cff4be630e4..da0e089794f 100644 --- a/sql/table.h +++ b/sql/table.h @@ -21,9 +21,33 @@ class Item_subselect; class GRANT_TABLE; class st_select_lex_unit; class st_select_lex; +class partition_info; class COND_EQUAL; class Security_context; +/*************************************************************************/ + +/** + View_creation_ctx -- creation context of view objects. +*/ + +class View_creation_ctx : public Default_object_creation_ctx, + public Sql_alloc +{ +public: + static View_creation_ctx *create(THD *thd); + + static View_creation_ctx *create(THD *thd, + TABLE_LIST *view); + +private: + View_creation_ctx(THD *thd) + : Default_object_creation_ctx(thd) + { } +}; + +/*************************************************************************/ + /* Order clause list element */ typedef struct st_order { @@ -55,10 +79,11 @@ typedef struct st_grant_info ulong orig_want_privilege; } GRANT_INFO; -enum tmp_table_type {NO_TMP_TABLE=0, - NON_TRANSACTIONAL_TMP_TABLE=1, TRANSACTIONAL_TMP_TABLE=2, - SYSTEM_TMP_TABLE=3}; - +enum tmp_table_type +{ + NO_TMP_TABLE, NON_TRANSACTIONAL_TMP_TABLE, TRANSACTIONAL_TMP_TABLE, + INTERNAL_TMP_TABLE, SYSTEM_TMP_TABLE +}; /** Event on which trigger is invoked. */ enum trg_event_type @@ -69,7 +94,6 @@ enum trg_event_type TRG_EVENT_MAX }; - enum frm_type_enum { FRMTYPE_ERROR= 0, @@ -77,18 +101,20 @@ enum frm_type_enum FRMTYPE_VIEW }; +enum release_type { RELEASE_NORMAL, RELEASE_WAIT_FOR_DROP }; + typedef struct st_filesort_info { - IO_CACHE *io_cache; /* If sorted through filebyte */ - uchar **sort_keys; /* Buffer for sorting keys */ - byte *buffpek; /* Buffer for buffpek structures */ - uint buffpek_len; /* Max number of buffpeks in the buffer */ - byte *addon_buf; /* Pointer to a buffer if sorted with fields */ - uint addon_length; /* Length of the buffer */ + IO_CACHE *io_cache; /* If sorted through filesort */ + uchar **sort_keys; /* Buffer for sorting keys */ + uchar *buffpek; /* Buffer for buffpek structures */ + uint buffpek_len; /* Max number of buffpeks in the buffer */ + uchar *addon_buf; /* Pointer to a buffer if sorted with fields */ + size_t addon_length; /* Length of the buffer */ struct st_sort_addon_field *addon_field; /* Pointer to the fields info */ - void (*unpack)(struct st_sort_addon_field *, byte *); /* To unpack back */ - byte *record_pointers; /* If sorted in memory */ - ha_rows found_records; /* How many records in sort */ + void (*unpack)(struct st_sort_addon_field *, uchar *); /* To unpack back */ + uchar *record_pointers; /* If sorted in memory */ + ha_rows found_records; /* How many records in sort */ } FILESORT_INFO; @@ -114,6 +140,100 @@ class Field_timestamp; class Field_blob; class Table_triggers_list; +/** + Category of table found in the table share. +*/ +enum enum_table_category +{ + /** + Unknown value. + */ + TABLE_UNKNOWN_CATEGORY=0, + + /** + Temporary table. + The table is visible only in the session. + Therefore, + - FLUSH TABLES WITH READ LOCK + - SET GLOBAL READ_ONLY = ON + do not apply to this table. + Note that LOCK TABLE t FOR READ/WRITE + can be used on temporary tables. + Temporary tables are not part of the table cache. + */ + TABLE_CATEGORY_TEMPORARY=1, + + /** + User table. + These tables do honor: + - LOCK TABLE t FOR READ/WRITE + - FLUSH TABLES WITH READ LOCK + - SET GLOBAL READ_ONLY = ON + User tables are cached in the table cache. + */ + TABLE_CATEGORY_USER=2, + + /** + System table, maintained by the server. + These tables do honor: + - LOCK TABLE t FOR READ/WRITE + - FLUSH TABLES WITH READ LOCK + - SET GLOBAL READ_ONLY = ON + Typically, writes to system tables are performed by + the server implementation, not explicitly be a user. + System tables are cached in the table cache. + */ + 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 explicitely + 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, + + /** + Performance schema tables. + These tables are an interface provided by the system + to inspect the system performance data. + 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 explicitely + a PERFORMANCE_SCHEMA table. + An example of PERFORMANCE_SCHEMA tables are: + - mysql.slow_log + - mysql.general_log, + which *are* updated even when there is either + a GLOBAL READ LOCK or a GLOBAL READ_ONLY in effect. + User queries do not write directly to these tables + (there are exceptions for log tables). + The server implementation perform writes. + Performance tables are cached in the table cache. + */ + TABLE_CATEGORY_PERFORMANCE=5 +}; +typedef enum enum_table_category TABLE_CATEGORY; + +TABLE_CATEGORY get_table_category(const LEX_STRING *db, + const LEX_STRING *name); + /* This structure is shared between different table objects. There is one instance of table share per one table in the database. @@ -121,32 +241,52 @@ class Table_triggers_list; typedef struct st_table_share { + st_table_share() {} /* Remove gcc warning */ + + /** Category of this table. */ + TABLE_CATEGORY table_category; + /* hash of field names (contains pointers to elements of field array) */ HASH name_hash; /* hash of field names */ MEM_ROOT mem_root; TYPELIB keynames; /* Pointers to keynames */ TYPELIB fieldnames; /* Pointer to fieldnames */ TYPELIB *intervals; /* pointer to interval info */ -#ifdef NOT_YET pthread_mutex_t mutex; /* For locking the share */ pthread_cond_t cond; /* To signal that share is ready */ + struct st_table_share *next, /* Link to unused shares */ + **prev; +#ifdef NOT_YET struct st_table *open_tables; /* link to open tables */ - struct st_table *used_next, /* Link to used tables */ - **used_prev; +#endif + /* The following is copied to each TABLE on OPEN */ Field **field; + Field **found_next_number_field; + Field *timestamp_field; /* Used only during open */ KEY *key_info; /* data of keys in database */ -#endif uint *blob_field; /* Index to blobs in Field arrray*/ - byte *default_values; /* row with default values */ + + uchar *default_values; /* row with default values */ LEX_STRING comment; /* Comment about table */ CHARSET_INFO *table_charset; /* Default charset of string fields */ - /* A pair "database_name\0table_name\0", widely used as simply a db name */ - char *table_cache_key; - const char *db; /* Pointer to db */ - const char *table_name; /* Table name (for open) */ - const char *path; /* Path to .frm file (from datadir) */ + MY_BITMAP all_set; + /* + Key which is used for looking-up table in table cache and in the list + of thread's temporary tables. Has the form of: + "database_name\0table_name\0" + optional part for temporary tables. + + Note that all three 'table_cache_key', 'db' and 'table_name' members + must be set (and be non-zero) for tables in table cache. They also + should correspond to each other. + To ensure this one can use set_table_cache() methods. + */ + LEX_STRING table_cache_key; + LEX_STRING db; /* Pointer to db */ + LEX_STRING table_name; /* Table name (for open) */ + LEX_STRING path; /* Path to .frm file (from datadir) */ + LEX_STRING normalized_path; /* unpack_filename(path) */ LEX_STRING connect_string; /* @@ -155,20 +295,29 @@ typedef struct st_table_share */ key_map keys_in_use; key_map keys_for_keyread; + ha_rows min_rows, max_rows; /* create information */ ulong avg_row_length; /* create information */ ulong raid_chunksize; - ulong version, flush_version, mysql_version; + ulong version, mysql_version; ulong timestamp_offset; /* Set to offset+1 of record */ ulong reclength; /* Recordlength */ - ha_rows min_rows, max_rows; /* create information */ - enum db_type db_type; /* table_type for handler */ + plugin_ref db_plugin; /* storage engine plugin */ + inline handlerton *db_type() const /* table_type for handler */ + { + // DBUG_ASSERT(db_plugin); + return db_plugin ? plugin_data(db_plugin, handlerton*) : NULL; + } enum row_type row_type; /* How rows are stored */ enum tmp_table_type tmp_table; + enum ha_choice transactional; + enum ha_choice page_checksum; + uint ref_count; /* How many TABLE objects uses this */ + uint open_count; /* Number of tables in open list */ uint blob_ptr_size; /* 4 or 8 */ + uint key_block_size; /* create key_block_size, if used */ uint null_bytes, last_null_bit_pos; - uint key_length; /* Length of table_cache_key */ uint fields; /* Number of fields */ uint rec_buff_length; /* Size of table->record[] buffer */ uint keys, key_parts; @@ -176,37 +325,230 @@ typedef struct st_table_share uint uniques; /* Number of UNIQUE index */ uint null_fields; /* number of null fields */ uint blob_fields; /* number of blob fields */ + uint timestamp_field_offset; /* Field number for timestamp field */ uint varchar_fields; /* number of varchar fields */ uint db_create_options; /* Create options from database */ uint db_options_in_use; /* Options in use */ uint db_record_offset; /* if HA_REC_IN_SEQ */ uint raid_type, raid_chunks; - uint open_count; /* Number of tables in open list */ + uint rowid_field_offset; /* Field_nr +1 to rowid field */ /* Index of auto-updated TIMESTAMP field in field array */ uint primary_key; - uint timestamp_field_offset; - uint next_number_index; - uint next_number_key_offset; - uchar frm_version; - my_bool system; /* Set if system record */ - my_bool crypted; /* If .frm file is crypted */ - my_bool db_low_byte_first; /* Portable row format */ - my_bool crashed; - my_bool is_view; - my_bool name_lock, replace_with_name_lock; - /* - TRUE if this is a system table like 'mysql.proc', which we want to be - able to open and lock even when we already have some tables open and - locked. To avoid deadlocks we have to put certain restrictions on - locking of this table for writing. FALSE - otherwise. - */ - my_bool system_table; + uint next_number_index; /* autoincrement key number */ + uint next_number_key_offset; /* autoinc keypart offset in a key */ + uint next_number_keypart; /* autoinc keypart number in a key */ + uint error, open_errno, errarg; /* error from open_table_def() */ + uint column_bitmap_size; + uchar frm_version; + bool null_field_first; + bool system; /* Set if system table (one record) */ + bool crypted; /* If .frm file is crypted */ + bool db_low_byte_first; /* Portable row format */ + bool crashed; + bool is_view; + bool name_lock, replace_with_name_lock; + bool waiting_on_cond; /* Protection against free */ + ulong table_map_id; /* for row-based replication */ + ulonglong table_map_version; + + /* + Cache for row-based replication table share checks that does not + need to be repeated. Possible values are: -1 when cache value is + not calculated yet, 0 when table *shall not* be replicated, 1 when + table *may* be replicated. + */ + int cached_row_logging_check; + +#ifdef WITH_PARTITION_STORAGE_ENGINE + bool auto_partitioned; + const char *partition_info; + uint partition_info_len; + uint partition_info_buffer_size; + const char *part_state; + uint part_state_len; + handlerton *default_part_db_type; +#endif + + + /* + Set share's table cache key and update its db and table name appropriately. + + SYNOPSIS + set_table_cache_key() + key_buff Buffer with already built table cache key to be + referenced from share. + key_length Key length. + + NOTES + Since 'key_buff' buffer will be referenced from share it should has same + life-time as share itself. + This method automatically ensures that TABLE_SHARE::table_name/db have + appropriate values by using table cache key as their source. + */ + + void set_table_cache_key(char *key_buff, uint key_length) + { + table_cache_key.str= key_buff; + table_cache_key.length= key_length; + /* + Let us use the fact that the key is "db/0/table_name/0" + optional + part for temporary tables. + */ + db.str= table_cache_key.str; + db.length= strlen(db.str); + table_name.str= db.str + db.length + 1; + table_name.length= strlen(table_name.str); + } + + + /* + Set share's table cache key and update its db and table name appropriately. + + SYNOPSIS + set_table_cache_key() + key_buff Buffer to be used as storage for table cache key + (should be at least key_length bytes). + key Value for table cache key. + key_length Key length. + + NOTE + Since 'key_buff' buffer will be used as storage for table cache key + it should has same life-time as share itself. + */ + + void set_table_cache_key(char *key_buff, const char *key, uint key_length) + { + memcpy(key_buff, key, key_length); + set_table_cache_key(key_buff, key_length); + } + + inline bool honor_global_locks() + { + return ((table_category == TABLE_CATEGORY_USER) + || (table_category == TABLE_CATEGORY_SYSTEM)); + } + + inline bool require_write_privileges() + { + return (table_category == TABLE_CATEGORY_PERFORMANCE); + } + + inline ulong get_table_def_version() + { + return table_map_id; + } + + /** + Convert unrelated members of TABLE_SHARE to one enum + representing its type. + + @todo perhaps we need to have a member instead of a function. + */ + enum enum_table_ref_type get_table_ref_type() const + { + if (is_view) + return TABLE_REF_VIEW; + switch (tmp_table) { + case NO_TMP_TABLE: + return TABLE_REF_BASE_TABLE; + case SYSTEM_TMP_TABLE: + return TABLE_REF_I_S_TABLE; + default: + return TABLE_REF_TMP_TABLE; + } + } + /** + Return a table metadata version. + * for base tables, we return table_map_id. + It is assigned from a global counter incremented for each + new table loaded into the table definition cache (TDC). + * for temporary tables it's table_map_id again. But for + temporary tables table_map_id is assigned from + thd->query_id. The latter is assigned from a thread local + counter incremented for every new SQL statement. Since + temporary tables are thread-local, each temporary table + gets a unique id. + * for everything else (views, information schema tables), + the version id is zero. + + This choice of version id is a large compromise + to have a working prepared statement validation in 5.1. In + future version ids will be persistent, as described in WL#4180. + + Let's try to explain why and how this limited solution allows + to validate prepared statements. + + Firstly, sets (in mathematical sense) of version numbers + never intersect for different table types. Therefore, + version id of a temporary table is never compared with + a version id of a view, and vice versa. + + Secondly, for base tables, we know that each DDL flushes the + respective share from the TDC. This ensures that whenever + a table is altered or dropped and recreated, it gets a new + version id. + Unfortunately, since elements of the TDC are also flushed on + LRU basis, this choice of version ids leads to false positives. + E.g. when the TDC size is too small, we may have a SELECT + * FROM INFORMATION_SCHEMA.TABLES flush all its elements, which + in turn will lead to a validation error and a subsequent + reprepare of all prepared statements. This is + considered acceptable, since as long as prepared statements are + automatically reprepared, spurious invalidation is only + a performance hit. Besides, no better simple solution exists. + + For temporary tables, using thd->query_id ensures that if + a temporary table was altered or recreated, a new version id is + assigned. This suits validation needs very well and will perhaps + never change. + + Metadata of information schema tables never changes. + Thus we can safely assume 0 for a good enough version id. + + Views are a special and tricky case. A view is always inlined + into the parse tree of a prepared statement at prepare. + Thus, when we execute a prepared statement, the parse tree + will not get modified even if the view is replaced with another + view. Therefore, we can safely choose 0 for version id of + views and effectively never invalidate a prepared statement + when a view definition is altered. Note, that this leads to + wrong binary log in statement-based replication, since we log + prepared statement execution in form Query_log_events + containing conventional statements. But since there is no + metadata locking for views, the very same problem exists for + conventional statements alone, as reported in Bug#25144. The only + difference between prepared and conventional execution is, + effectively, that for prepared statements the race condition + window is much wider. + In 6.0 we plan to support view metadata locking (WL#3726) and + extend table definition cache to cache views (WL#4298). + When this is done, views will be handled in the same fashion + as the base tables. + + Finally, by taking into account table type, we always + track that a change has taken place when a view is replaced + with a base table, a base table is replaced with a temporary + table and so on. + + @sa TABLE_LIST::is_table_ref_id_equal() + */ + ulong get_table_ref_version() const + { + return (tmp_table == SYSTEM_TMP_TABLE || is_view) ? 0 : table_map_id; + } + } TABLE_SHARE; extern ulong refresh_version; /* Information for one open table */ +enum index_hint_type +{ + INDEX_HINT_IGNORE, + INDEX_HINT_USE, + INDEX_HINT_FORCE +}; struct st_table { st_table() {} /* Remove gcc warning */ @@ -219,16 +561,27 @@ struct st_table { #endif struct st_table *next, *prev; + /* For the below MERGE related members see top comment in ha_myisammrg.cc */ + struct st_table *parent; /* Set in MERGE child. Ptr to parent */ + TABLE_LIST *child_l; /* Set in MERGE parent. List of children */ + TABLE_LIST **child_last_l; /* Set in MERGE parent. End of list */ + THD *in_use; /* Which thread uses this */ Field **field; /* Pointer to fields */ - byte *record[2]; /* Pointer to records */ - byte *insert_values; /* used by INSERT ... UPDATE */ - key_map quick_keys, used_keys; - + uchar *record[2]; /* Pointer to records */ + uchar *write_row_record; /* Used as optimisation in + THD::write_row */ + uchar *insert_values; /* used by INSERT ... UPDATE */ + /* + Map of keys that can be used to retrieve all data from this table + needed by the query without reading the row. + */ + key_map covering_keys; + key_map quick_keys, merge_keys; /* A set of keys that can be used in the query that references this - table + table. All indexes disabled on the table's TABLE_SHARE (see TABLE::s) will be subtracted from this set upon instantiation. Thus for any TABLE t it holds @@ -238,12 +591,14 @@ struct st_table { The set is implemented as a bitmap. */ key_map keys_in_use_for_query; - key_map merge_keys; + /* Map of keys that can be used to calculate GROUP BY without sorting */ + 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; KEY *key_info; /* data of keys in database */ - Field *next_number_field, /* Set if next_number is activated */ - *found_next_number_field, /* Set on open */ - *rowid_field; + Field *next_number_field; /* Set if next_number is activated */ + Field *found_next_number_field; /* Set on open */ Field_timestamp *timestamp_field; /* Table's triggers, 0 if there are no of them */ @@ -252,13 +607,51 @@ struct st_table { ORDER *group; const char *alias; /* alias or table name */ uchar *null_flags; + my_bitmap_map *bitmap_init_value; + MY_BITMAP def_read_set, def_write_set, tmp_set; /* containers */ + MY_BITMAP *read_set, *write_set; /* Active column sets */ + /* + The ID of the query that opened and is using this table. Has different + meanings depending on the table type. + + Temporary tables: + + table->query_id is set to thd->query_id for the duration of a statement + and is reset to 0 once it is closed by the same statement. A non-zero + table->query_id means that a statement is using the table even if it's + not the current statement (table is in use by some outer statement). + + Non-temporary tables: + + Under pre-locked or LOCK TABLES mode: query_id is set to thd->query_id + for the duration of a statement and is reset to 0 once it is closed by + the same statement. A non-zero query_id is used to control which tables + in the list of pre-opened and locked tables are actually being used. + */ query_id_t query_id; + /* + For each key that has quick_keys.is_set(key) == TRUE: estimate of #records + and max #key parts that range access would use. + */ ha_rows quick_rows[MAX_KEY]; + + /* Bitmaps of key parts that =const for the entire join. */ key_part_map const_key_parts[MAX_KEY]; + uint quick_key_parts[MAX_KEY]; uint quick_n_ranges[MAX_KEY]; + /* + Estimate of number of records that satisfy SARGable part of the table + condition, or table->file->records if no SARGable condition could be + constructed. + This value is used by join optimizer as an estimate of number of records + that will pass the table condition (condition that depends on fields of + this table and constants) + */ + ha_rows quick_condition_rows; + /* If this table has TIMESTAMP field with auto-set property (pointed by timestamp_field member) then this variable indicates during which @@ -297,6 +690,12 @@ struct st_table { NULL, including columns declared as "not null" (see maybe_null). */ my_bool null_row; + + /* + TODO: Each of the following flags take up 8 bits. They can just as easily + be put into one single unsigned long and instead of taking up 18 + bytes, it would take up 4. + */ my_bool force_index; my_bool distinct,const_table,no_rows; my_bool key_read, no_keyread; @@ -318,11 +717,13 @@ struct st_table { not rely on that. */ my_bool open_placeholder; + my_bool locked_by_logger; + my_bool no_replicate; my_bool locked_by_name; my_bool fulltext_searched; my_bool no_cache; - /* To signal that we should reset query_id for tables and cols */ - my_bool clear_query_id; + /* To signal that the table is associated with a HANDLER statement */ + my_bool open_by_handler; /* To indicate that a non-null value of the auto_increment field was provided by the user or retrieved from the current record. @@ -331,15 +732,53 @@ struct st_table { my_bool auto_increment_field_not_null; my_bool insert_or_update; /* Can be used by the handler */ my_bool alias_name_used; /* true if table_name is alias */ + my_bool get_fields_in_item_tree; /* Signal to fix_field */ + /* If MERGE children attached to parent. See top comment in ha_myisammrg.cc */ + my_bool children_attached; REGINFO reginfo; /* field connections */ MEM_ROOT mem_root; GRANT_INFO grant; FILESORT_INFO sort; - TABLE_SHARE share_not_to_be_used; /* To be deleted when true shares */ +#ifdef WITH_PARTITION_STORAGE_ENGINE + partition_info *part_info; /* Partition related information */ + bool no_partitions_used; /* If true, all partitions have been pruned away */ +#endif bool fill_item_list(List<Item> *item_list) const; void reset_item_list(List<Item> *item_list) const; + void clear_column_bitmaps(void); + void prepare_for_position(void); + void mark_columns_used_by_index_no_reset(uint index, MY_BITMAP *map); + void mark_columns_used_by_index(uint index); + void restore_column_maps_after_mark_index(); + void mark_auto_increment_column(void); + void mark_columns_needed_for_update(void); + void mark_columns_needed_for_delete(void); + void mark_columns_needed_for_insert(void); + inline void column_bitmaps_set(MY_BITMAP *read_set_arg, + MY_BITMAP *write_set_arg) + { + read_set= read_set_arg; + write_set= write_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 use_all_columns() + { + column_bitmaps_set(&s->all_set, &s->all_set); + } + inline void default_column_bitmaps() + { + read_set= &def_read_set; + write_set= &def_write_set; + } /* Is table open or should be treated as such by name-locking? */ inline bool is_name_opened() { return db_stat || open_placeholder; } /* @@ -347,6 +786,7 @@ struct st_table { */ inline bool needs_reopen_or_name_lock() { return s->version != refresh_version; } + bool is_children_attached(void); }; enum enum_schema_table_state @@ -361,11 +801,16 @@ typedef struct st_foreign_key_info LEX_STRING *forein_id; LEX_STRING *referenced_db; LEX_STRING *referenced_table; - LEX_STRING *constraint_method; + LEX_STRING *update_method; + LEX_STRING *delete_method; + LEX_STRING *referenced_key_name; List<LEX_STRING> foreign_fields; List<LEX_STRING> referenced_fields; } FOREIGN_KEY_INFO; +/* + Make sure that the order of schema_tables and enum_schema_tables are the same. +*/ enum enum_schema_tables { @@ -374,11 +819,23 @@ enum enum_schema_tables SCH_COLLATION_CHARACTER_SET_APPLICABILITY, SCH_COLUMNS, SCH_COLUMN_PRIVILEGES, + SCH_ENGINES, + SCH_EVENTS, + SCH_FILES, + SCH_GLOBAL_STATUS, + SCH_GLOBAL_VARIABLES, SCH_KEY_COLUMN_USAGE, SCH_OPEN_TABLES, + SCH_PARTITIONS, + SCH_PLUGINS, + SCH_PROCESSLIST, + SCH_PROFILES, + SCH_REFERENTIAL_CONSTRAINTS, SCH_PROCEDURES, SCH_SCHEMATA, SCH_SCHEMA_PRIVILEGES, + SCH_SESSION_STATUS, + SCH_SESSION_VARIABLES, SCH_STATISTICS, SCH_STATUS, SCH_TABLES, @@ -392,14 +849,47 @@ enum enum_schema_tables }; +#define MY_I_S_MAYBE_NULL 1 +#define MY_I_S_UNSIGNED 2 + + +#define SKIP_OPEN_TABLE 0 // do not open table +#define OPEN_FRM_ONLY 1 // open FRM file only +#define OPEN_FULL_TABLE 2 // open FRM,MYD, MYI files + typedef struct st_field_info { + /** + This is used as column name. + */ const char* field_name; + /** + For string-type columns, this is the maximum number of + characters. Otherwise, it is the 'display-length' for the column. + */ uint field_length; + /** + This denotes data type for the column. For the most part, there seems to + be one entry in the enum for each SQL data type, although there seem to + be a number of additional entries in the enum. + */ enum enum_field_types field_type; int value; - bool maybe_null; + /** + This is used to set column attributes. By default, columns are @c NOT + @c NULL and @c SIGNED, and you can deviate from the default + by setting the appopriate flags. You can use either one of the flags + @c MY_I_S_MAYBE_NULL and @cMY_I_S_UNSIGNED or + combine them using the bitwise or operator @c |. Both flags are + defined in table.h. + */ + uint field_flags; // Field atributes(maybe_null, signed, unsigned etc.) const char* old_name; + /** + This should be one of @c SKIP_OPEN_TABLE, + @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE. + */ + uint open_method; } ST_FIELD_INFO; @@ -416,11 +906,11 @@ typedef struct st_schema_table int (*fill_table) (THD *thd, TABLE_LIST *tables, COND *cond); /* Handle fileds for old SHOW */ int (*old_format) (THD *thd, struct st_schema_table *schema_table); - int (*process_table) (THD *thd, TABLE_LIST *tables, - TABLE *table, bool res, const char *base_name, - const char *file_name); + int (*process_table) (THD *thd, TABLE_LIST *tables, TABLE *table, + bool res, LEX_STRING *db_name, LEX_STRING *table_name); int idx_field1, idx_field2; bool hidden; + uint i_s_requested_object; /* the object we need to open(TABLE | VIEW) */ } ST_SCHEMA_TABLE; @@ -445,6 +935,9 @@ typedef struct st_schema_table #define VIEW_CHECK_ERROR 1 #define VIEW_CHECK_SKIP 2 +/** The threshold size a blob field buffer before it is freed */ +#define MAX_TDC_BLOB_SIZE 65536 + struct st_lex; class select_union; class TMP_TABLE_PARAM; @@ -523,9 +1016,25 @@ public: (TABLE_LIST::join_using_fields != NULL) */ +class Index_hint; struct TABLE_LIST { TABLE_LIST() {} /* Remove gcc warning */ + + /** + Prepare TABLE_LIST that consists of one table instance to use in + simple_open_and_lock_tables + */ + inline void init_one_table(const char *db_name_arg, + const char *table_name_arg, + enum thr_lock_type lock_type_arg) + { + bzero((char*) this, sizeof(*this)); + db= (char*) db_name_arg; + table_name= alias= (char*) table_name_arg; + lock_type= lock_type_arg; + } + /* List of tables local to a subquery (used by SQL_LIST). Considers views as leaves (unlike 'next_leaf' below). Created at parse time @@ -579,8 +1088,9 @@ struct TABLE_LIST */ TABLE_LIST *next_name_resolution_table; /* Index names in a "... JOIN ... USE/IGNORE INDEX ..." clause. */ - List<String> *use_index, *ignore_index; - TABLE *table; /* opened table */ + List<Index_hint> *index_hints; + TABLE *table; /* opened table */ + uint table_id; /* table id (from binlog) for opened table */ /* select_result for derived table to pass it from table creation to table filling procedure @@ -628,6 +1138,8 @@ struct TABLE_LIST (non-zero only for merged underlying tables of a view). */ TABLE_LIST *referencing_view; + /* Ptr to parent MERGE table list item. See top comment in ha_myisammrg.cc */ + TABLE_LIST *parent_l; /* Security context (non-zero only for tables which belong to view with SQL SECURITY DEFINER) @@ -647,7 +1159,7 @@ struct TABLE_LIST TABLE_LIST *next_leaf; Item *where; /* VIEW WHERE clause condition */ Item *check_option; /* WITH CHECK OPTION condition */ - LEX_STRING query; /* text of (CRETE/SELECT) statement */ + LEX_STRING select_stmt; /* text of (CREATE/SELECT) statement */ LEX_STRING md5; /* md5 of query text */ LEX_STRING source; /* source of CREATE VIEW */ LEX_STRING view_db; /* saved view database */ @@ -674,8 +1186,8 @@ struct TABLE_LIST thr_lock_type lock_type; uint outer_join; /* Which join type */ uint shared; /* Used in multi-upd */ - uint db_length; - uint32 table_name_length; + size_t db_length; + size_t table_name_length; bool updatable; /* VIEW/TABLE can be updated now */ bool straight; /* optimize with prev table */ bool updating; /* for replicate-do/ignore table */ @@ -700,6 +1212,7 @@ struct TABLE_LIST bool check_option_processed; /* FRMTYPE_ERROR if any type is acceptable */ enum frm_type_enum required_type; + handlerton *db_type; /* table_type for handler */ char timestamp_buffer[20]; /* buffer for timestamp (19+1) */ /* This TABLE_LIST object is just placeholder for prelocking, it will be @@ -712,6 +1225,33 @@ struct TABLE_LIST ... SELECT implementation). */ bool create; + bool internal_tmp_table; + + + /* View creation context. */ + + View_creation_ctx *view_creation_ctx; + + /* + Attributes to save/load view creation context in/from frm-file. + + Ther are required only to be able to use existing parser to load + view-definition file. As soon as the parser parsed the file, view + creation context is initialized and the attributes become redundant. + + These attributes MUST NOT be used for any purposes but the parsing. + */ + + LEX_STRING view_client_cs_name; + LEX_STRING view_connection_cl_name; + + /* + View definition (SELECT-statement) in the UTF-form. + */ + + LEX_STRING view_body_utf8; + + /* End of view definition context. */ /** Indicates what triggers we need to pre-load for this TABLE_LIST @@ -720,6 +1260,10 @@ struct TABLE_LIST */ uint8 trg_event_map; + uint i_s_requested_object; + bool has_db_lookup_value; + bool has_table_lookup_value; + uint table_open_method; enum enum_schema_table_state schema_table_state; void calc_md5(char *buffer); void set_underlying_merge(); @@ -731,7 +1275,7 @@ struct TABLE_LIST return derived || view || schema_table || create && !table->db_stat || !table; } - void print(THD *thd, String *str); + void print(THD *thd, String *str, enum_query_type query_type); bool check_single_table(TABLE_LIST **table, table_map map, TABLE_LIST *view); bool set_insert_values(MEM_ROOT *mem_root); @@ -770,15 +1314,68 @@ struct TABLE_LIST void reinit_before_use(THD *thd); Item_subselect *containing_subselect(); + /* + Compiles the tagged hints list and fills up st_table::keys_in_use_for_query, + st_table::keys_in_use_for_group_by, st_table::keys_in_use_for_order_by, + st_table::force_index and st_table::covering_keys. + */ + bool process_index_hints(TABLE *table); + + /* Access MERGE child def version. See top comment in ha_myisammrg.cc */ + inline ulong get_child_def_version() + { + return child_def_version; + } + inline void set_child_def_version(ulong version) + { + child_def_version= version; + } + inline void init_child_def_version() + { + child_def_version= ~0UL; + } + + /** + Compare the version of metadata from the previous execution + (if any) with values obtained from the current table + definition cache element. + + @sa check_and_update_table_version() + */ + inline + bool is_table_ref_id_equal(TABLE_SHARE *s) const + { + return (m_table_ref_type == s->get_table_ref_type() && + m_table_ref_version == s->get_table_ref_version()); + } + + /** + Record the value of metadata version of the corresponding + table definition cache element in this parse tree node. + + @sa check_and_update_table_version() + */ + inline + void set_table_ref_id(TABLE_SHARE *s) + { + m_table_ref_type= s->get_table_ref_type(); + m_table_ref_version= s->get_table_ref_version(); + } + private: bool prep_check_option(THD *thd, uint8 check_opt_type); bool prep_where(THD *thd, Item **conds, bool no_where_clause); - void print_index_hint(THD *thd, String *str, const char *hint, - uint32 hint_length, List<String>); /* Cleanup for re-execution in a prepared statement or a stored procedure. */ + + /* Remembered MERGE child def version. See top comment in ha_myisammrg.cc */ + ulong child_def_version; + /** See comments for set_metadata_id() */ + enum enum_table_ref_type m_table_ref_type; + /** See comments for set_metadata_id() */ + ulong m_table_ref_version; }; class Item; @@ -936,4 +1533,52 @@ typedef struct st_open_table_list{ uint32 in_use,locked; } OPEN_TABLE_LIST; +typedef struct st_table_field_w_type +{ + LEX_STRING name; + LEX_STRING type; + LEX_STRING cset; +} TABLE_FIELD_W_TYPE; + + +my_bool +table_check_intact(TABLE *table, const uint table_f_count, + const TABLE_FIELD_W_TYPE *table_def); + +static inline my_bitmap_map *tmp_use_all_columns(TABLE *table, + MY_BITMAP *bitmap) +{ + my_bitmap_map *old= bitmap->bitmap; + bitmap->bitmap= table->s->all_set.bitmap; + return old; +} + + +static inline void tmp_restore_column_map(MY_BITMAP *bitmap, + my_bitmap_map *old) +{ + bitmap->bitmap= old; +} + +/* The following is only needed for debugging */ + +static inline my_bitmap_map *dbug_tmp_use_all_columns(TABLE *table, + MY_BITMAP *bitmap) +{ +#ifndef DBUG_OFF + return tmp_use_all_columns(table, bitmap); +#else + return 0; +#endif +} + +static inline void dbug_tmp_restore_column_map(MY_BITMAP *bitmap, + my_bitmap_map *old) +{ +#ifndef DBUG_OFF + tmp_restore_column_map(bitmap, old); +#endif +} + +size_t max_row_length(TABLE *table, const uchar *data); |