Skip to content

Avoid exclusive catalog lock during parallel join planning - #2404

Open
reshke wants to merge 1 commit into
apache:mainfrom
reshke:fix-issue-2350-planner-catalog-lock
Open

reshke wants to merge 1 commit into
apache:mainfrom
reshke:fix-issue-2350-planner-catalog-lock

Conversation

@reshke

@reshke reshke commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #2350
Parallel DEDUP SEMI planning reads the maximum dbid only to size worker identifiers. Use AccessShareLock for both planner paths, while segment allocation keeps AccessExclusiveLock.

@yjhjstz

yjhjstz commented Nov 24, 2026

Copy link
Copy Markdown
Member

Thanks, LGTM overall. I built the branch and verified that after planning a parallel DEDUP_SEMI join the backend only holds AccessShareLock on gp_segment_configuration, and concurrent readers / FTS probe requests are no longer blocked.

Two minor suggestions (non-blocking):

  1. For the non-exclusive case, consider releasing the lock right away (table_close(rel, AccessShareLock)) like readGpSegConfigFromCatalog does. The planner only uses maxdbid to size bit widths, plans can be cached across transactions anyway, and holding the lock to xact end still makes gp_add_segment*/expansion wait behind any long transaction that happened to plan such a join.
  2. In cbdb_parallel.sql both pg_locks checks run inside the same transaction, so the second check's shared_lock=t is inherited from the first one. Committing between them (or only asserting exclusive_lock=f) would make the REVERSE-path check meaningful. An isolation2 test showing a concurrent reader isn't blocked would cover the actual symptom from [Bug] Parallel dedup semi-join planning takes an exclusive lock on gp_segment_configuration #2350.

@reshke
reshke force-pushed the fix-issue-2350-planner-catalog-lock branch from e9dbf5c to 84694fc Compare November 24, 2026 08:28
@reshke

reshke commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, LGTM overall. I built the branch and verified that after planning a parallel DEDUP_SEMI join the backend only holds AccessShareLock on gp_segment_configuration, and concurrent readers / FTS probe requests are no longer blocked.

Two minor suggestions (non-blocking):

  1. For the non-exclusive case, consider releasing the lock right away (table_close(rel, AccessShareLock)) like readGpSegConfigFromCatalog does. The planner only uses maxdbid to size bit widths, plans can be cached across transactions anyway, and holding the lock to xact end still makes gp_add_segment*/expansion wait behind any long transaction that happened to plan such a join.

Yes, I did more conservative approach in first commit. But releasing locks right away looks indeed safe, so did that.

  1. In cbdb_parallel.sql both pg_locks checks run inside the same transaction, so the second check's shared_lock=t is inherited from the first one. Committing between them (or only asserting exclusive_lock=f) would make the REVERSE-path check meaningful. An isolation2 test showing a concurrent reader isn't blocked would cover the actual symptom from [Bug] Parallel dedup semi-join planning takes an exclusive lock on gp_segment_configuration #2350.

Sure, well spotted, thanks. Should be fixed now.

Parallel DEDUP SEMI planning reads gp_segment_configuration only to size worker identifiers. Use AccessShareLock for the lookup and release it after the scan; keep AccessExclusiveLock transaction-scoped for segment allocation.

Add lock-mode checks and isolation coverage where a second session reads the catalog while the planner transaction remains open. Trigger query: SELECT sum(foo.a) FROM foo WHERE EXISTS (SELECT 1 FROM bar WHERE foo.a = bar.b); with parallel DEDUP SEMI enabled. Fixes apache#2350.
@reshke
reshke force-pushed the fix-issue-2350-planner-catalog-lock branch from 84694fc to a8e922f Compare November 25, 2026 03:42

@Alena0704 Alena0704 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the diagnosis and the fix. Thanks for addressing this issue!

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.

[Bug] Parallel dedup semi-join planning takes an exclusive lock on gp_segment_configuration

4 participants