diff options
author | Jon Olav Hauglid <jon.hauglid@oracle.com> | 2011-06-01 10:06:55 +0200 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@oracle.com> | 2011-06-01 10:06:55 +0200 |
commit | f21fd6e40f1c593534f7530475571a3369f6c74f (patch) | |
tree | 250d4171faac82b1092b588097b1a32c82ea4336 /sql/handler.h | |
parent | bd708b42400ff2ca8ba22accc696acd3539d9859 (diff) | |
download | mariadb-git-f21fd6e40f1c593534f7530475571a3369f6c74f.tar.gz |
Bug#11853126 RE-ENABLE CONCURRENT READS WHILE CREATING
SECONDARY INDEX IN INNODB
The patches for Bug#11751388 and Bug#11784056 enabled concurrent
reads while creating secondary indexes in InnoDB. However, they
introduced a regression. This regression occured if ALTER TABLE
failed after the index had been added, for example during the
lock upgrade needed to update .FRM. If this happened, InnoDB
and the server got out of sync with regards to which indexes
actually existed. Therefore the patch for Bug#11815600 again
disabled concurrent reads.
This patch re-enables concurrent reads. The original regression
is fixed by splitting the ADD INDEX operation into two parts.
First the new index is created but not made active. This is
done while concurrent reads are allowed. The second part of
the operation makes the index active (or reverts the change).
This is done after lock upgrade, which prevents the original
regression.
In order to implement this change, the patch changes the storage
API for in-place index creation. handler::add_index() is split
into two functions, handler_add_index() and
handler::final_add_index(). The former for creating indexes without
making them visible and the latter for commiting (i.e. making
visible) new indexes or reverting the changes.
Large parts of this patch were written by Marko Mäkelä.
Test case added to innodb_mysql_lock.test.
Diffstat (limited to 'sql/handler.h')
-rw-r--r-- | sql/handler.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/sql/handler.h b/sql/handler.h index fbc52170297..893d8f015f5 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1159,6 +1159,27 @@ uint calculate_key_len(TABLE *, uint, const uchar *, key_part_map); */ #define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1) + +/** + Index creation context. + Created by handler::add_index() and freed by handler::final_add_index(). +*/ + +class handler_add_index +{ +public: + /* Table where the indexes are added */ + TABLE* const table; + /* Indexes being created */ + KEY* const key_info; + /* Size of key_info[] */ + const uint num_of_keys; + handler_add_index(TABLE *table_arg, KEY *key_info_arg, uint num_of_keys_arg) + : table (table_arg), key_info (key_info_arg), num_of_keys (num_of_keys_arg) + {} + virtual ~handler_add_index() {} +}; + /** The handler class is the interface for dynamically loadable storage engines. Do not add ifdefs and take care when adding or @@ -1717,8 +1738,36 @@ public: virtual ulong index_flags(uint idx, uint part, bool all_parts) const =0; - virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys) +/** + First phase of in-place add index. + Handlers are supposed to create new indexes here but not make them + visible. + + @param table_arg Table to add index to + @param key_info Information about new indexes + @param num_of_key Number of new indexes + @param add[out] Context of handler specific information needed + for final_add_index(). + + @note This function can be called with less than exclusive metadata + lock depending on which flags are listed in alter_table_flags. +*/ + virtual int add_index(TABLE *table_arg, KEY *key_info, uint num_of_keys, + handler_add_index **add) { return (HA_ERR_WRONG_COMMAND); } + +/** + Second and last phase of in-place add index. + Commit or rollback pending new indexes. + + @param add Context of handler specific information from add_index(). + @param commit If true, commit. If false, rollback index changes. + + @note This function is called with exclusive metadata lock. +*/ + virtual int final_add_index(handler_add_index *add, bool commit) + { return (HA_ERR_WRONG_COMMAND); } + virtual int prepare_drop_index(TABLE *table_arg, uint *key_num, uint num_of_keys) { return (HA_ERR_WRONG_COMMAND); } |