Skip to content

Commit c0b4dad

Browse files
committed
Promote assertion about !ReindexIsProcessingIndex to runtime error.
When this assertion was installed (in commit d2f60a3), I thought it was only for catching server logic errors that caused accesses to catalogs that were undergoing index rebuilds. However, it will also fire in case of a user-defined index expression that attempts to access its own table. We occasionally see reports of people trying to do that, and typically getting unintelligible low-level errors as a result. We can provide a more on-point message by making this a regular runtime check. While at it, adjust the similar error check in systable_beginscan_ordered to use the same message text. That one is (probably) not reachable without a coding bug, but we might as well use a translatable message if we have one. Per bug #18363 from Alexander Lakhin. Back-patch to all supported branches. Discussion: https://postgr.es/m/18363-e3598a5a572d0699@postgresql.org
1 parent 10f3087 commit c0b4dad

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/backend/access/index/genam.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,8 +572,10 @@ systable_beginscan_ordered(Relation heapRelation,
572572

573573
/* REINDEX can probably be a hard error here ... */
574574
if (ReindexIsProcessingIndex(RelationGetRelid(indexRelation)))
575-
elog(ERROR, "cannot do ordered scan on index \"%s\", because it is being reindexed",
576-
RelationGetRelationName(indexRelation));
575+
ereport(ERROR,
576+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
577+
errmsg("cannot access index \"%s\" while it is being reindexed",
578+
RelationGetRelationName(indexRelation))));
577579
/* ... but we only throw a warning about violating IgnoreSystemIndexes */
578580
if (IgnoreSystemIndexes)
579581
elog(WARNING, "using index \"%s\" despite IgnoreSystemIndexes",

src/backend/access/index/indexam.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,23 @@
6464
* Note: the ReindexIsProcessingIndex() check in RELATION_CHECKS is there
6565
* to check that we don't try to scan or do retail insertions into an index
6666
* that is currently being rebuilt or pending rebuild. This helps to catch
67-
* things that don't work when reindexing system catalogs. The assertion
67+
* things that don't work when reindexing system catalogs, as well as prevent
68+
* user errors like index expressions that access their own tables. The check
6869
* doesn't prevent the actual rebuild because we don't use RELATION_CHECKS
6970
* when calling the index AM's ambuild routine, and there is no reason for
7071
* ambuild to call its subsidiary routines through this file.
7172
* ----------------------------------------------------------------
7273
*/
7374
#define RELATION_CHECKS \
74-
( \
75-
AssertMacro(RelationIsValid(indexRelation)), \
76-
AssertMacro(PointerIsValid(indexRelation->rd_indam)), \
77-
AssertMacro(!ReindexIsProcessingIndex(RelationGetRelid(indexRelation))) \
78-
)
75+
do { \
76+
Assert(RelationIsValid(indexRelation)); \
77+
Assert(PointerIsValid(indexRelation->rd_indam)); \
78+
if (unlikely(ReindexIsProcessingIndex(RelationGetRelid(indexRelation)))) \
79+
ereport(ERROR, \
80+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
81+
errmsg("cannot access index \"%s\" while it is being reindexed", \
82+
RelationGetRelationName(indexRelation)))); \
83+
} while(0)
7984

8085
#define SCAN_CHECKS \
8186
( \

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy