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

Commit d2f60a3

Browse files
committed
Add an Assert that indexam.c isn't used on an index awaiting reindexing.
This might have caught the recent embarrassment over trying to modify pg_index while its indexes were being rebuilt. Noah Misch
1 parent 2d3320d commit d2f60a3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/backend/access/index/indexam.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#include "access/relscan.h"
6666
#include "access/transam.h"
6767
#include "access/xact.h"
68+
#include "catalog/index.h"
6869
#include "pgstat.h"
6970
#include "storage/bufmgr.h"
7071
#include "storage/lmgr.h"
@@ -76,12 +77,21 @@
7677

7778
/* ----------------------------------------------------------------
7879
* macros used in index_ routines
80+
*
81+
* Note: the ReindexIsProcessingIndex() check in RELATION_CHECKS is there
82+
* to check that we don't try to scan or do retail insertions into an index
83+
* that is currently being rebuilt or pending rebuild. This helps to catch
84+
* things that don't work when reindexing system catalogs. The assertion
85+
* doesn't prevent the actual rebuild because we don't use RELATION_CHECKS
86+
* when calling the index AM's ambuild routine, and there is no reason for
87+
* ambuild to call its subsidiary routines through this file.
7988
* ----------------------------------------------------------------
8089
*/
8190
#define RELATION_CHECKS \
8291
( \
8392
AssertMacro(RelationIsValid(indexRelation)), \
84-
AssertMacro(PointerIsValid(indexRelation->rd_am)) \
93+
AssertMacro(PointerIsValid(indexRelation->rd_am)), \
94+
AssertMacro(!ReindexIsProcessingIndex(RelationGetRelid(indexRelation))) \
8595
)
8696

8797
#define SCAN_CHECKS \

0 commit comments

Comments
 (0)