Skip to content

Commit d223680

Browse files
committed
Cause REINDEX to regard TOAST tables as regular relations, not system
tables that need special defenses. I believe this is okay even for TOAST tables that belong to system tables.
1 parent 5f97dc3 commit d223680

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/backend/catalog/index.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.190 2002/08/28 20:46:47 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.191 2002/08/29 15:56:19 tgl Exp $
1212
*
1313
*
1414
* INTERFACE ROUTINES
@@ -1245,7 +1245,8 @@ setNewRelfilenode(Relation relation)
12451245
Buffer buffer;
12461246
RelationData workrel;
12471247

1248-
Assert(!IsSystemRelation(relation) || relation->rd_rel->relkind == RELKIND_INDEX);
1248+
Assert(!IsSystemRelation(relation) || IsToastRelation(relation) ||
1249+
relation->rd_rel->relkind == RELKIND_INDEX);
12491250

12501251
pg_class = heap_openr(RelationRelationName, RowExclusiveLock);
12511252
/* Fetch and lock the classTuple associated with this relation */
@@ -1927,7 +1928,8 @@ reindex_relation(Oid relid, bool force)
19271928
* ignore the indexes of the target system relation while processing
19281929
* reindex.
19291930
*/
1930-
if (!IsIgnoringSystemIndexes() && IsSystemRelation(rel))
1931+
if (!IsIgnoringSystemIndexes() &&
1932+
IsSystemRelation(rel) && !IsToastRelation(rel))
19311933
deactivate_needed = true;
19321934
#ifndef ENABLE_REINDEX_NAILED_RELATIONS
19331935

src/backend/commands/indexcmds.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.84 2002/08/16 20:55:09 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.85 2002/08/29 15:56:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -559,12 +559,8 @@ RemoveIndex(RangeVar *relation, DropBehavior behavior)
559559
}
560560

561561
/*
562-
* Reindex
562+
* ReindexIndex
563563
* Recreate an index.
564-
*
565-
* Exceptions:
566-
* "ERROR" if index nonexistent.
567-
* ...
568564
*/
569565
void
570566
ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
@@ -593,7 +589,8 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
593589
indexRelation->relname,
594590
((Form_pg_class) GETSTRUCT(tuple))->relkind);
595591

596-
if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple)))
592+
if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
593+
!IsToastClass((Form_pg_class) GETSTRUCT(tuple)))
597594
{
598595
if (!allowSystemTableMods)
599596
elog(ERROR, "\"%s\" is a system index. call REINDEX under standalone postgres with -O -P options",
@@ -614,16 +611,13 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
614611
/*
615612
* ReindexTable
616613
* Recreate indexes of a table.
617-
*
618-
* Exceptions:
619-
* "ERROR" if table nonexistent.
620-
* ...
621614
*/
622615
void
623616
ReindexTable(RangeVar *relation, bool force)
624617
{
625618
Oid heapOid;
626619
HeapTuple tuple;
620+
char relkind;
627621

628622
/*
629623
* REINDEX within a transaction block is dangerous, because if the
@@ -639,11 +633,11 @@ ReindexTable(RangeVar *relation, bool force)
639633
0, 0, 0);
640634
if (!HeapTupleIsValid(tuple))
641635
elog(ERROR, "table \"%s\" does not exist", relation->relname);
636+
relkind = ((Form_pg_class) GETSTRUCT(tuple))->relkind;
642637

643-
if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_RELATION)
638+
if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE)
644639
elog(ERROR, "relation \"%s\" is of type \"%c\"",
645-
relation->relname,
646-
((Form_pg_class) GETSTRUCT(tuple))->relkind);
640+
relation->relname, relkind);
647641

648642
ReleaseSysCache(tuple);
649643

@@ -710,12 +704,16 @@ ReindexDatabase(const char *dbname, bool force, bool all)
710704
relcnt = relalc = 0;
711705
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
712706
{
707+
char relkind;
708+
713709
if (!all)
714710
{
715-
if (!IsSystemClass((Form_pg_class) GETSTRUCT(tuple)))
711+
if (!(IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
712+
!IsToastClass((Form_pg_class) GETSTRUCT(tuple))))
716713
continue;
717714
}
718-
if (((Form_pg_class) GETSTRUCT(tuple))->relkind == RELKIND_RELATION)
715+
relkind = ((Form_pg_class) GETSTRUCT(tuple))->relkind;
716+
if (relkind == RELKIND_RELATION || relkind == RELKIND_TOASTVALUE)
719717
{
720718
old = MemoryContextSwitchTo(private_context);
721719
if (relcnt == 0)
@@ -742,7 +740,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
742740
{
743741
StartTransactionCommand();
744742
if (reindex_relation(relids[i], force))
745-
elog(WARNING, "relation %u was reindexed", relids[i]);
743+
elog(NOTICE, "relation %u was reindexed", relids[i]);
746744
CommitTransactionCommand();
747745
}
748746
StartTransactionCommand();

0 commit comments

Comments
 (0)