Skip to content
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

Add index and table metrics to vttablet #17570

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

rafer
Copy link
Contributor

@rafer rafer commented Jan 18, 2025

Description

This adds the following metrics to vttablet's schema engine.

  • TableRows (by table) - The estimated number of rows in the table
  • TableClusteredIndexSize (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 index
  • IndexBytes (by index) - The size of the index
metrics sample
curl -sS http://localhost:15100/debug/vars | jq -S '{TableRows, TableClusteredIndexSize, IndexCardinality, IndexBytes}'
{
  "IndexBytes": {
    "corder.PRIMARY": 16384,
    "customer.PRIMARY": 16384,
    "product.PRIMARY": 16384
  },
  "IndexCardinality": {
    "corder.PRIMARY": 0,
    "customer.PRIMARY": 0,
    "product.PRIMARY": 0
  },
  "TableClusteredIndexSize": {
    "corder": 16384,
    "customer": 16384,
    "product": 16384
  },
  "TableRows": {
    "corder": 0,
    "customer": 0,
    "product": 0
  }
}

These values are read from mysql system tables when Engine#Reload is called, and made available via Env#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.

  • 5,000 tables with 6 indexes each (5 secondary indexes)
  • 5 tables with 5,000 partitions each, 4 indexes each (3 secondary indexes)

Results:

  • Entire updateTableIndexMetrics method: 716ms
    • Partitions query: 37ms
    • Table stats query (table row count and clustered index size): 15ms
    • Index bytes query (byte size of each index): 205ms
    • Cardinality query: 427ms

For comparison the InnoDBTableSizes query takes 2.0s for the same test setup.

Related Issue(s)

#17569

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

None

* IndexBytes
* IndexCardinality
* TableClusteredIndexSize
* TableRows

Signed-off-by: Rafer Hazen <[email protected]>
Copy link
Contributor

vitess-bot bot commented Jan 18, 2025

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Jan 18, 2025
@github-actions github-actions bot added this to the v22.0.0 milestone Jan 18, 2025
@rafer rafer added Type: Feature Component: VTTablet and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant