Commit f63a5ea
committed
Avoid touching replica identity index in ExtractReplicaIdentity().
In what seems like a fit of misplaced optimization,
ExtractReplicaIdentity() accessed the relation's replica-identity
index without taking any lock on it. Usually, the surrounding query
already holds some lock so this is safe enough ... but in the case
of a previously-planned delete, there might be no existing lock.
Given a suitable test case, this is exposed in v12 and HEAD by an
assertion added by commit b04aeb0.
The whole thing's rather poorly thought out anyway; rather than
looking directly at the index, we should use the index-attributes
bitmap that's held by the parent table's relcache entry, as the
caller functions do. This is more consistent and likely a bit
faster, since it avoids a cache lookup. Hence, change to doing it
that way.
While at it, rather than blithely assuming that the identity
columns are non-null (with catastrophic results if that's wrong),
add assertion checks that they aren't null. Possibly those should
be actual test-and-elog, but I'll leave it like this for now.
In principle, this is a bug that's been there since this code was
introduced (in 9.4). In practice, the risk seems quite low, since
we do have a lock on the index's parent table, so concurrent
changes to the index's catalog entries seem unlikely. Given the
precedent that commit 9c703c1 wasn't back-patched, I won't risk
back-patching this further than v12.
Per report from Hadi Moshayedi.
Discussion: https://postgr.es/m/CAK=1=Wrek44Ese1V7LjKiQS-Nd-5LgLi_5_CskGbpggKEf3tKQ@mail.gmail.com1 parent aef3623 commit f63a5ea
1 file changed
+37
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7593 | 7593 | | |
7594 | 7594 | | |
7595 | 7595 | | |
7596 | | - | |
| 7596 | + | |
| 7597 | + | |
| 7598 | + | |
| 7599 | + | |
| 7600 | + | |
| 7601 | + | |
| 7602 | + | |
7597 | 7603 | | |
7598 | 7604 | | |
7599 | | - | |
| 7605 | + | |
| 7606 | + | |
7600 | 7607 | | |
7601 | 7608 | | |
7602 | | - | |
7603 | | - | |
7604 | 7609 | | |
7605 | | - | |
| 7610 | + | |
| 7611 | + | |
7606 | 7612 | | |
7607 | 7613 | | |
7608 | | - | |
7609 | 7614 | | |
7610 | 7615 | | |
7611 | 7616 | | |
| |||
7624 | 7629 | | |
7625 | 7630 | | |
7626 | 7631 | | |
7627 | | - | |
| 7632 | + | |
7628 | 7633 | | |
7629 | 7634 | | |
7630 | 7635 | | |
| |||
7633 | 7638 | | |
7634 | 7639 | | |
7635 | 7640 | | |
7636 | | - | |
7637 | | - | |
7638 | | - | |
7639 | | - | |
7640 | | - | |
7641 | | - | |
7642 | | - | |
7643 | | - | |
7644 | | - | |
7645 | | - | |
7646 | | - | |
7647 | | - | |
7648 | | - | |
7649 | | - | |
7650 | | - | |
| 7641 | + | |
| 7642 | + | |
| 7643 | + | |
7651 | 7644 | | |
7652 | | - | |
7653 | | - | |
| 7645 | + | |
| 7646 | + | |
| 7647 | + | |
| 7648 | + | |
| 7649 | + | |
| 7650 | + | |
| 7651 | + | |
| 7652 | + | |
7654 | 7653 | | |
7655 | 7654 | | |
7656 | | - | |
7657 | | - | |
| 7655 | + | |
| 7656 | + | |
| 7657 | + | |
7658 | 7658 | | |
7659 | | - | |
7660 | | - | |
7661 | | - | |
| 7659 | + | |
7662 | 7660 | | |
7663 | | - | |
7664 | | - | |
7665 | | - | |
| 7661 | + | |
| 7662 | + | |
| 7663 | + | |
| 7664 | + | |
| 7665 | + | |
| 7666 | + | |
| 7667 | + | |
7666 | 7668 | | |
7667 | 7669 | | |
7668 | 7670 | | |
7669 | 7671 | | |
7670 | | - | |
| 7672 | + | |
| 7673 | + | |
7671 | 7674 | | |
7672 | 7675 | | |
7673 | 7676 | | |
| |||
7680 | 7683 | | |
7681 | 7684 | | |
7682 | 7685 | | |
7683 | | - | |
| 7686 | + | |
7684 | 7687 | | |
7685 | 7688 | | |
7686 | 7689 | | |
| |||
0 commit comments