mirror of
https://github.com/MariaDB/server.git
synced 2025-08-11 21:11:35 +02:00
![]() Global temporary table (GTT) is a table with globally defined metadata, but per-session data. That is, the life duration of this data is limited with session duration. Here we have two options: 1. ON COMMIT DELETE ROWS: a default option. The life duration of data is transaction duration. 2. ON COMMIT PRESERVE ROWS: The life duration of data is session duration. # Implementation The implementation consists of the following fundamental parts. ## Part 1: CREATE TABLE + frm format 1. Store GLOBAL TEMPORARY and ON COMMIT bits in create_info->table_options 2. Store higher word of create_info->table_options in frm header 3. Also disallow ON COMMIT keyword for (local) temporary tables As a result, the bits will be available in share->db_create_options. New Table_type enum element: TABLE_TYPE_GLOBAL_TEMPORARY (datadict.h) ## Part 2: open_table: a local data table is created on demand On open, a session-local temporary table copy is created from a global TABLE_SHARE. Let us refer to the former as "local data table of GTT", and the latter as "global metadata table of GTT". There is a number of cases, when a global metadata table is opened instead, like ALTER, DROP, SHOW CREATE A local data table holds: 1. A reference to that share, and holds the increased tdc reference count. 2. An explicit MDL lock to the duration of local copy's existence. While at least one local data table exists (2) guarantees that ALTER, DROP or RENAME will not happen. (1) guarantees that a global metadata table will not be flushed At an implementation level, a local data table is a temporary table, invisible for a user and augmented with (1) and (2). The reference and lock are released upon dropping this local data table, which happens due to: a) TRUNCATE TABLE b) Connection close c) If ON COMMIT DELETE ROWS is used, then on transaction commit/rollback ## Part 3: ALTER, DROP, RENAME These operations always open a real global temporary table. ALTER, RENAME and DROP TABLE require all local data tables to be destroyed, thus, having no references to a modified/deleted table. For that, they: 1. acquire an EXCLUSIVE MDL lock. To match oracle behavior, lock_wait_timeout is 0 in ALTER TABLE. 2. Check that there is no matching local temporary table in the same connection (which is not guaranteed by 1) ## Part 4 ON COMMIT DELETE ROWS This clause is assumed by default, i.e. it is implicit. When ON COMMIT DELETE ROWS, the local data table is dropped on commit/rollback. On table open, global_temporary_tables handlerton is injected, implementing this behavior. # Limitations The following is forbidden for GTT: system versioning partitioning fk ONLINE ALTER CREATE GLOBAL TEMPORARY under LOCK TABLES FLUSH TABLE on Global temporary table is no-op for now # Refactorings, details 1. Extract drop_tmp_table_share (temporary_tables.cc) 2. Extract THD::open_temporary_table_impl (temporary_tables.cc) 3. information_schema support: x) "GLOBAL TEMPORARY" type is show in information_schema.tables y) an artifical temporary table is hidden from SHOW TABLE STATUS 4. VIEWs are supported. 5. AS SELECT support x) Made in Oracle style, so that the data is only inserted in the session that creates GTT y) ON COMMIT DELETE ROWS inserts the data for real, and then deletes the data table on implicit commit 6. CREATE TABLE ... LIKE is supported. 7. Replication support x) Set share->table_creation_was_logged to 0 to make the table ignored for replication. y) Statements with GTT involved will be logged in Row-based style (RBR) z) Global temporary table creation and alter/drop will be logged. |
||
---|---|---|
.. | ||
atomic | ||
mysql | ||
providers | ||
aligned.h | ||
aria_backup.h | ||
assume_aligned.h | ||
big_endian.h | ||
byte_order_generic.h | ||
byte_order_generic_x86.h | ||
byte_order_generic_x86_64.h | ||
CMakeLists.txt | ||
decimal.h | ||
dur_prop.h | ||
errmsg.h | ||
ft_global.h | ||
handler_ername.h | ||
handler_state.h | ||
hash.h | ||
heap.h | ||
ilist.h | ||
json_lib.h | ||
keycache.h | ||
lf.h | ||
little_endian.h | ||
m_ctype.h | ||
m_string.h | ||
ma_dyncol.h | ||
maria.h | ||
mariadb_capi_rename.h | ||
my_alloc.h | ||
my_alloca.h | ||
my_atomic.h | ||
my_atomic_wrapper.h | ||
my_attribute.h | ||
my_base.h | ||
my_bit.h | ||
my_bitmap.h | ||
my_byteorder.h | ||
my_check_opt.h | ||
my_cmp.h | ||
my_compare.h | ||
my_compiler.h | ||
my_counter.h | ||
my_cpu.h | ||
my_crypt.h | ||
my_dbug.h | ||
my_decimal_limits.h | ||
my_default.h | ||
my_dir.h | ||
my_getopt.h | ||
my_global.h | ||
my_handler_errors.h | ||
my_libwrap.h | ||
my_list.h | ||
my_md5.h | ||
my_minidump.h | ||
my_net.h | ||
my_nosys.h | ||
my_pthread.h | ||
my_rdtsc.h | ||
my_rnd.h | ||
my_service_manager.h | ||
my_stack_alloc.h | ||
my_stacktrace.h | ||
my_sys.h | ||
my_time.h | ||
my_tracker.h | ||
my_tree.h | ||
my_uctype.h | ||
my_user.h | ||
my_valgrind.h | ||
my_virtual_mem.h | ||
my_xml.h | ||
myisam.h | ||
myisamchk.h | ||
myisammrg.h | ||
myisampack.h | ||
mysql.h | ||
mysql_com.h | ||
mysql_com_server.h | ||
mysql_embed.h | ||
mysql_time.h | ||
mysql_version.h.in | ||
mysqld_default_groups.h | ||
mysys_err.h | ||
no_valgrind_without_big.inc | ||
pack.h | ||
password.h | ||
pfs_file_provider.h | ||
pfs_idle_provider.h | ||
pfs_memory_provider.h | ||
pfs_metadata_provider.h | ||
pfs_socket_provider.h | ||
pfs_stage_provider.h | ||
pfs_statement_provider.h | ||
pfs_table_provider.h | ||
pfs_thread_provider.h | ||
pfs_transaction_provider.h | ||
probes_mysql.d.base | ||
probes_mysql.h | ||
probes_mysql_nodtrace.h.in | ||
queues.h | ||
rijndael.h | ||
scope.h | ||
service_versions.h | ||
source_revision.h.in | ||
span.h | ||
sql_common.h | ||
ssl_compat.h | ||
sslopt-case.h | ||
sslopt-longopts.h | ||
sslopt-vars.h | ||
t_ctype.h | ||
thr_lock.h | ||
thr_timer.h | ||
typelib.h | ||
violite.h | ||
waiting_threads.h | ||
welcome_copyright_notice.h | ||
wqueue.h | ||
wsrep.h |