mariadb/storage/innobase
Marko Mäkelä 8777458a6e MDEV-6076 Persistent AUTO_INCREMENT for InnoDB
This should be functionally equivalent to WL#6204 in MySQL 8.0.0, with
the notable difference that the file format changes are limited to
repurposing a previously unused data field in B-tree pages.

For persistent InnoDB tables, write the last used AUTO_INCREMENT
value to the root page of the clustered index, in the previously
unused (0) PAGE_MAX_TRX_ID field, now aliased as PAGE_ROOT_AUTO_INC.
Unlike some other previously unused InnoDB data fields, this one was
actually always zero-initialized, at least since MySQL 3.23.49.

The writes to PAGE_ROOT_AUTO_INC are protected by SX or X latch on the
root page. The SX latch will allow concurrent read access to the root
page. (The field PAGE_ROOT_AUTO_INC will only be read on the
first-time call to ha_innobase::open() from the SQL layer. The
PAGE_ROOT_AUTO_INC can only be updated when executing SQL, so
read/write races are not possible.)

During INSERT, the PAGE_ROOT_AUTO_INC is updated by the low-level
function btr_cur_search_to_nth_level(), adding no extra page
access. [Adaptive hash index lookup will be disabled during INSERT.]

If some rare UPDATE modifies an AUTO_INCREMENT column, the
PAGE_ROOT_AUTO_INC will be adjusted in a separate mini-transaction in
ha_innobase::update_row().

When a page is reorganized, we have to preserve the PAGE_ROOT_AUTO_INC
field.

During ALTER TABLE, the initial AUTO_INCREMENT value will be copied
from the table. ALGORITHM=COPY and online log apply in LOCK=NONE will
update PAGE_ROOT_AUTO_INC in real time.

innodb_col_no(): Determine the dict_table_t::cols[] element index
corresponding to a Field of a non-virtual column.
(The MySQL 5.7 implementation of virtual columns breaks the 1:1
relationship between Field::field_index and dict_table_t::cols[].
Virtual columns are omitted from dict_table_t::cols[]. Therefore,
we must translate the field_index of AUTO_INCREMENT columns into
an index of dict_table_t::cols[].)

Upgrade from old data files:

By default, the AUTO_INCREMENT sequence in old data files would appear
to be reset, because PAGE_MAX_TRX_ID or PAGE_ROOT_AUTO_INC would contain
the value 0 in each clustered index page. In new data files,
PAGE_ROOT_AUTO_INC can only be 0 if the table is empty or does not contain
any AUTO_INCREMENT column.

For backward compatibility, we use the old method of
SELECT MAX(auto_increment_column) for initializing the sequence.

btr_read_autoinc(): Read the AUTO_INCREMENT sequence from a new-format
data file.

btr_read_autoinc_with_fallback(): A variant of btr_read_autoinc()
that will resort to reading MAX(auto_increment_column) for data files
that did not use AUTO_INCREMENT yet. It was manually tested that during
the execution of innodb.autoinc_persist the compatibility logic is
not activated (for new files, PAGE_ROOT_AUTO_INC is never 0 in nonempty
clustered index root pages).

initialize_auto_increment(): Replaces
ha_innobase::innobase_initialize_autoinc(). This initializes
the AUTO_INCREMENT metadata. Only called from ha_innobase::open().

ha_innobase::info_low(): Do not try to lazily initialize
dict_table_t::autoinc. It must already have been initialized by
ha_innobase::open() or ha_innobase::create().

Note: The adjustments to class ha_innopart were not tested, because
the source code (native InnoDB partitioning) is not being compiled.
2016-12-16 09:19:19 +02:00
..
api MDEV-10813 - Clean-up InnoDB atomics, memory barriers and mutexes 2016-10-17 18:35:48 +04:00
btr MDEV-6076 Persistent AUTO_INCREMENT for InnoDB 2016-12-16 09:19:19 +02:00
buf shut up annoying InnoDB warning when --gdb 2016-12-12 20:27:20 +01:00
data Merge InnoDB 5.7 from mysql-5.7.14. 2016-09-08 15:49:03 +03:00
dict MDEV-6076 Persistent AUTO_INCREMENT for InnoDB 2016-12-16 09:19:19 +02:00
eval Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
fil MDEV-11487 Revert InnoDB internal temporary tables from WL#7682 2016-12-09 12:05:07 +02:00
fsp Merge InnoDB 5.7 from mysql-5.7.14. 2016-09-08 15:49:03 +03:00
fts MDEV-11487 Revert InnoDB internal temporary tables from WL#7682 2016-12-09 12:05:07 +02:00
fut Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
gis MDEV-11487 Revert InnoDB internal temporary tables from WL#7682 2016-12-09 12:05:07 +02:00
ha Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
handler MDEV-6076 Persistent AUTO_INCREMENT for InnoDB 2016-12-16 09:19:19 +02:00
ibuf MDEV-10813 - Clean-up InnoDB atomics, memory barriers and mutexes 2016-10-17 18:35:48 +04:00
include MDEV-6076 Persistent AUTO_INCREMENT for InnoDB 2016-12-16 09:19:19 +02:00
lock Merge branch '10.2-vats' of https://github.com/sensssz/server into sensssz-10.2-vats 2016-12-07 09:18:41 +02:00
log MDEV-5800 InnoDB support for indexed vcols 2016-12-12 20:27:42 +01:00
mach Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
mem Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
mtr MDEV-11487 Revert InnoDB internal temporary tables from WL#7682 2016-12-09 12:05:07 +02:00
mysql-test/storage_engine Follow-up for MDEV-6720 (enable connection log in mysqltest by default) 2016-06-19 20:30:03 +03:00
os MDEV-10813 - Clean-up InnoDB atomics, memory barriers and mutexes 2016-10-17 18:35:49 +04:00
page MDEV-6076 Persistent AUTO_INCREMENT for InnoDB 2016-12-16 09:19:19 +02:00
pars Merge InnoDB 5.7 from mysql-5.7.14. 2016-09-08 15:49:03 +03:00
que Merge InnoDB 5.7 from mysql-5.7.14. 2016-09-08 15:49:03 +03:00
read Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
rem Merge InnoDB 5.7 from mysql-5.7.14. 2016-09-08 15:49:03 +03:00
row MDEV-6076 Persistent AUTO_INCREMENT for InnoDB 2016-12-16 09:19:19 +02:00
srv InnoDB: don't stop purge threads if there's work to do 2016-12-15 09:35:25 +01:00
sync MDEV-11296 - InnoDB stalls under OLTP RW on P8 2016-11-25 12:41:35 +04:00
trx MDEV-11236 Failing assertion: state == TRX_STATE_NOT_STARTED 2016-12-02 16:44:53 +02:00
usr Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
ut MDEV-11075: Power - runtime detection of optimized instructions 2016-12-12 15:35:08 +11:00
CMakeLists.txt MDEV-11195: Simplify enablement of NUMA in innodb/xtradb 2016-11-02 14:37:43 +11:00
compile-innodb move to storage/innobase 2015-05-04 19:17:21 +02:00
COPYING.Google move to storage/innobase 2015-05-04 19:17:21 +02:00
COPYING.Percona move to storage/innobase 2015-05-04 19:17:21 +02:00
innodb.cmake MDEV-10813 - Clean-up InnoDB atomics, memory barriers and mutexes 2016-10-17 18:35:49 +04:00
plugin_exports Solaris compilation failure: xtradb is linked in statically, ha_innodb.so needs 2014-05-01 14:05:52 +02:00