Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Bug 22988461 - INCORRECT CALCULATION FOR PAGES_HASHED, PAGES_OLD
Browse files Browse the repository at this point in the history
The views:

   * innodb_buffer_stats_by_schema
   * innodb_buffer_stats_by_table

used COUNT(IF(...), 1, 0) to sum up the number of hashed and old pages.
However COUNT(0) will increment the counter, so the counts have been changed
to COUNT(IF(...), 1, NULL) as NULL will not increment the counter. This solution
is preferred over SUM(IF(...), 1, 0) as SUM returns a decimal instead of an
integer.

Also added test cases to ensure the percentage of old pages found is less
than @@global.innodb_old_blocks_pct as a check that not all pages are included
in the count.
  • Loading branch information
JesperWisborgKrogh committed May 19, 2016
1 parent e4fec21 commit 924323a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ pages_hashed bigint(21) NO 0
pages_old bigint(21) NO 0
rows_cached decimal(44,0) NO 0
SELECT * FROM sys.x$innodb_buffer_stats_by_schema;
SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.innodb_buffer_stats_by_schema;
OldPagesSmallEnough
1
SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.x$innodb_buffer_stats_by_schema;
OldPagesSmallEnough
1
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ pages_hashed bigint(21) NO 0
pages_old bigint(21) NO 0
rows_cached decimal(44,0) NO 0
SELECT * FROM sys.x$innodb_buffer_stats_by_table;
SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.innodb_buffer_stats_by_table;
OldPagesSmallEnough
1
SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.x$innodb_buffer_stats_by_table;
OldPagesSmallEnough
1
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ DESC sys.x$innodb_buffer_stats_by_schema;
SELECT * FROM sys.x$innodb_buffer_stats_by_schema;
--enable_result_log


# Check that the old pages percentage is smaller than @@global.innodb_old_blocks_pct
# Add 3 percent to avoid false positives due to rounding errors
SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.innodb_buffer_stats_by_schema;

SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.x$innodb_buffer_stats_by_schema;
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ DESC sys.x$innodb_buffer_stats_by_table;
SELECT * FROM sys.x$innodb_buffer_stats_by_table;
--enable_result_log


# Check that the old pages percentage is smaller than @@global.innodb_old_blocks_pct
# Add 3 percent to avoid false positives due to rounding errors
SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.innodb_buffer_stats_by_table;

SELECT (SUM(pages_old)/sum(pages)*100 < (@@global.innodb_old_blocks_pct + 3)) AS OldPagesSmallEnough
FROM sys.x$innodb_buffer_stats_by_table;
4 changes: 2 additions & 2 deletions views/i_s/innodb_buffer_stats_by_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_IN
sys.format_bytes(SUM(IF(ibp.compressed_size = 0, 16384, compressed_size))) AS allocated,
sys.format_bytes(SUM(ibp.data_size)) AS data,
COUNT(ibp.page_number) AS pages,
COUNT(IF(ibp.is_hashed = 'YES', 1, 0)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, 0)) AS pages_old,
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
ROUND(SUM(ibp.number_records)/COUNT(DISTINCT ibp.index_name)) AS rows_cached
FROM information_schema.innodb_buffer_page ibp
WHERE table_name IS NOT NULL
Expand Down
4 changes: 2 additions & 2 deletions views/i_s/innodb_buffer_stats_by_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_IN
sys.format_bytes(SUM(IF(ibp.compressed_size = 0, 16384, compressed_size))) AS allocated,
sys.format_bytes(SUM(ibp.data_size)) AS data,
COUNT(ibp.page_number) AS pages,
COUNT(IF(ibp.is_hashed = 'YES', 1, 0)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, 0)) AS pages_old,
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
ROUND(SUM(ibp.number_records)/COUNT(DISTINCT ibp.index_name)) AS rows_cached
FROM information_schema.innodb_buffer_page ibp
WHERE table_name IS NOT NULL
Expand Down
4 changes: 2 additions & 2 deletions views/i_s/x_innodb_buffer_stats_by_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_IN
SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) AS allocated,
SUM(ibp.data_size) AS data,
COUNT(ibp.page_number) AS pages,
COUNT(IF(ibp.is_hashed = 'YES', 1, 0)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, 0)) AS pages_old,
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
ROUND(IFNULL(SUM(ibp.number_records)/NULLIF(COUNT(DISTINCT ibp.index_name), 0), 0)) AS rows_cached
FROM information_schema.innodb_buffer_page ibp
WHERE table_name IS NOT NULL
Expand Down
4 changes: 2 additions & 2 deletions views/i_s/x_innodb_buffer_stats_by_table.sql
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ SELECT IF(LOCATE('.', ibp.table_name) = 0, 'InnoDB System', REPLACE(SUBSTRING_IN
SUM(IF(ibp.compressed_size = 0, 16384, compressed_size)) AS allocated,
SUM(ibp.data_size) AS data,
COUNT(ibp.page_number) AS pages,
COUNT(IF(ibp.is_hashed = 'YES', 1, 0)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, 0)) AS pages_old,
COUNT(IF(ibp.is_hashed = 'YES', 1, NULL)) AS pages_hashed,
COUNT(IF(ibp.is_old = 'YES', 1, NULL)) AS pages_old,
ROUND(IFNULL(SUM(ibp.number_records)/NULLIF(COUNT(DISTINCT ibp.index_name), 0), 0)) AS rows_cached
FROM information_schema.innodb_buffer_page ibp
WHERE table_name IS NOT NULL
Expand Down

0 comments on commit 924323a

Please sign in to comment.