Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f5a465f

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 57b28c0 commit f5a465f

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
@@ -653,8 +653,10 @@ systable_beginscan_ordered(Relation heapRelation,
653653

654654
/* REINDEX can probably be a hard error here ... */
655655
if (ReindexIsProcessingIndex(RelationGetRelid(indexRelation)))
656-
elog(ERROR, "cannot do ordered scan on index \"%s\", because it is being reindexed",
657-
RelationGetRelationName(indexRelation));
656+
ereport(ERROR,
657+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
658+
errmsg("cannot access index \"%s\" while it is being reindexed",
659+
RelationGetRelationName(indexRelation))));
658660
/* ... but we only throw a warning about violating IgnoreSystemIndexes */
659661
if (IgnoreSystemIndexes)
660662
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
@@ -70,18 +70,23 @@
7070
* Note: the ReindexIsProcessingIndex() check in RELATION_CHECKS is there
7171
* to check that we don't try to scan or do retail insertions into an index
7272
* that is currently being rebuilt or pending rebuild. This helps to catch
73-
* things that don't work when reindexing system catalogs. The assertion
73+
* things that don't work when reindexing system catalogs, as well as prevent
74+
* user errors like index expressions that access their own tables. The check
7475
* doesn't prevent the actual rebuild because we don't use RELATION_CHECKS
7576
* when calling the index AM's ambuild routine, and there is no reason for
7677
* ambuild to call its subsidiary routines through this file.
7778
* ----------------------------------------------------------------
7879
*/
7980
#define RELATION_CHECKS \
80-
( \
81-
AssertMacro(RelationIsValid(indexRelation)), \
82-
AssertMacro(PointerIsValid(indexRelation->rd_indam)), \
83-
AssertMacro(!ReindexIsProcessingIndex(RelationGetRelid(indexRelation))) \
84-
)
81+
do { \
82+
Assert(RelationIsValid(indexRelation)); \
83+
Assert(PointerIsValid(indexRelation->rd_indam)); \
84+
if (unlikely(ReindexIsProcessingIndex(RelationGetRelid(indexRelation)))) \
85+
ereport(ERROR, \
86+
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED), \
87+
errmsg("cannot access index \"%s\" while it is being reindexed", \
88+
RelationGetRelationName(indexRelation)))); \
89+
} while(0)
8590

8691
#define SCAN_CHECKS \
8792
( \

0 commit comments

Comments
 (0)