MDEV-16983 Application-time periods: foreign key PART 1/4
This work adds support for FOREIGN KEYS for SQL:2011 Application-time
periods feature.
* Two hidden keys are added in key matching a referred foreign key;
* Referential integrity check is done completely on sql layer, in handler;
* A new struct FOREIGN_KEY is introduced to store a prelocked referential
metadata in TABLE
Limitations:
* Only versionde-to-versioned and plain-to-plain references are supported
at this moment
* innodb: a flag denoting a period is added to FK flags,
see dict_create_add_foreign_to_dictionary() and dict_load_foreign().
In this way only one period per table is supported, and it's quite
poorly scalable.
In this commit:
* Update is treated as delete + insert which causes false-positives.
(will bi fixed in PART 2)
* Self-referencing tables have false-negatives during deletes, since
the same row could be fetched during lookup (will be fixed in PART 3)
* NULL fields are not supported (will be fixed in part 4)
MDEV-16978 Application-time periods: WITHOUT OVERLAPS
* The overlaps check is implemented on a handler level per row command.
It creates a separate cursor (actually, another handler instance) and
caches it inside the original handler, when ha_update_row or
ha_insert_row is issued. Cursor closes on unlocking the handler.
* Containing the same key in index means unique constraint violation
even in usual terms. So we fetch left and right neighbours and check
that they have same key prefix, excluding from the key only the period part.
If it doesnt match, then there's no such neighbour, and the check passes.
Otherwise, we check if this neighbour intersects with the considered key.
* The check does not introduce new error and fails with ER_DUPP_KEY error.
This might break REPLACE workflow and should be fixed separately
cleanup: prepare "update_handler" for WITHOUT OVERLAPS
* rename to a generic name
* move remaning initializations from query exec to prepare time
* simplify/unify key handling in open_table_from_share and delayed
* remove dead code
* move tests where they belong