Add index and table metrics to vttablet #17570
Open
+193
−5
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 adds the following metrics to vttablet's schema engine.
TableRows
(by table) - The estimated number of rows in the tableTableClusteredIndexSize
(by table) - The size of the clustered index (i.e. the size of the "row data")IndexCardinality
(by index) - The estimated number of unique values in the indexIndexBytes
(by index) - The size of the indexmetrics sample
These values are read from mysql system tables when
Engine#Reload
is called, and made available viaEnv#Exporter
Partition names
Since mysql implements partitions internally as one table per partition, the "table name" referenced in the stats tables mostly look like
TABLE_NAME#p#PARTITION_NAME
. We want to report statistics per logical table (not per partition) so we need a way to extract the underlying table name. Unfortunately, it's not as simple as splitting the composite name by#p#
, because it's possible to create a table or partition with#p#
as a part of the name.The approach I took here is to load the
information_schema.partitions
table, which includes separate columns for the table and partition name. Then, as we read through the stats tables that contain the composite name, if we encounter a#p#
, we attempt to find a matching table/partition in the loaded list, and, if it is present, we can find the base table name.An alternative method would be to make use of
information_schema.innodb_tables.name
column (like we do here), which provides the table name with special characters encoded. This makes it possible to confidently split on#p#
, because the#
characters would be encoded if they were part of the real table or partition name. I opted for the "loading all partitions" approach instead because the joins required to get an encoded table name made the queries too slow when there are many tables, indexes or partitions.Performance
Since performance of the queries run on
#Reload
has been an issue in the past, I tested the queries added in this PR with the following test setup.Results:
updateTableIndexMetrics
method:716ms
37ms
15ms
205ms
427ms
For comparison the
InnoDBTableSizes
query takes2.0s
for the same test setup.Related Issue(s)
#17569
Checklist
Deployment Notes
None