mariadb/mysql-test/suite/versioning/r
Nikita Malyavin 9b5f36a269 MDEV-36274 Implement IDENTITY column
This patch implements basic IDENTITY feature, with the following
syntax:

<col> GENERATED {ALWAYS AS | BY DEFAULT [ON NULL]} identity_props

The following identity_props are recognized and saved in
the table metadata, but ignored
- START WITH num
- INCREMENT BY num
- MAXVALUE num
- MINVALUE num
- ORDER, NOORDER
- CYCLE, NOCYCLE
- NOMINVALUE, NO MINVALUE
- NOMAXVALUE, NO MAXVALUE

The following identity_props are newly added keywords, however they are
not reserved, i.e. can be used as identifiers, column names, etc. just
as before:
- KEEP
- SCALE
- SHARD
- EXTEND
- NOKEEP
- NOSCALE
- NOSHARD
- NOEXTEND

The patch is designed in minimalistic manner, re-using existing
AUTO_INCREMENT implementation, yet utilizing the default values
evaluation mechanism. As a result, it grants usage of CHECK constraints
and other table expressions: vcols, default values with identity column.

Some notes:
* IDENTITY is evaluated as Field's default_value. Even GENERATED ALWAYS
is considered "default", since the IDENTITY expression is not
determistic.

* However, the GENERATED ALWAYS kind cannot be assigned in DMLs in
STRICT SQL_MODE. That is, the behavior for users is like for other
GENERATED ALWAYS columns.

* It honors INSERT_ID and uses it, which is important for
statement-based replication to work.

* START WITH and INCREMENT BY are ignored. auto_increment_increment and
auto_increment_offset are being followed instead, exactly as for
AUTO_INCREMENT.

* Since IDENTITY behaves as DEFAULT, it cannot follow
NO_AUTO_VALUE_ON_ZERO and should accept user-set keyword with zeroes,
even when it is off, otherwise, `default` will not work.
See test "Zeroes and defaults handling".

* IDENTITY column is always replicated and saved in mariadb-dump, which
is guaranteed by using default_value instead of vcol_expr (vcols, even
stored, are usually not replicated).

* In frm, it is loaded and saved as a default expression. For that,
parse_vcol_expr definition was extended to support things like GENERATED
BY DEFAULT, and even GENERATED ALWAYS. That is, no EXTRA2 header had to
be added.

* AUTO_INCREMENT is not transformed into default_value and works
completely as before.

* IDENTITY should work without the key, and moreover should generate new
values without repetition. If no suitable key is created by user, one is
created implicitly.

* New IDENTITY keyword is added as not-reserved.

handler::update_auto_increment: extract a part checking for explicit
value and zeroes. Invoke only for AUTO_INCREMENT. The rest is contained
in handler::update_auto_increment_impl, which will be invoked by
IDENTITY. Add field argument to use instead of next_number_field.
Note that for IDENTITY, field is not always next_number_field
(Item_default_value can create its own field).
* show_create.cc: changes make it possible to output Field's
default_value as GENERATED BY DEFAULT, instead of DEFAULT (expr).
* Item_field::check_vcol_func_processor: allow default on IDENTITY
fields (they still have AUTO_INCREMENT properties, like unireg_check)
* Item_default_value::tie_field: forbid default(x) exprs.
Item_default_value distinguishes `default` and `default(x)` by the
vcol_assignment_ok flag.
* mysql_prepare_create_table_finalize: make sure there is at least
one key where IDENTITY field goes as a first key_part. If there's none -
create one.

Known issues:
* LAST_INSERT_ID() is not working for now.

Limitations:
* default(identity_column), is disabled, because persistent write is
not properly done in that case.
2025-06-30 19:51:44 +02:00
..
alter.result MDEV-36274 Implement IDENTITY column 2025-06-30 19:51:44 +02:00
autoinc.result MDEV-22562 Assertion `next_insert_id == 0' upon UPDATE on system-versioned table 2021-03-31 21:25:36 +03:00
binlog.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
commit_id.result Removed "<select expression> INTO <destination>" deprication. 2023-02-03 11:57:50 +03:00
create.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
cte,32bit.rdiff MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range 2024-05-27 12:39:02 +02:00
cte.result MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range 2024-05-27 12:39:02 +02:00
data.result Merge branch '11.4' into 11.7 2025-02-06 16:46:36 +01:00
debug.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
delete.result MDEV-25644 UPDATE not working properly on transaction precise system versioned table 2023-07-20 18:22:31 +03:00
delete_history,32bit.rdiff MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range 2024-05-27 12:39:02 +02:00
delete_history.result MariaDB 11.4.4 release 2024-11-08 07:17:00 +01:00
derived.result MDEV-15751 CURRENT_TIMESTAMP should return a TIMESTAMP [WITH TIME ZONE?] 2024-10-19 22:48:23 +02:00
foreign.result Removed "<select expression> INTO <destination>" deprication. 2023-02-03 11:57:50 +03:00
insert.result MariaDB 11.4.4 release 2024-11-08 07:17:00 +01:00
insert2.result MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range 2024-05-27 12:39:02 +02:00
misc.result MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range 2024-05-27 12:39:02 +02:00
not_embedded.result MDEV-5215 prerequisite: remove test and test_* database hacks in the test suite 2022-11-01 16:33:00 +01:00
old_timestamp.result Merge branch '11.4' into 11.7 2025-02-06 16:46:36 +01:00
online.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
optimized.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
partition,heap.rdiff Merge branch '11.4' into 11.5 2024-08-05 17:50:18 +02:00
partition.result Merge 11.4 into 11.8 2025-04-02 14:07:01 +03:00
replace.result MDEV-35343 unexpected replace behaviour when long unique index on 2025-01-14 18:56:13 +03:00
rpl.result MariaDB 11.4.4 release 2024-11-08 07:17:00 +01:00
rpl_mix.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
rpl_row.result MariaDB 11.4.4 release 2024-11-08 07:17:00 +01:00
rpl_stmt.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
select.result MDEV-32188 make TIMESTAMP use whole 32-bit unsigned range 2024-05-27 12:39:02 +02:00
select2,trx_id.rdiff Merge 10.11 into 11.4 2025-01-09 07:58:08 +02:00
select2.result Removed "<select expression> INTO <destination>" deprication. 2023-02-03 11:57:50 +03:00
simple.result MDEV-28632 Change default of explicit_defaults_for_timestamp to ON 2022-08-10 15:03:22 +02:00
sysvars.result Merge branch '10.3' into 10.4 2021-07-31 22:59:58 +02:00
trx_id.result MDEV-19123 Change default charset from latin1 to utf8mb4 2024-07-11 10:21:07 +04:00
update,trx_id.rdiff Merge branch '10.11' into 11.0 2023-08-09 07:53:48 +02:00
update-big.result MDEV-17554 Auto-create new partition for system versioned tables with history partitioned by INTERVAL/LIMIT 2022-05-06 15:11:02 +03:00
update.result fix incorrect merge 15700f54c2 2025-04-18 09:41:24 +02:00
view.result MDEV-23779 Error upon querying the view, that selecting from versioned table with partitions 2020-10-20 10:49:54 +03:00