MDEV-31541: Optimize calls to build_table_filenames for CREATE TABLE - #2696
Open
an3l wants to merge 1 commit into
Open
MDEV-31541: Optimize calls to build_table_filenames for CREATE TABLE#2696an3l wants to merge 1 commit into
an3l wants to merge 1 commit into
Conversation
an3l
force-pushed
the
bb-11.2-anel-MDEV-31541
branch
from
July 15, 2023 09:10
3ef0c36 to
c463508
Compare
- In order to optimize the call of `ha_table_exists()` for `CREATE`
statement that for single statement has 2 paths from
`mysql_create_table(()` that are called sequentually:
- Path 1
```
mysql_create_table
--> open_and_lock_tables
--> open_tables
--> lock_table_names
--> upgrade_lock_if_not_exists
--> ha_table_exists()
--> build_table_filename
```
- Path 2:
```
mysql_create_table
--> mysql_create_table_no_lock
--> build_table_filename
--> create_table_impl
--> ha_table_exists()
```
- We are creating the new members of HA_CREATE_INFO that are updated
after first call of `ha_table_exists()` and used in the place where second
invocation of function was done.
- Handling of case for `CREATE ...SELECT FROM` is added too with early
call of `ha_table_exists` instead from `ha_create`.
- Since `or replace [like]` , `if not exists` and `lock tables`,
have different paths invocation that are different from Path 1, we are
leaving the `ha_table_exists()` call for that cases, without
optimization.
- To optimize `build_table_filename` call is done in Path 1 from
`upgrade_lock_if_not_exists` by saving the path and length, that is
reused in `ha_table_exists()`, while there is special handling for
views that still need to call the function from within
`ha_table_exists()`. Optimization is done by eliminating the call for
Path 2.
- Special cases are `replace` or `if not exists` ddl that do not use
Path 1 but Path2 only, without optimization
- Special case is `CREATE..SELECT` without optimization.
Reviewer: <monty@mariadb.org>
an3l
force-pushed
the
bb-11.2-anel-MDEV-31541
branch
from
March 13, 2024 08:36
c463508 to
1265bce
Compare
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.
ha_table_exists()forCREATEstatement that for single statement has 2 paths frommysql_create_table(()that are called sequentually:sequenceDiagram box create table query participant mysql_create_table as mysql_create_table participant open_and_lock_tables as open&lock tbl participant open_tables as open tbl participant lock_table_names as lock tbl names participant upgrade_lock_if_not_exists as upgrade lock if not exists participant ha_table_exists as ha_table_exists participant mysql_create_table_no_lock as create without lock participant build_table_filename as build tbl filename participant create_table_impl as implicit create end autonumber Note left of mysql_create_table:Query mysql_create_table->>+open_and_lock_tables: open_and_lock_tables->>open_tables: open_tables->>lock_table_names: lock_table_names->>+upgrade_lock_if_not_exists: upgrade_lock_if_not_exists->>+ha_table_exists: Note over upgrade_lock_if_not_exists, ha_table_exists: pdate HA_CREATE_INFO <br>with table_path and table_exists <br> call here <br> build_table_filename ha_table_exists->>+build_table_filename: Optimized activate build_table_filename deactivate build_table_filename build_table_filename-->>ha_table_exists: ha_table_exists-->>-mysql_create_table: Return to caller Note over ha_table_exists, mysql_create_table: Path 1 mysql_create_table->>+mysql_create_table_no_lock: mysql_create_table_no_lock->>+build_table_filename: Optimized Note over mysql_create_table_no_lock, build_table_filename: Use HA_CRETE_INFO struct activate build_table_filename deactivate build_table_filename mysql_create_table_no_lock->>create_table_impl: create_table_impl--xha_table_exists: Optimized (no call) Note over create_table_impl, ha_table_exists: Use HA_CRETE_INFO struct ha_table_exists--x+build_table_filename: Optimized (no call) create_table_impl-->+mysql_create_table: Return to caller Note over create_table_impl, mysql_create_table: Path 2We are creating the new members of HA_CREATE_INFO that are updated after first call of
ha_table_exists()and used in the place where second invocation of function was done.CREATE ...SELECT FROMis added too with early call ofha_table_existsinstead fromha_create.or replace [like],if not existsandlock tables, have different paths invocation that are different from Path 1, we are leaving theha_table_exists()call for that cases, without optimization.To optimize
build_table_filenamecall is done in Path 1 fromupgrade_lock_if_not_existsby saving the path and length, that is reused inha_table_exists(), while there is special handling for views that still need to call the function from withinha_table_exists(). Optimization is done by eliminating the call for Path 2.replaceorif not existsddl that do not use Path 1 but Path2 only, without optimizationCREATE..SELECTwithout optimization.Reviewer: monty@mariadb.org
Description
How can this PR be tested?
I have tested the PR using debug traces and noted optimization of calls for
CREATE TABLEinha_table_exists(), as well asbuild_table_filenames()by comparing the trace files with/without PR.Here is the test case
Basing the PR against the correct MariaDB version
PR quality check