-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MDEV-32286 ANALYZE displays a huge number of InnoDB secondary index pages_accessed #5362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iMineLink
wants to merge
2
commits into
MariaDB:10.11
Choose a base branch
from
iMineLink:MDEV-32286
base: 10.11
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
mysql-test/suite/innodb/r/non_covering_sec_idx_scan.result
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| create table t1 ( | ||
| pk int not null primary key, | ||
| domain_grp int, | ||
| val int | ||
| ) engine=innodb; | ||
| insert into t1 select seq, mod(seq,10), seq from seq_1_to_10000; | ||
| create index domain_idx on t1(domain_grp); | ||
| analyze table t1 persistent for all; | ||
| Table Op Msg_type Msg_text | ||
| test.t1 analyze status Engine-independent statistics collected | ||
| test.t1 analyze status OK | ||
| set @js='$out_scan'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_FULL_SCAN; | ||
| PAGES_ACCESSED_FULL_SCAN | ||
| 23 | ||
| set @js='$out_idx'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_SEC_INDEX; | ||
| PAGES_ACCESSED_SEC_INDEX | ||
| 1046 | ||
| drop table t1; | ||
| create table t2 ( | ||
| pk varchar(500) not null primary key, | ||
| domain_grp int, | ||
| val int | ||
| ) engine=innodb; | ||
| insert into t2 select lpad(seq,500,'0'), mod(seq,4), seq from seq_1_to_20000; | ||
| create index domain_idx on t2(domain_grp); | ||
| analyze table t2 persistent for all; | ||
| Table Op Msg_type Msg_text | ||
| test.t2 analyze status Engine-independent statistics collected | ||
| test.t2 analyze status OK | ||
| select stat_value into @size from mysql.innodb_index_stats | ||
| where database_name='test' and table_name='t2' and index_name='PRIMARY' | ||
| and stat_name='size'; | ||
| select stat_value into @leaf from mysql.innodb_index_stats | ||
| where database_name='test' and table_name='t2' and index_name='PRIMARY' | ||
| and stat_name='n_leaf_pages'; | ||
| select @size as TOTAL_PAGES, @leaf as LEAF_PAGES, (@size - @leaf) as NON_LEAF_PAGES; | ||
| TOTAL_PAGES LEAF_PAGES NON_LEAF_PAGES | ||
| 761 715 46 | ||
| select (@size - @leaf) > 1 as THREE_LEVEL_TREE; | ||
| THREE_LEVEL_TREE | ||
| 1 | ||
| set @js='$out_scan2'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_FULL_SCAN_3LEVEL; | ||
| PAGES_ACCESSED_FULL_SCAN_3LEVEL | ||
| 717 | ||
| set @js='$out_idx2'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_SEC_INDEX_3LEVEL; | ||
| PAGES_ACCESSED_SEC_INDEX_3LEVEL | ||
| 7309 | ||
| drop table t2; | ||
| create table t3 ( | ||
| pk int not null primary key, | ||
| k int, | ||
| val int | ||
| ) engine=innodb; | ||
| insert into t3 select seq, mod(seq*997+13,10007), seq from seq_1_to_10000; | ||
| create index k_idx on t3(k); | ||
| analyze table t3 persistent for all; | ||
| Table Op Msg_type Msg_text | ||
| test.t3 analyze status Engine-independent statistics collected | ||
| test.t3 analyze status OK | ||
| set @js='$out_uncorr'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_UNCORRELATED; | ||
| PAGES_ACCESSED_UNCORRELATED | ||
| 20012 | ||
| drop table t3; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| --innodb-page-size=16k | ||
| --innodb-buffer-pool-size=64M | ||
| --innodb-default-row-format=dynamic | ||
| --loose-innodb-adaptive-hash-index=0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # | ||
| # MDEV-32286 ANALYZE displays a huge number of InnoDB secondary index pages_accessed | ||
| # | ||
| # The .result records raw pages_accessed values, so the .opt pins every | ||
| # server option they depend on: page size and row format (tree shape), | ||
| # buffer pool size (the whole working set must stay resident, so that no | ||
| # access path depends on eviction timing), and the adaptive hash index | ||
| # (its hash guesses skip descent pages). | ||
| --source include/have_innodb.inc | ||
| --source include/have_sequence.inc | ||
|
|
||
| create table t1 ( | ||
| pk int not null primary key, | ||
| domain_grp int, | ||
| val int | ||
| ) engine=innodb; | ||
|
|
||
| insert into t1 select seq, mod(seq,10), seq from seq_1_to_10000; | ||
|
|
||
| create index domain_idx on t1(domain_grp); | ||
|
|
||
| analyze table t1 persistent for all; | ||
|
|
||
| # "val" is outside domain_idx, so each matching row needs a clustered-index | ||
| # lookup either way. | ||
| let $out_scan=`analyze format=json select sql_no_cache val from t1 ignore index(domain_idx) where domain_grp=3`; | ||
| evalp set @js='$out_scan'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_FULL_SCAN; | ||
|
|
||
| # ~1000 rows share key 3 | ||
| let $out_idx=`analyze format=json select sql_no_cache val from t1 force index(domain_idx) where domain_grp=3`; | ||
| evalp set @js='$out_idx'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_SEC_INDEX; | ||
|
|
||
| drop table t1; | ||
|
|
||
| # Wide primary key: the clustered index needs a 3-level tree. | ||
| create table t2 ( | ||
| pk varchar(500) not null primary key, | ||
| domain_grp int, | ||
| val int | ||
| ) engine=innodb; | ||
|
|
||
| insert into t2 select lpad(seq,500,'0'), mod(seq,4), seq from seq_1_to_20000; | ||
|
|
||
| create index domain_idx on t2(domain_grp); | ||
|
|
||
| analyze table t2 persistent for all; | ||
|
|
||
| # more than one non-leaf page implies an internal level below the root | ||
| select stat_value into @size from mysql.innodb_index_stats | ||
| where database_name='test' and table_name='t2' and index_name='PRIMARY' | ||
| and stat_name='size'; | ||
| select stat_value into @leaf from mysql.innodb_index_stats | ||
| where database_name='test' and table_name='t2' and index_name='PRIMARY' | ||
| and stat_name='n_leaf_pages'; | ||
| select @size as TOTAL_PAGES, @leaf as LEAF_PAGES, (@size - @leaf) as NON_LEAF_PAGES; | ||
| select (@size - @leaf) > 1 as THREE_LEVEL_TREE; | ||
|
|
||
| let $out_scan2=`analyze format=json select sql_no_cache val from t2 ignore index(domain_idx) where domain_grp=3`; | ||
| evalp set @js='$out_scan2'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_FULL_SCAN_3LEVEL; | ||
|
|
||
| # ~5000 rows share key 3 | ||
| let $out_idx2=`analyze format=json select sql_no_cache val from t2 force index(domain_idx) where domain_grp=3`; | ||
| evalp set @js='$out_idx2'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_SEC_INDEX_3LEVEL; | ||
|
|
||
| drop table t2; | ||
|
|
||
| # Secondary index decorrelated from clustered key order: the clustered-leaf | ||
| # hint must give up instead of paying a wasted probe on every row. | ||
| create table t3 ( | ||
| pk int not null primary key, | ||
| k int, | ||
| val int | ||
| ) engine=innodb; | ||
|
|
||
| insert into t3 select seq, mod(seq*997+13,10007), seq from seq_1_to_10000; | ||
|
|
||
| create index k_idx on t3(k); | ||
|
|
||
| analyze table t3 persistent for all; | ||
|
|
||
| let $out_uncorr=`analyze format=json select sql_no_cache val from t3 force index(k_idx) where k between 0 and 10006`; | ||
| evalp set @js='$out_uncorr'; | ||
| set @out=(select json_extract(@js,'$**.r_engine_stats.pages_accessed')); | ||
| select cast(json_extract(@out,'$[0]') as DOUBLE) as PAGES_ACCESSED_UNCORRELATED; | ||
|
|
||
| drop table t3; | ||
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.