MDEV-40388 Optimizer context records unusable DDL for SEQUENCE tables#5432
Closed
LukeYL026 wants to merge 1 commit into
Closed
MDEV-40388 Optimizer context records unusable DDL for SEQUENCE tables#5432LukeYL026 wants to merge 1 commit into
LukeYL026 wants to merge 1 commit into
Conversation
With optimizer_record_context enabled, the optimizer trace records a CREATE TABLE statement for every base table a query references, so an Optimizer Context Replay server (MDEV-39368) can rebuild the query's context. For SEQUENCE-engine helper tables (seq_<from>_to_<to>[_step_<step>]) this recorded a CREATE TABLE ... ENGINE=SEQUENCE that can never be replayed: the SEQUENCE engine discovers such tables from their name alone and ha_seq::create() rejects CREATE TABLE, so replay fails with "Table '...' already exists". Add a handlerton capability flag HTON_TABLE_EXISTS_BY_NAME that an engine sets to declare that its tables are discovered from the table name alone and cannot be created with an explicit CREATE TABLE. The SEQUENCE storage engine sets it in init(). is_base_table() in opt_trace_ddl_info.cc skips tables whose engine has the flag, so their DDL is not recorded. The flag uses a previously unused bit and defaults to 0 (handlertons are zero-filled), so no other engine is affected. PERFORMANCE_SCHEMA tables remain excluded earlier by the table-category check. Test main.opt_trace_store_ddls_sequence: a query over a sequence table records no DDL, and a join of a regular table with a sequence table records only the regular table's DDL. All new code of the whole pull request, including one or several files that are either new files or modified ones, are contributed under the BSD-new license. I am contributing on behalf of my employer Amazon Web Services, Inc.
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Author
|
Closing this PR - PR 5427 is a simpler fix for the issue that takes advantage of the fact that we already have a means of identifying sequence tables, and can avoid the introduction of flags in my draft. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This is a draft PR including MTR regression test and example of adding flag to identify sequence tables, in case it may be of use.
With
optimizer_record_contextenabled, the optimizer trace records aCREATE TABLEstatement for every base table referenced by aSELECT/INSERT/DELETE/UPDATE query, so that an Optimizer Context Replay server
(MDEV-39368) can recreate the query's context. The recording code emitted a
CREATE TABLE ... ENGINE=SEQUENCEfor the auto-generated SEQUENCE-enginehelper tables (
seq_<from>_to_<to>[_step_<step>]).Replaying that DDL fails:
The SEQUENCE engine discovers such tables purely from their name pattern — the
table exists the moment it is referenced and can never be created with an
explicit
CREATE TABLE(ha_seq::create()returnsHA_ERR_WRONG_COMMAND), sothe recorded DDL is unusable on replay.
Root cause
is_base_table()insql/opt_trace_ddl_info.ccrecords the DDL of every tablein the
TABLE_CATEGORY_USERcategory. It did not exclude engines that determinea table's existence from its name alone, so SEQUENCE tables were treated like
ordinary base tables and their (unusable) DDL was recorded.
Fix
sql/handler.h: add a handlerton capability flagHTON_TABLE_EXISTS_BY_NAME (1 << 4). An engine sets it to declare that itstables are discovered from the table name alone and cannot be created with an
explicit
CREATE TABLE.storage/sequence/sequence.cc: the SEQUENCE storage engine setsHTON_TABLE_EXISTS_BY_NAMEin itsinit().sql/opt_trace_ddl_info.cc:is_base_table()now also returnsfalsewhenthe table's engine has
HTON_TABLE_EXISTS_BY_NAMEset, so no DDL is recordedfor such tables. All other base tables (InnoDB, MyISAM, views, ...) are
unaffected.
Using a declared handlerton flag (rather than inferring the property from the
engine's
discover_table_existencehook) states the intent explicitly and isopt-in: only engines that set the flag are skipped. The flag occupies a
previously unused bit and defaults to 0 (handlertons are zero-filled at
allocation), so no other engine's behaviour changes.
PERFORMANCE_SCHEMAtablesremain excluded earlier in
is_base_table()by the table-category check.How this PR Can Be Tested
New MTR test
main.opt_trace_store_ddls_sequence:seq_15_to_1_step_12345records no DDL (thelist_ddlsarray isempty).
t1withseq_1_to_10records the DDL fort1only, confirming normal tables are still captured while the sequencetable is skipped.
Verification performed on a Debug build of
main:main.opt_trace_store_ddls_sequencefails — the trace recordsCREATE TABLE ... ENGINE=SEQUENCEfor bothseq_15_to_1_step_12345andseq_1_to_10, matching the JIRA report.main.opt_trace_store_ddls_sequencepasses.main.opt_trace_store_ddls(pre-existing),sequence.simple, andsequence.group_byall pass.Basing the PR against the correct MariaDB version
Based on
main. The optimizer-context-recording feature (opt_trace_ddl_info.cc,optimizer_record_context) is not present in any released LTS (10.6, 10.11,11.4, 11.8); it lives only on
main, so there is no older affected branch tobase on.
Release Notes
The optimizer context (
optimizer_record_context) no longer records anunusable
CREATE TABLE ... ENGINE=SEQUENCEstatement for auto-generatedSEQUENCE tables, so recorded contexts referencing sequence tables can be
replayed.
All new code of the whole pull request, including one or several files that are
either new files or modified ones, are contributed under the BSD-new license. I
am contributing on behalf of my employer Amazon Web Services, Inc.