Skip to content

Commit

Permalink
Do accquire a spinlock when not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
kovmir committed Mar 16, 2023
1 parent dd4adb7 commit 1a90b9a
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pg_show_plans.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,20 +459,22 @@ pgsp_ExecutorRun(QueryDesc *queryDesc, ScanDirection direction,
standard_ExecutorRun(queryDesc, direction, count, execute_once);

nest_level--;
/* Wait for reading to complete, the delete. */
SpinLockAcquire(&pgsp_cache->mutex);
if (nest_level < 1) /* Mark hash entry as empty. */
/* Wait for reading to complete, then delete. */
if (nest_level < 1) { /* Mark hash entry as empty. */
SpinLockAcquire(&pgsp_cache->mutex);
pgsp_cache->n_plans = 0;
SpinLockRelease(&pgsp_cache->mutex);
SpinLockRelease(&pgsp_cache->mutex);
}
}
PG_CATCH(); /* Since 13 PG_FINALLY() is available. */
{
nest_level--;
/* Wait for reading to complete, the delete. */
SpinLockAcquire(&pgsp_cache->mutex);
if (nest_level < 1) /* Mark hash entry as empty. */
/* Wait for reading to complete, then delete. */
if (nest_level < 1) { /* Mark hash entry as empty. */
SpinLockAcquire(&pgsp_cache->mutex);
pgsp_cache->n_plans = 0;
SpinLockRelease(&pgsp_cache->mutex);
SpinLockRelease(&pgsp_cache->mutex);
}

PG_RE_THROW();
}
Expand Down

0 comments on commit 1a90b9a

Please sign in to comment.