Skip to content

rebuild indexes in PAX after CLUSTER rewrite - #2419

Draft
reshke wants to merge 2 commits into
apache:mainfrom
reshke:fix-pax-cluster-index-20261124
Draft

reshke wants to merge 2 commits into
apache:mainfrom
reshke:fix-pax-cluster-index-20261124

Conversation

@reshke

@reshke reshke commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Clustering by PAX columns rewrites micro-partitions and changes tuple IDs. Leaving the index entries untouched can make an indexed query miss rows that a sequential scan still finds. In the regression case, the indexed lookup for c1 = 42 returns (42,714) before CLUSTER and zero rows afterward.

Rebuild the indexes after removing the old micro-partition entries so their TIDs refer to the rewritten table. Add a PAX regression case that checks the indexed result before and after CLUSTER.

Fixes #ISSUE_Number

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


Clustering by PAX columns rewrites micro-partitions and changes tuple
IDs. Leaving the index entries untouched can make an indexed query
miss rows that a sequential scan still finds. In the regression case,
the indexed lookup for c1 = 42 returns (42,714) before CLUSTER and
zero rows afterward.

Rebuild the indexes after removing the old micro-partition entries so
their TIDs refer to the rewritten table. Add a PAX regression case
that checks the indexed result before and after CLUSTER.
The column-based CLUSTER utility hook rewrites PAX micro-partitions with only an AccessShareLock on the coordinator. A concurrent UPDATE can commit while the rewrite is in progress, after which CLUSTER fails with tuple concurrently updated. A concurrent INSERT can also complete before CLUSTER finishes.

Acquire an AccessExclusiveLock before dispatching the rewrite and hold it until transaction end. Apply the same locking to database-wide CLUSTER. Add isolation coverage for concurrent UPDATE and INSERT through both paths.
@reshke
reshke marked this pull request as draft November 24, 2026 18:49
@reshke

reshke commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

second commit currently directly breaks what https://github.com/apache/cloudberry/blob/4ee39f781d25d488ff138d912763b364902189b5/contrib/pax_storage/doc/README.clustering.md describes. I will make another commit here

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.

1 participant