Skip to content

Fix shard-hiding filter on pg_class under outer joins - #8992

Open
Gilles Darold (darold) wants to merge 1 commit into
citusdata:mainfrom
darold:main
Open

Gilles Darold (darold) wants to merge 1 commit into
citusdata:mainfrom
darold:main

Conversation

@darold

Copy link
Copy Markdown

FilterShardsFromPgclass() adds "relation_is_a_known_shard(oid) IS NOT TRUE" to the top-level quals of any query that reads pg_class. The Var for pg_class.oid was built with empty varnullingrels, even when pg_class is on the nullable side of an outer join. Since PG16, a Var that references a nullable relation from above the outer join must carry the join's RT index in varnullingrels. Without it the planner gets an inconsistent tree; on PG18 this fails during deconstruct_jointree() with:

ERROR: negative bitmapset member not allowed

for queries as simple as:

SELECT c.relname FROM pg_class c
LEFT JOIN pg_class t ON c.reltoastrelid = t.oid;

As a result, vacuumdb on PostgreSQL 18 fails on every database with the extension, because it builds its relation list with this kind of join.

Walk the jointree to collect the RT indexes of the outer joins that null the pg_class RTE (right side of LEFT JOIN, left side of RIGHT JOIN, both sides of FULL JOIN) and set them in the filter Var's varnullingrels. The filter placement and its semantics are unchanged.

DESCRIPTION: PR description that will go into the change log, up to 78 characters

FilterShardsFromPgclass() adds "relation_is_a_known_shard(oid) IS NOT TRUE"
to the top-level quals of any query that reads pg_class. The Var for
pg_class.oid was built with empty varnullingrels, even when pg_class is on
the nullable side of an outer join. Since PG16, a Var that references a
nullable relation from above the outer join must carry the join's RT index
in varnullingrels. Without it the planner gets an inconsistent tree; on
PG18 this fails during deconstruct_jointree() with:

  ERROR:  negative bitmapset member not allowed

for queries as simple as:

  SELECT c.relname FROM pg_class c
  LEFT JOIN pg_class t ON c.reltoastrelid = t.oid;

As a result, vacuumdb on PostgreSQL 18 fails on every database with the
extension, because it builds its relation list with this kind of join.

Walk the jointree to collect the RT indexes of the outer joins that null
the pg_class RTE (right side of LEFT JOIN, left side of RIGHT JOIN, both
sides of FULL JOIN) and set them in the filter Var's varnullingrels. The
filter placement and its semantics are unchanged.
@darold

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@ihalatci

Copy link
Copy Markdown
Contributor

Thanks for your contribution, though #8973 is already covering this case and in progress to merge soon. Please take a look and let us know if you dont agree.

@darold

Copy link
Copy Markdown
Author

The patch your are pointing need to be rebased on master, it can't be applied. I don't have time to do that because a lot of thing have changed in the code but reading the patch it seems to fix the issue and also cover PG19 changes that I have not verified.

If the tests I have provided above pass successfully before merging you can consider that commit 42b2389 fix this issue. Then you can close this PR and the related issue.

@gfontenay

gfontenay commented Nov 21, 2026 •

Copy link
Copy Markdown

Hi,
Same error on Citus 14.3.0 / PostgreSQL 18.7 (single-node, coordinator only), triggered by psql \d on any table and by vacuumdb --missing-stats-only. Minimal reproducer, fails at plan time in a database with the citus extension and works in one without:

explain select c.relkind, am.amname from pg_catalog.pg_class c left join pg_catalog.pg_class tc on (c.reltoastrelid = tc.oid) left join pg_catalog.pg_am am on (c.relam = am.oid) where c.oid = 1259;
ERROR: negative bitmapset member not allowed

set citus.show_shards_for_app_name_prefixes = '*' makes it plan normally, consistent with the shard-hiding filter being the cause.

Thanks for reading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants