Repository navigation
Plan the store table health reads for the rows the store has (#9224) - #9231
Conversation
…alog (#9224) The chunk catalog's relid column exists only from TimescaleDB 2.29, so the read failed with 42703 on older stores. Core inheritance names the same chunks on every version. The per-index estimate test now counts the rows the estimate produces.
| JOIN pg_catalog.pg_class AS pc ON pc.relnamespace = pn.oid AND pc.relname = ch.chunk_name | ||
| /* Chunk membership from core inheritance, not timescaledb_information.chunks: that view joins every chunk to its dimension | ||
| slices and to all of pg_class, and its row count is estimated far too low, which let the planner pick the wrong join order | ||
| (#9224). No _timescaledb_catalog column is named: TimescaleDB 2.29 rebuilt the chunk catalog, so a column of it exists on |
There was a problem hiding this comment.
This comment is wrong as written, and so is the matching PR-body sentence ("The statement names no TimescaleDB catalog column"). Four lines up (L557–558) this same CTE reads _timescaledb_catalog.compression_settings and names cs.relid and cs.compress_relid. TimescaleMemberArms names them again at L576–577. What is true is narrower: no column of the chunk catalog (_timescaledb_catalog.chunk) is named, and that is the catalog 2.29 rebuilt.
This matters because the comment is the record of the version-compatibility guarantee. If a future TimescaleDB reshapes compression_settings the way 2.29 reshaped chunk, the next reader will believe this statement is immune. Suggested wording: "No column of _timescaledb_catalog.chunk is named (2.29 rebuilt that catalog). The compression_settings.relid / compress_relid reads below predate this change and are the remaining catalog dependency." Please make the same correction in the PR body.
|
Non-blocking note, a narrow race in the presized per-index read. Before this PR, the |
There was a problem hiding this comment.
Verdict: CHANGES REQUESTED
Claims
- VERIFIED — The member list has one arm for non-partitioned roots and one that walks only partitioned roots; same rows —
DarlingStoreTableHealthReader.cs:616-626. Therelkind <> 'p'arm keepskind='table',grouped=false. The'p'arm keeps'partitioned',grouped=true, leaves only. This matches the old LATERAL UNION. - VERIFIED — Chunk list comes from
pg_inheritsjoined topg_class, skipping foreign-table chunks —DarlingStoreTableHealthReader.cs:566-568(inh.inhparent = t.rel_oid,pc.relkind <> 'f'). Continuous-aggregate materializations are still walked becauseroot_rels(L547-551) carries thecontinuous_aggregatesarm. - VERIFIED — The size lists are joined as
oid = value::oid—DarlingStoreTableHealthReader.cs:709,:995,:996. - VERIFIED —
PgIndexBloatCollector.BuildQueryTexttakes a size expression and a filter, and the collector's own text is unchanged —PgIndexBloatCollector.cs:181passespg_catalog.pg_relation_size(c.oid)andstring.Emptyinto the same positions (L204, L220). The only other braces in the interpolated body are those two placeholders.const→static readonlyhas no const-context callers (PgIndexBloatCollector.cs:385,PgStatsLookupRowsLiveTests.cs:160-161,DarlingStoreTableHealthReader.cs:959). - VERIFIED — The store read keeps the estimate to the indexes it sized, takes the size column from its own list, and runs no second size function —
DarlingStoreTableHealthReader.cs:953-959(0::bigintplusc.oid::bigint = ANY($1)) and:985(est_index_bytesfromzi.bytes). The caller passesIndexRelationsSqloids as$1(:1786-1789). - VERIFIED — The Viewer's Store Health tab reads through the same reader —
PerformanceMonitor.Darling.Viewer/StoreHealthTab.xaml.csreferencesDarlingStoreTableHealthReader. - VERIFIED — Lite's store health shares no SQL — no file under
Lite/referencesTableHealthor this reader. - VERIFIED — No new test pins SQL text — both tests in
DarlingStoreTableHealthCatalogReadsLiveTests.csassert row counts from execution and EXPLAIN plans, not source text. - UNVERIFIED — The measurement table (6.4 s→0.7 s, 106 billion→21 thousand planned rows, 4.49M→10.6k) — needs a live seeded store.
- UNVERIFIED — On a 3,000-chunk store the old and new relation lists are equal under two-way
EXCEPT— needs a live store. - UNVERIFIED — Test 1 fails on the old member list ("planned 424196 rows, listed 1095") — needs a live run against the reverted SQL.
- UNVERIFIED — Test 2 fails with the filter reverted ("1333 rows for 689 indexes") — needs a live run. The mechanism is sound: the temp table's indexes are btree and are not excluded by the estimate's
nspnamefilter, whileplain_rootsdropsrelpersistence = 't'(:611). - UNVERIFIED — The statement returns dev's rows on TimescaleDB 2.28.1 — needs a 2.28.1 cluster.
- UNVERIFIED — Gate totals and the classes-run counts — needs CI or a local run.
- UNVERIFIED — The tiered-storage (OSM) chunk is a foreign table that
timescaledb_information.chunksskipped — needs the view definition on an OSM-enabled install. - REFUTED — "The statement names no TimescaleDB catalog column" (body), echoed in the code comment at
DarlingStoreTableHealthReader.cs:561— the same CTE reads_timescaledb_catalog.compression_settingsand namescs.relidandcs.compress_relid(:557-558), as doTimescaleMemberArmsat:576-577. Only the chunk catalog is no longer named. The version-compatibility guarantee the comment records is narrower than it says. See the inline comment.
Riskiest lines
Darling/PerformanceMonitor.Darling.Storage/DarlingStoreTableHealthReader.cs:567— chunk membership now comes frompg_inherits. A wrong parent (or a compressed-chunk table counted here as well as in the compressed arm) changesChunkCountand sizes — covered byDarlingStoreTableHealthLiveTests.HypertableChunks_RollUpToOneRow_WithTheChunkCount(assertsChunkCount == 3) andManySmallChunks_AndAFewLargeOnes_ReadTheSameAsTheCollectorAndTheSizeFunctions(compressed chunks, sizes against the size functions)Darling/PerformanceMonitor.Darling.Storage/DarlingStoreTableHealthReader.cs:954— the estimate filter. Too wide restores the old cost; too narrow silently drops estimates — covered byDarlingStoreTableHealthCatalogReadsLiveTests.ThePerIndexEstimate_IsKeptToTheIndexesTheReadWasHandedIn(too wide) andDarlingStoreTableHealthLiveTests.AnEstimatedIndexRow_ReadsABasisEqualToItsSize_ForOneIndexAndForARolledUpOne(too narrow:EstimateIndexesUsable1 and 2)Darling/PerformanceMonitor.Darling.Storage/DarlingStoreTableHealthReader.cs:985—est_index_bytesnow comes fromzi.bytes, not the estimate's own size. A wrong join or the0::bigintleaking through would zero the basis — covered byDarlingStoreTableHealthLiveTests.AnEstimatedIndexRow_ReadsABasisEqualToItsSize_ForOneIndexAndForARolledUpOne(EstimatedBasisBytes == Bytes, non-null)
Traps near this diff
- "
chunk_compression_statsreturns ZERO rows for a hypertable whose compression is off, so a chunk count over it reads 0 (#3610 …). Count chunks fromtimescaledb_information.chunks." — does not apply — the PR moves off the chunks view, but ontopg_inherits(DarlingStoreTableHealthReader.cs:567), which lists every chunk whether or not it is compressed. It does not usechunk_compression_stats. - "
timescaledb_information.hypertablesnever lists a continuous aggregate's materialization … Enumeratecontinuous_aggregates…" — does not apply —targetsstill unionscontinuous_aggregates(:543-545), andchunk_relswalksroot_rels(:566), which includes the materialization. - "
pg_relation_sizeis the heap alone; TOAST and indexes live elsewhere …" — does not apply —zi.bytes(:985) ispg_relation_sizeof the index itself (IndexSizesSql,:1516-1518), the same function the estimate used before. - "Lite and Darling ship in parity (CONTRIBUTING's two-store rule) …" — does not apply — Lite has no PostgreSQL store-health reader (no
TableHealthreference underLite/). The sharedPgIndexBloatCollector.QueryTextis byte-identical (PgIndexBloatCollector.cs:181). - "Ruling (#5833): tests are load-bearing. … never answer a trap with a test that reads source text or asserts how code is spelled …" — does not apply — the new tests assert executed and planned row counts (
DarlingStoreTableHealthCatalogReadsLiveTests.cs:116,174), not SQL text. - "
InternalsVisibleToon PerformanceMonitor.Analysis names Lite.Tests only — a helper Darling.Tests must call has to be public (#3688)." — does not apply — the newlyinternalIndexRelationsSqlis in Darling.Storage, whose csproj namesDarling.Tests(PerformanceMonitor.Darling.Storage.csproj:45).
Divergence (blind read vs PR body)
- The body (and the code comment at
:561) says the statement names no TimescaleDB catalog column. It still reads_timescaledb_catalog.compression_settings.relidandcompress_relid(:557-558,:576-577). The accurate claim is "no chunk-catalog column". - The body does not mention one behaviour change from the estimate filter: an index created between the oid list read and the per-index statement used to get an estimate (basis 0) and now reads
NoEstimateRowReason. This is minor and consistent with the documented "created after this read counts as empty" (:1539). See the top-level comment.
Reviewer checklist
- Run
DarlingStoreTableHealthCatalogReadsLiveTestsagainst the reverted member list and the reverted filter, to confirm both fail as the body says. - On a TimescaleDB store with tiered storage (OSM), confirm the old chunks view did skip the foreign-table chunk, so
relkind <> 'f'keeps the rows unchanged. - Re-run the store-health reads on 2.28.x and on the current version (2.32.1) and compare rows against dev.
The chunk list comment said no catalog column was named. The compression_settings reads in that statement and in TimescaleMemberArms name relid and compress_relid, so the comment now says those columns are still named and that no column of the chunk catalog is. Comment only.
There was a problem hiding this comment.
Verdict: LGTM
Claims
- VERIFIED — The comment now says the compression_settings reads (relid, compress_relid) are the catalog columns still named, here and in TimescaleMemberArms — DarlingStoreTableHealthReader.cs:557 (EXISTS on cs.relid / cs.compress_relid) and :578 (join on cs.relid in TimescaleMemberArms).
- UNVERIFIED — Those columns exist on TimescaleDB 2.28.1 and 2.29+ — needs a live read against both versions.
Riskiest lines
- Darling/PerformanceMonitor.Darling.Storage/DarlingStoreTableHealthReader.cs:561 — the only changed lines are inside a SQL block comment, so there is no behaviour change — UNCOVERED (nothing to cover)
- DarlingStoreTableHealthReader.cs:562 — the comment text sits inside a C# verbatim string, so a stray
"would break compilation; the new text has none — UNCOVERED (a build would catch it) - DarlingStoreTableHealthReader.cs:564 — the comment closes with
*/and no nested/*was added — UNCOVERED (nothing to cover)
Traps near this diff
- None applied: the range changes comment text only, so I did not check it against individual traps in .github/REVIEW-TRAPS.md.
Divergence (blind read vs PR body)
None. The follow-up range is a comment-only edit, and it matches the code at :557 and :578. I did not re-grade the PR body's claims about earlier commits.
Reviewer checklist
- Confirm that
_timescaledb_catalog.compression_settings(relid, compress_relid)exists on both 2.28.1 and 2.29+, since the comment asserts it.
Superseded by claude[bot]'s LGTM on 9925e7e: #9231 (review)
Claude posting for Erik Darling.
Fixes #9224
Cause
On a store with thousands of chunks the planner estimated millions of rows for the list of store relations, so every join and sort above it was planned for that many rows. The per-table statement hashed the joined rows into 2048 batches and spilled to temp files for a set that really holds a few thousand rows. Two things made the estimate wrong:
pg_partition_treein a lateral join over every table root. A set-returning function is estimated at 1000 rows per call, so the list was about 1000 times the number of roots, even though only partitioned roots have a tree.timescaledb_information.chunksview, which is estimated at one row.The per-index statement also spliced in the collector's estimate over every btree index in the database, and that estimate called
pg_relation_sizeon each index a second time, after the read had already sized them.Fix
pg_inherits(the hypertable root is the parent, the chunk is the child) joined topg_class, and skips foreign-table chunks, which are the tiered-storage chunks the view skipped. The statement names no column of the chunk catalog. The compression_settings reads (relid, compress_relid) are the catalog columns still named, and both exist on 2.28.1 and on 2.29 and later. TimescaleDB 2.29 rebuilt its chunk catalog (relidis new,table_nameandschema_nameare gone), so any join on that catalog fails with 42703 on one side of that version. Core inheritance gives the same chunks on every version, with no version check. A chunk dropped by retention has no relation and no inheritance row, as before.oid = value::oid, so the planner uses the catalog's statistics.PgIndexBloatCollector.BuildQueryText) takes a size expression and a filter. The collector's own text is unchanged. The store read keeps the estimate to the indexes it sized, and takes the estimate's size column from its own list. No size function runs a second time.Measured on a seeded test store
About 4,000 chunks over 40 hypertables (half compressed), about 29,000 catalog relations and 16,000 indexes. Same sizes passed to old and new statements. Timings are noisy because other work ran on the machine, so each pair below ran back to back.
Chunk list on a second store of 3,000 chunks over 20 hypertables and 17,000 catalog relations: the relation list returns 13,560 oids both ways, the old and new text compared with
EXCEPTin each direction are both empty, and it plans for about 10,000 rows either way. Execution is 78 to 86 ms with the view and 57 ms withpg_inherits.Rows: the per-table read returns 44 rows and the per-index read 2101 rows. Both sets compared with
EXCEPTin each direction are empty. The two relation lists return the same oids. The per-index read's buffer count did not fall: its time was the second set of size calls, and the remaining time is the per-columnpg_statslookups the estimate does by design.Not changed: the size statements (
SELECT s.rel_oid ..., run on up to four connections) already size each relation once. Their time is the file stat per relation. I did not reproduce a 3.6 sWITH targetsstatement on the test store as a member listing (it ran in about 0.1 s). The per-table read was the slow one that starts that way.Tests
DarlingStoreTableHealthCatalogReadsLiveTestshas two tests. The first seeds 150 tables with indexes, a hypertable with chunks and a partitioned table, and compares the index relation list's planned rows with the rows it returns. On the old member list it fails with "planned 424196 rows, listed 1095". The second adds a temporary table with 600 indexes the read does not list, hands the per-index read its sizes, and counts the rows the estimate produces withEXPLAIN ANALYZE. The estimate must produce no more rows than there are indexes handed in. With the estimate filter reverted it fails with "1333 rows for 689 indexes handed in", and it passes with the filter. The planned row count of the whole statement did not tell the two apart on a small store, so the test counts produced rows instead.pg_relation_sizea second time, and no test can see that: nothing differs but the number of file stats.table_nameand norelid. The version on dev now (2.32.1) runs through the live classes below.*DarlingStoreTableHealth*(49),*TableHealth*(49),*IndexBloat*(79) and*StoreHealth*(70), all with 0 failed, plus the earlier*PgStatsLookupRows*,*StoreIndexEstimateReason*,*StoreVacuumStalled*and Lite*PgIndexBloat*runs. No test pins SQL text.DarlingStoreTableHealthReader, so it gets the same change. Lite's store health is its own DuckDB read and shares no SQL, so it has no change.Gate
Pushed on green Guard lines and the classes above. CI decides the rest.
Considered, not added
pg_statslookups for index columns on the same table column (a chunk's two indexes both look upts). It would roughly halve the remaining estimate time but changes the estimate's shape, and no field number says it matters.Release note:
get_store_table_healthand the Viewer's Store Health tab read faster on a store with thousands of chunks.