public inbox for [email protected]help / color / mirror / Atom feed
[PATCH v8 7/8] Preserve indisclustered on children of clustered, partitioned indexes 2+ messages / 2 participants [nested] [flat]
* [PATCH v8 7/8] Preserve indisclustered on children of clustered, partitioned indexes @ 2020-10-07 01:40 Justin Pryzby <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Justin Pryzby @ 2020-10-07 01:40 UTC (permalink / raw) Note, this takes a parentIndex, but that wasn't previously used ... UpdateIndexRelation(Oid indexoid, Oid heapoid, Oid parentIndexId, --- src/backend/catalog/index.c | 2 +- src/test/regress/expected/cluster.out | 12 ++++++++++++ src/test/regress/sql/cluster.sql | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/backend/catalog/index.c b/src/backend/catalog/index.c index 1514937748..08fdf02ebc 100644 --- a/src/backend/catalog/index.c +++ b/src/backend/catalog/index.c @@ -604,7 +604,7 @@ UpdateIndexRelation(Oid indexoid, values[Anum_pg_index_indisprimary - 1] = BoolGetDatum(primary); values[Anum_pg_index_indisexclusion - 1] = BoolGetDatum(isexclusion); values[Anum_pg_index_indimmediate - 1] = BoolGetDatum(immediate); - values[Anum_pg_index_indisclustered - 1] = BoolGetDatum(false); + values[Anum_pg_index_indisclustered - 1] = BoolGetDatum(OidIsValid(parentIndexId) && get_index_isclustered(parentIndexId)); values[Anum_pg_index_indisvalid - 1] = BoolGetDatum(isvalid); values[Anum_pg_index_indcheckxmin - 1] = BoolGetDatum(false); values[Anum_pg_index_indisready - 1] = BoolGetDatum(isready); diff --git a/src/test/regress/expected/cluster.out b/src/test/regress/expected/cluster.out index e7f0889743..a3943c13f5 100644 --- a/src/test/regress/expected/cluster.out +++ b/src/test/regress/expected/cluster.out @@ -581,6 +581,18 @@ Indexes: "clstrpart_idx" btree (a) Number of partitions: 4 (Use \d+ to list them.) +-- Check that new children inherit clustered mark +ALTER TABLE clstrpart CLUSTER ON clstrpart_idx; +CREATE TABLE clstrpart4 PARTITION OF clstrpart FOR VALUES FROM (30)TO(40); +\d clstrpart4 + Table "public.clstrpart4" + Column | Type | Collation | Nullable | Default +--------+---------+-----------+----------+--------- + a | integer | | | +Partition of: clstrpart FOR VALUES FROM (30) TO (40) +Indexes: + "clstrpart4_a_idx" btree (a) CLUSTER + -- Test CLUSTER with external tuplesorting create table clstr_4 as select * from tenk1; create index cluster_sort on clstr_4 (hundred, thousand, tenthous); diff --git a/src/test/regress/sql/cluster.sql b/src/test/regress/sql/cluster.sql index 3c8085c69e..22628e90ca 100644 --- a/src/test/regress/sql/cluster.sql +++ b/src/test/regress/sql/cluster.sql @@ -244,6 +244,10 @@ ALTER TABLE clstrpart CLUSTER ON clstrpart_idx; CREATE TABLE clstrpart5 (LIKE clstrpart INCLUDING INDEXES); ALTER TABLE clstrpart ATTACH PARTITION clstrpart5 FOR VALUES FROM (40)TO(50); \d clstrpart +-- Check that new children inherit clustered mark +ALTER TABLE clstrpart CLUSTER ON clstrpart_idx; +CREATE TABLE clstrpart4 PARTITION OF clstrpart FOR VALUES FROM (30)TO(40); +\d clstrpart4 -- Test CLUSTER with external tuplesorting -- 2.17.0 --O5XBE6gyVG5Rl6Rj Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v8-0008-pg_dump-partitioned-index-depend-on-its-partition.patch" ^ permalink raw reply [nested|flat] 2+ messages in thread
* [PATCH v9 04/10] lwlock: Invert meaning of LW_FLAG_RELEASE_OK @ 2026-01-06 01:40 Andres Freund <[email protected]> 0 siblings, 0 replies; 2+ messages in thread From: Andres Freund @ 2026-01-06 01:40 UTC (permalink / raw) Instead of setting a flag whenever a lock release is supposed to wake up waiters - the majority of the time - set a flag whenever wakeups are inhibited. The motivation for this that in an upcoming commit, buffer content locks are implemented separately from lwlocks, and for buffer content locks it is useful to be able to reset all buffer flags when a buffer invalidated, alternatively we would have to set the release-ok flag when making a buffer valid. It seems good to keep the implementation of lwlocks and buffer content locks as similar as reasonably possible. Author: Reviewed-by: Discussion: https://postgr.es/m/ Backpatch: --- src/backend/storage/lmgr/lwlock.c | 42 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 6a9f86d5025..148309cc186 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -92,7 +92,7 @@ #define LW_FLAG_HAS_WAITERS ((uint32) 1 << 31) -#define LW_FLAG_RELEASE_OK ((uint32) 1 << 30) +#define LW_FLAG_WAKE_IN_PROGRESS ((uint32) 1 << 30) #define LW_FLAG_LOCKED ((uint32) 1 << 29) #define LW_FLAG_BITS 3 #define LW_FLAG_MASK (((1<<LW_FLAG_BITS)-1)<<(32-LW_FLAG_BITS)) @@ -246,14 +246,14 @@ PRINT_LWDEBUG(const char *where, LWLock *lock, LWLockMode mode) ereport(LOG, (errhidestmt(true), errhidecontext(true), - errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u rOK %d", + errmsg_internal("%d: %s(%s %p): excl %u shared %u haswaiters %u waiters %u waking %d", MyProcPid, where, T_NAME(lock), lock, (state & LW_VAL_EXCLUSIVE) != 0, state & LW_SHARED_MASK, (state & LW_FLAG_HAS_WAITERS) != 0, pg_atomic_read_u32(&lock->nwaiters), - (state & LW_FLAG_RELEASE_OK) != 0))); + (state & LW_FLAG_WAKE_IN_PROGRESS) != 0))); } } @@ -700,7 +700,7 @@ LWLockInitialize(LWLock *lock, int tranche_id) /* verify the tranche_id is valid */ (void) GetLWTrancheName(tranche_id); - pg_atomic_init_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_init_u32(&lock->state, 0); #ifdef LOCK_DEBUG pg_atomic_init_u32(&lock->nwaiters, 0); #endif @@ -929,15 +929,13 @@ LWLockWaitListUnlock(LWLock *lock) static void LWLockWakeup(LWLock *lock) { - bool new_release_ok; + bool new_release_in_progress = false; bool wokeup_somebody = false; proclist_head wakeup; proclist_mutable_iter iter; proclist_init(&wakeup); - new_release_ok = true; - /* lock wait list while collecting backends to wake up */ LWLockWaitListLock(lock); @@ -958,7 +956,7 @@ LWLockWakeup(LWLock *lock) * that are just waiting for the lock to become free don't retry * automatically. */ - new_release_ok = false; + new_release_in_progress = true; /* * Don't wakeup (further) exclusive locks. @@ -997,10 +995,10 @@ LWLockWakeup(LWLock *lock) /* compute desired flags */ - if (new_release_ok) - desired_state |= LW_FLAG_RELEASE_OK; + if (new_release_in_progress) + desired_state |= LW_FLAG_WAKE_IN_PROGRESS; else - desired_state &= ~LW_FLAG_RELEASE_OK; + desired_state &= ~LW_FLAG_WAKE_IN_PROGRESS; if (proclist_is_empty(&lock->waiters)) desired_state &= ~LW_FLAG_HAS_WAITERS; @@ -1131,10 +1129,10 @@ LWLockDequeueSelf(LWLock *lock) */ /* - * Reset RELEASE_OK flag if somebody woke us before we removed - * ourselves - they'll have set it to false. + * Clear LW_FLAG_WAKE_IN_PROGRESS if somebody woke us before we + * removed ourselves - they'll have set it. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * Now wait for the scheduled wakeup, otherwise our ->lwWaiting would @@ -1301,7 +1299,7 @@ LWLockAcquire(LWLock *lock, LWLockMode mode) } /* Retrying, allow LWLockRelease to release waiters again. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); #ifdef LOCK_DEBUG { @@ -1636,10 +1634,10 @@ LWLockWaitForVar(LWLock *lock, pg_atomic_uint64 *valptr, uint64 oldval, LWLockQueueSelf(lock, LW_WAIT_UNTIL_FREE); /* - * Set RELEASE_OK flag, to make sure we get woken up as soon as the - * lock is released. + * Clear LW_FLAG_WAKE_IN_PROGRESS flag, to make sure we get woken up + * as soon as the lock is released. */ - pg_atomic_fetch_or_u32(&lock->state, LW_FLAG_RELEASE_OK); + pg_atomic_fetch_and_u32(&lock->state, ~LW_FLAG_WAKE_IN_PROGRESS); /* * We're now guaranteed to be woken up if necessary. Recheck the lock @@ -1852,11 +1850,11 @@ LWLockReleaseInternal(LWLock *lock, LWLockMode mode) TRACE_POSTGRESQL_LWLOCK_RELEASE(T_NAME(lock)); /* - * We're still waiting for backends to get scheduled, don't wake them up - * again. + * Check if we're still waiting for backends to get scheduled, if so, + * don't wake them up again. */ - if ((oldstate & (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK)) == - (LW_FLAG_HAS_WAITERS | LW_FLAG_RELEASE_OK) && + if ((oldstate & LW_FLAG_HAS_WAITERS) && + !(oldstate & LW_FLAG_WAKE_IN_PROGRESS) && (oldstate & LW_LOCK_MASK) == 0) check_waiters = true; else -- 2.48.1.76.g4e746b1a31.dirty --rkiyqpij3ajqn7ww Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v9-0005-bufmgr-Make-definitions-related-to-buffer-descrip.patch" ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2026-01-06 01:40 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-10-07 01:40 [PATCH v8 7/8] Preserve indisclustered on children of clustered, partitioned indexes Justin Pryzby <[email protected]> 2026-01-06 01:40 [PATCH v9 04/10] lwlock: Invert meaning of LW_FLAG_RELEASE_OK Andres Freund <[email protected]>
This inbox is served by agora; see mirroring instructions for how to clone and mirror all data and code used for this inbox