Collect catalog and statistics observations - #5
Merged
Conversation
Adds the seven catalog queries the profile is built from: relation row and size estimates, columns with their types, per-column statistics, extended statistics, foreign keys and indexes. None of them reads a user table; row counts come from pg_class.reltuples and distributions from pg_stats as PostgreSQL already computed them. Partitioned and inherited tables are rejected before the remaining queries run. A partitioned parent's reltuples is not the sum of its children, so a fan-out estimate derived from one would be silently wrong -- worse than refusing to produce a profile. Raw statistic values land in collector-local dataclasses that are never serialized. Tokenization and normalization map them onto the contract types in later changes. pg_inherits joins the --check-safety relation allowlist alongside the collector that reads it. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
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.
Task 5 of the MVP plan.
Adds the seven catalog queries the profile is built from — relation row and size estimates, columns with their types, per-column statistics, extended statistics, foreign keys, indexes. None reads a user table: row counts come from
pg_class.reltuples, distributions frompg_statsas PostgreSQL already computed them.Rejects unsupported layouts early. Partitioned and inherited tables abort after the first two queries, before the other five run. A partitioned parent's
reltuplesis not the sum of its children, so a fan-out derived from one is silently wrong — worse than refusing.Raw values never reach a serialized type. The collector dataclasses hold PostgreSQL's own encodings, including raw MCVs and histogram bounds, and none of them is written. Tokenization and normalization map them onto the contract types in later tasks.
parse_pg_arrayis a real parser. PostgreSQL quotes and backslash-escapes elements containing punctuation; asplit(",")would corrupt exactly the values that matter most, silently.Type support is an allowlist. Anything not enumerated is reported unsupported. A false negative costs an investigation; a false positive costs a failed cutover.
pg_inheritsjoins the--check-safetyrelation allowlist alongside the collector that reads it, per the house rule.Verification: 157 tests pass,
--check-safetyclean over 9 SQL constants,ruff checkclean, 3.9 grammar verified.