fix(plugin-postgresql): list a partitioned table once and nest its partitions (#1984) - #1989
Merged
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
datlechin
force-pushed
the
fix/1984-postgres-partition-children
branch
from
July 29, 2026 02:35
372f308 to
784c117
Compare
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
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.
Fixes #1984.
Problem
information_schema.tablesis defined asWHERE c.relkind IN ('r','v','f','p')and reportstable_type = 'BASE TABLE'for both a partitioned parent (relkind='p') and every one of its partition children (relkind='r'). The table listing had no way to tell them apart, so a table split into hundreds of partitions buried the rest of the schema, and the children also filled up autocomplete, Cmd+K, and the export picker.Why not
relispartitionThe issue suggested
AND c.relispartition IS NOT TRUE. That column only exists from PostgreSQL 10, and referencing a missing column fails at parse time, which noCASEor version guard inside the statement can rescue. Verified against a live PostgreSQL 9.6.24:42703is not in the driver's fallback ladder, so that change would have replaced a cluttered table list with no table list at all on PostgreSQL 9.x.This uses
pg_inheritsjoined to the parent'srelkindinstead.pg_inherits,pg_class,pg_namespace, and therelkindcolumn all exist back to PostgreSQL 8, andrelkind IN ('p','I')is a value comparison, so on older servers it simply matches nothing, which is correct because they have no declarative partitioning. No version gate and no capability probe are needed.Rows still come from
information_schema.tables, so its privilege filtering (pg_has_role/has_table_privilege/has_any_column_privilege) is preserved. Queryingpg_classdirectly instead would have been a privilege regression: verified on PG 18, a role grantedSELECTon one table saw 1 row throughinformation_schemaand 9 through a naivepg_classquery.Legacy
INHERITSchildren stay listed on purpose. Their parent is an ordinary table (relkind='r'), and they are independently useful tables rather than one parent's implementation detail.What changed
PostgreSQLSchemaQueries.fetchTables): newincludePartitionAwarenessflag that labels a parent asPARTITIONED TABLEand drops its children.PostgreSQLPluginDriver): the old flat two-armcatchcould not express "the same SQLSTATE means a different missing catalog at each rung", and a second42P01from the first retry was uncaught. It is now an ordered list, extracted toPostgreSQLTableListingLadderso the ordering is unit-testable. Partition awareness degrades last, since it is the only rung that changes which rows come back rather than which columns.NSOutlineViewand lazily loads its direct partitions on disclosure, recursing for subpartitioned children. Expansion state persists, per the HIG outline-view guidance to retain expansion choices. Loading is lazy by design: DataGrip's partition-nesting regression (DBE-13678) came from eager introspection.fetchTablesForSchemaran its own rawinformation_schema.tablesquery, bypassing the plugin, so export would have kept listing every partition. It now callsdriver.fetchTables(schema:), which also deletes a hardcoded Oracle SQL branch that was living in a View.fetchTablesForDatabaseis deliberately left alone: MySQL'sfetchTables(schema:)ignores its schema argument (WHERE TABLE_SCHEMA = DATABASE()), so routing it would return the wrong database's tables.fetchDatabaseMetadatacounted partition children too. Fixed with the same anti-join.ABI
Additive.
scripts/check-pluginkit-abi.shreports exactly two additions (thefetchPartitionsrequirement and its default implementation) and zero removals, so nocurrentPluginKitVersionbump and no plugin re-release. A driver that never implements it resolves through the protocol default, covered by a test. Needs theabi-additivelabel.Verification
Against live PostgreSQL 18.4 and 9.6.24 with a fixture covering multi-level subpartitions, a
DEFAULTpartition, legacyINHERITS, a view, and a materialized view:ordersPARTITIONED TABLEINHERITSchildfetchPartitionson an inheritance parentpg_catalogreference49 tests pass, 0 failures.
PostgreSQLFetchTablesCommentTests.baseQueryStaysPortableasserted the query contains nopg_catalog.pg_class. It is re-pointed at the fully degraded fallback shape, where that guarantee still has to hold, rather than deleted.Not covered
_timescaledb_internal, a different mechanism this filter deliberately does not touch. Worth a follow-up.RecentTableEntryonly persists anisViewboolean. Materialized views and foreign tables already share that pre-existing limitation.SELECTon a partition child but not its parent previously saw that child and now sees neither. pgAdmin and DBeaver behave the same way.Test plan