mariadb/include
Aleksey Midenkov 92bfc0e8c4 MDEV-17554 Auto-create new partition for system versioned tables with history partitioned by INTERVAL/LIMIT
:: Syntax change ::

Keyword AUTO enables history partition auto-creation.

Examples:

    CREATE TABLE t1 (x int) WITH SYSTEM VERSIONING
    PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR AUTO;

    CREATE TABLE t1 (x int) WITH SYSTEM VERSIONING
    PARTITION BY SYSTEM_TIME INTERVAL 1 MONTH
    STARTS '2021-01-01 00:00:00' AUTO PARTITIONS 12;

    CREATE TABLE t1 (x int) WITH SYSTEM VERSIONING
    PARTITION BY SYSTEM_TIME LIMIT 1000 AUTO;

Or with explicit partitions:

    CREATE TABLE t1 (x int) WITH SYSTEM VERSIONING
    PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR AUTO
    (PARTITION p0 HISTORY, PARTITION pn CURRENT);

To disable or enable auto-creation one can use ALTER TABLE by adding
or removing AUTO from partitioning specification:

    CREATE TABLE t1 (x int) WITH SYSTEM VERSIONING
    PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR AUTO;

    # Disables auto-creation:
    ALTER TABLE t1 PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR;

    # Enables auto-creation:
    ALTER TABLE t1 PARTITION BY SYSTEM_TIME INTERVAL 1 HOUR AUTO;

If the rest of partitioning specification is identical to CREATE TABLE
no repartitioning will be done (for details see MDEV-27328).

:: Description ::

Before executing history-generating DML command (see the list of commands below)
add N history partitions, so that N would be sufficient for potentially
generated history. N > 1 may be required when history partitions are switched
by INTERVAL and current_timestamp is N times further than the interval
boundary of the last history partition.

If the last history partition equals or exceeds LIMIT records then new history
partition is created and selected as the working partition. According to
MDEV-28411 partitions cannot be switched (or created) while the command is
running. Thus LIMIT does not carry strict limitation and the history partition
size must be planned as LIMIT value plus average number of history one DML
command can generate.

Auto-creation is implemented by synchronous fast_alter_partition_table() call
from the thread of the executed DML command before the command itself is run
(by the fallback and retry mechanism similar to Discovery feature,
see Open_table_context).

The name for newly added partitions are generated like default partition names
with extension of MDEV-22155 (which avoids name clashes by extending assignment
counter to next free-enough gap).

These DML commands can trigger auto-creation:

    DELETE (including multitable DELETE, excluding DELETE HISTORY)
    UPDATE (including multitable UPDATE)
    REPLACE (including REPLACE .. SELECT)
    INSERT .. ON DUPLICATE KEY UPDATE (including INSERT .. SELECT .. ODKU)
    LOAD DATA .. REPLACE

:: Bug fixes ::

MDEV-23642 Locking timeout caused by auto-creation affects original DML

    The reasons for this are:

    - Do not disrupt main business process (the history is auxiliary service);

    - Consequences are non-fatal (history is not lost, but comes into wrong
      partition; fixed by partitioning rebuild);

    - There is more freedom for application to fail in this case or not: it may
      read warning info and find corresponding error number.

    - While non-failing command is easy to handle by an application and fail it,
      the opposite is hard to handle: there is no automatic actions to fix
      failed command and retry, DBA intervention is required and until then
      application is non-functioning.

MDEV-23639 Auto-create does not work under LOCK TABLES or inside triggers

    Don't do tdc_remove_table() for OT_ADD_HISTORY_PARTITION because it is
    not possible in locked tables mode.

    LTM_LOCK_TABLES mode (and LTM_PRELOCKED_UNDER_LOCK_TABLES) works out
    of the box as fast_alter_partition_table() can reopen tables via
    locked_tables_list.

    In LTM_PRELOCKED we reopen and relock table manually.

:: More fixes ::

* some_table_marked_for_reopen flag fix

  some_table_marked_for_reopen affets only reopen of
  m_locked_tables. I.e. Locked_tables_list::reopen_tables() reopens only
  tables from m_locked_tables.

* Unused can_recover_from_failed_open() condition

  Is recover_from_failed_open() can be really used after
  open_and_process_routine()?

:: Reviewed by ::

Sergei Golubchik <serg@mariadb.org>
2022-05-06 15:11:02 +03:00
..
atomic MDEV-19696 - Cleanup gcc sync builtins 2019-07-03 12:11:22 +03:00
mysql Merge 10.7 into 10.8 2022-03-11 15:56:59 +02:00
providers support lzma < 5.1.3alpha 2022-02-09 19:13:52 +01:00
aria_backup.h S3 is pluggable now 2020-06-19 19:43:07 +02:00
assume_aligned.h Remove a misleading copyright message 2020-03-21 10:25:54 +02:00
big_endian.h Update FSF address 2019-05-11 19:25:02 +03:00
byte_order_generic.h Fix all warnings given by UBSAN 2021-04-20 12:30:09 +03:00
byte_order_generic_x86.h Fix all warnings given by UBSAN 2021-04-20 12:30:09 +03:00
byte_order_generic_x86_64.h MDEV-21981 Replace arithmetic + with bitwise OR when possible 2020-03-19 15:09:13 +02:00
CMakeLists.txt Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
decimal.h Added typedef decimal_digits_t (uint16) for number of digits in most 2021-05-19 22:27:27 +02:00
dur_prop.h Merge InnoDB 5.7 from mysql-5.7.9. 2016-09-02 13:22:28 +03:00
errmsg.h test cases for MySQL bugs 2022-01-21 16:02:34 +01:00
ft_global.h MDEV-23269 SIGSEGV in ft_boolean_check_syntax_string on setting ft_boolean_syntax 2021-10-11 17:43:23 +04:00
handler_ername.h Merge 10.5 into 10.6 2021-09-16 20:17:12 +03:00
handler_state.h Fix for MDEV-533: Confusing error code when doing auto-increment insert for out-of-range values 2012-09-18 15:14:19 +03:00
hash.h MDEV-26221: DYNAMIC_ARRAY use size_t for sizes 2021-10-19 16:00:26 +03:00
heap.h Added page_range to records_in_range() to improve range statistics 2020-03-27 03:54:45 +02:00
ilist.h fix C++20 !!! build failure: iterator concept was not fully implemented 2021-10-12 23:00:09 +06:00
json_lib.h MDEV-27911: Implement range notation for json path 2022-04-15 01:02:44 +05:30
keycache.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
lf.h MDEV-23510: arm64 lf_hash alignment of pointers 2021-02-25 10:06:15 +11:00
little_endian.h Update FSF address 2019-05-11 19:25:02 +03:00
m_ctype.h MDEV-27743 Remove Lex::charset 2022-03-22 17:12:15 +04:00
m_string.h Simplify a preprocessor condition 2021-05-17 18:10:11 +03:00
ma_dyncol.h MDEV-19897 Rename source code variable names from utf8 to utf8mb3 2019-06-28 12:37:04 +04:00
maria.h cleanup: Aria headers 2020-06-19 19:43:07 +02:00
my_alarm.h Fixes some compiler issues on AIX ( 2022-02-08 14:32:28 +02:00
my_alloc.h Fix clang -Wtypedef-redefinition 2022-03-11 15:33:59 +02:00
my_atomic.h MDEV-17441 fixup: Remove unused my_atomic long macros 2022-03-24 09:53:52 +02:00
my_atomic_wrapper.h Merge 10.5 into 10.6 2021-06-26 11:53:28 +03:00
my_attribute.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
my_base.h MDEV-17554 Auto-create new partition for system versioned tables with history partitioned by INTERVAL/LIMIT 2022-05-06 15:11:02 +03:00
my_bit.h Coding style fixes 2020-04-04 14:55:51 +04:00
my_bitmap.h cleanup: MY_BITMAP mutex 2021-08-26 23:39:52 +02:00
my_byteorder.h MDEV-25870 Windows - fix ARM64 cross-compilation 2021-06-07 23:15:36 +02:00
my_check_opt.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_compare.h Merge 10.4 into 10.5 2021-04-21 09:01:01 +03:00
my_compiler.h MDEV-15250 fixup: Remove MY_GNUC_PREREQ 2022-04-26 15:13:39 +03:00
my_counter.h MDEV-22456 after-merge fix: introduce Atomic_relaxed 2020-05-18 15:02:55 +03:00
my_cpu.h MDEV-25807: ARM build failure due to missing ISB instruction on ARMv6 2021-06-01 13:51:39 +10:00
my_crypt.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_dbug.h Vanilla cleanups and refactorings 2021-10-26 17:07:46 +02:00
my_decimal_limits.h Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
my_default.h MDEV-22214 mariadbd.exe calls function mysqld.exe, and crashes 2020-04-10 19:05:26 +02:00
my_dir.h Revert "MDEV-27036: re-enable my_json_writer-t unit test" 2021-12-07 09:57:51 +01:00
my_getopt.h Added 'const' to arguments in get_one_option and find_typeset() 2021-02-08 12:16:29 +02:00
my_global.h fix clang-cl warnings 2022-02-02 01:35:40 +01:00
my_handler_errors.h Merge branch '10.4' into 10.5 2022-02-01 20:33:04 +01:00
my_libwrap.h Update FSF Address 2019-05-11 21:29:06 +03:00
my_list.h Update FSF Address 2019-05-11 21:29:06 +03:00
my_md5.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_minidump.h MDEV-11499 mysqltest, Windows : improve diagnostics if server fails to shutdown 2021-09-24 11:49:28 +02:00
my_net.h MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_nosys.h Update FSF Address 2019-05-11 21:29:06 +03:00
my_pthread.h Merge 10.5 into 10.6 2021-10-28 09:08:58 +03:00
my_rdtsc.h mysys: my_rdtsc note about ARM counter 2022-01-06 10:36:55 +11:00
my_rnd.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
my_service_manager.h MDEV-10183 implement service_manager_extend_timeout on Windows 2022-04-11 07:49:43 +02:00
my_stack_alloc.h perfschema memory related instrumentation changes 2020-03-10 19:24:22 +01:00
my_stacktrace.h MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
my_sys.h Merge branch '10.7' into 10.8 2022-02-04 14:50:25 +01:00
my_time.h Merge 10.3 into 10.4 2022-04-06 08:59:09 +03:00
my_tree.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
my_uctype.h Update FSF Address 2019-05-11 21:29:06 +03:00
my_user.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
my_valgrind.h Cleanup: Remove IF_VALGRIND 2022-04-25 09:40:40 +03:00
my_xml.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
myisam.h Added page_range to records_in_range() to improve range statistics 2020-03-27 03:54:45 +02:00
myisamchk.h Fixed bug in aria_chk that overwrote sort_buffer_length 2021-09-15 21:21:03 +03:00
myisammrg.h Added page_range to records_in_range() to improve range statistics 2020-03-27 03:54:45 +02:00
myisampack.h Fix all warnings given by UBSAN 2021-04-20 12:30:09 +03:00
mysql.h Vanilla cleanups and refactorings 2021-10-26 17:07:46 +02:00
mysql.h.pp Fix clang -Wtypedef-redefinition 2022-03-11 15:33:59 +02:00
mysql_com.h MDEV-27743 Remove Lex::charset 2022-03-22 17:12:15 +04:00
mysql_com_server.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mysql_embed.h Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
mysql_time.h Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
mysql_version.h.in Merge 10.3 into 10.4 2020-10-29 13:38:38 +02:00
mysqld_default_groups.h Fixed that mariadb-# binaries reads their corresponding entry from my.cnf 2019-07-18 15:32:22 +03:00
mysys_err.h MDEV-7947 strcmp() takes 0.37% in OLTP RO 2020-07-23 10:54:33 +03:00
pack.h Merge branch '10.2' into bb-10.2-connector-c-integ-subm 2016-09-21 12:54:56 +02:00
password.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
pfs_file_provider.h perfschema compilation, test and misc fixes 2020-03-10 19:24:23 +01:00
pfs_idle_provider.h P_S 5.7.28 2020-03-10 19:24:22 +01:00
pfs_memory_provider.h P_S 5.7.28 2020-03-10 19:24:22 +01:00
pfs_metadata_provider.h P_S 5.7.28 2020-03-10 19:24:22 +01:00
pfs_socket_provider.h P_S 5.7.28 2020-03-10 19:24:22 +01:00
pfs_stage_provider.h P_S 5.7.28 2020-03-10 19:24:22 +01:00
pfs_statement_provider.h P_S 5.7.28 2020-03-10 19:24:22 +01:00
pfs_table_provider.h P_S 5.7.28 2020-03-10 19:24:22 +01:00
pfs_thread_provider.h Merge 10.4 into 10.5 2021-08-31 10:04:56 +03:00
pfs_transaction_provider.h cleanup: pass trxid by value 2020-03-10 19:24:23 +01:00
probes_mysql.d.base Update FSF Address 2019-05-11 21:29:06 +03:00
probes_mysql.h Update FSF Address 2019-05-11 21:29:06 +03:00
probes_mysql_nodtrace.h.in Merge branch '5.5' into 10.0 2016-02-15 22:50:59 +01:00
queues.h Merge branch '10.2' into 10.3 2020-05-04 16:47:11 +02:00
rijndael.h Update FSF Address 2019-05-11 21:29:06 +03:00
scope.h MDEV-18543 IMPORT TABLESPACE fails after instant DROP COLUMN 2021-10-26 22:50:58 +06:00
service_versions.h MDEV-12933 sort out the compression library chaos 2021-10-27 15:55:14 +02:00
source_revision.h.in SOURCE_REVISION should always be defined in source_revision.h 2017-11-01 13:20:32 +00:00
span.h span cleanup 2020-05-15 16:25:32 +03:00
sql_common.h MDEV-19275 Provide SQL service to plugins. 2021-10-19 17:35:06 +02:00
ssl_compat.h Merge branch '10.7' into 10.8 2022-02-04 14:50:25 +01:00
sslopt-case.h MDEV-25511: Command line tools don't support CRL parameters 2021-05-31 08:29:37 +02:00
sslopt-longopts.h MDEV-14101 Provide an option to select TLS protocol version 2019-06-17 12:26:25 +02:00
sslopt-vars.h MDEV-14101 Provide an option to select TLS protocol version 2019-06-17 12:26:25 +02:00
t_ctype.h Update FSF Address 2019-05-11 21:29:06 +03:00
thr_alarm.h MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
thr_lock.h MDEV-13115: Implement SELECT SKIP LOCKED 2021-04-08 16:51:36 +10:00
thr_timer.h MDEV-16264 - prerequisite patch, periodic thr_timer 2019-11-15 16:50:22 +01:00
typelib.h Added 'const' to arguments in get_one_option and find_typeset() 2021-02-08 12:16:29 +02:00
violite.h MDEV-25602 get rid of __WIN__ in favor of standard _WIN32 2021-06-06 13:21:03 +02:00
waiting_threads.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
welcome_copyright_notice.h Update FSF Address 2019-05-11 21:29:06 +03:00
wqueue.h Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
wsrep.h Merge 10.5 into 10.6 2022-01-04 09:26:38 +02:00