Commit d2236800 authored by Tom Lane's avatar Tom Lane

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.
parent 5f97dc3e
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.190 2002/08/28 20:46:47 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.191 2002/08/29 15:56:19 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -1245,7 +1245,8 @@ setNewRelfilenode(Relation relation) ...@@ -1245,7 +1245,8 @@ setNewRelfilenode(Relation relation)
Buffer buffer; Buffer buffer;
RelationData workrel; RelationData workrel;
Assert(!IsSystemRelation(relation) || relation->rd_rel->relkind == RELKIND_INDEX); Assert(!IsSystemRelation(relation) || IsToastRelation(relation) ||
relation->rd_rel->relkind == RELKIND_INDEX);
pg_class = heap_openr(RelationRelationName, RowExclusiveLock); pg_class = heap_openr(RelationRelationName, RowExclusiveLock);
/* Fetch and lock the classTuple associated with this relation */ /* Fetch and lock the classTuple associated with this relation */
...@@ -1927,7 +1928,8 @@ reindex_relation(Oid relid, bool force) ...@@ -1927,7 +1928,8 @@ reindex_relation(Oid relid, bool force)
* ignore the indexes of the target system relation while processing * ignore the indexes of the target system relation while processing
* reindex. * reindex.
*/ */
if (!IsIgnoringSystemIndexes() && IsSystemRelation(rel)) if (!IsIgnoringSystemIndexes() &&
IsSystemRelation(rel) && !IsToastRelation(rel))
deactivate_needed = true; deactivate_needed = true;
#ifndef ENABLE_REINDEX_NAILED_RELATIONS #ifndef ENABLE_REINDEX_NAILED_RELATIONS
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.84 2002/08/16 20:55:09 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.85 2002/08/29 15:56:20 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -559,12 +559,8 @@ RemoveIndex(RangeVar *relation, DropBehavior behavior) ...@@ -559,12 +559,8 @@ RemoveIndex(RangeVar *relation, DropBehavior behavior)
} }
/* /*
* Reindex * ReindexIndex
* Recreate an index. * Recreate an index.
*
* Exceptions:
* "ERROR" if index nonexistent.
* ...
*/ */
void void
ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ ) ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
...@@ -593,7 +589,8 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ ) ...@@ -593,7 +589,8 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
indexRelation->relname, indexRelation->relname,
((Form_pg_class) GETSTRUCT(tuple))->relkind); ((Form_pg_class) GETSTRUCT(tuple))->relkind);
if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple))) if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
!IsToastClass((Form_pg_class) GETSTRUCT(tuple)))
{ {
if (!allowSystemTableMods) if (!allowSystemTableMods)
elog(ERROR, "\"%s\" is a system index. call REINDEX under standalone postgres with -O -P options", 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 */ ) ...@@ -614,16 +611,13 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
/* /*
* ReindexTable * ReindexTable
* Recreate indexes of a table. * Recreate indexes of a table.
*
* Exceptions:
* "ERROR" if table nonexistent.
* ...
*/ */
void void
ReindexTable(RangeVar *relation, bool force) ReindexTable(RangeVar *relation, bool force)
{ {
Oid heapOid; Oid heapOid;
HeapTuple tuple; HeapTuple tuple;
char relkind;
/* /*
* REINDEX within a transaction block is dangerous, because if the * REINDEX within a transaction block is dangerous, because if the
...@@ -639,11 +633,11 @@ ReindexTable(RangeVar *relation, bool force) ...@@ -639,11 +633,11 @@ ReindexTable(RangeVar *relation, bool force)
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
elog(ERROR, "table \"%s\" does not exist", relation->relname); elog(ERROR, "table \"%s\" does not exist", relation->relname);
relkind = ((Form_pg_class) GETSTRUCT(tuple))->relkind;
if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_RELATION) if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE)
elog(ERROR, "relation \"%s\" is of type \"%c\"", elog(ERROR, "relation \"%s\" is of type \"%c\"",
relation->relname, relation->relname, relkind);
((Form_pg_class) GETSTRUCT(tuple))->relkind);
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
...@@ -710,12 +704,16 @@ ReindexDatabase(const char *dbname, bool force, bool all) ...@@ -710,12 +704,16 @@ ReindexDatabase(const char *dbname, bool force, bool all)
relcnt = relalc = 0; relcnt = relalc = 0;
while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL) while ((tuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{ {
char relkind;
if (!all) if (!all)
{ {
if (!IsSystemClass((Form_pg_class) GETSTRUCT(tuple))) if (!(IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
!IsToastClass((Form_pg_class) GETSTRUCT(tuple))))
continue; continue;
} }
if (((Form_pg_class) GETSTRUCT(tuple))->relkind == RELKIND_RELATION) relkind = ((Form_pg_class) GETSTRUCT(tuple))->relkind;
if (relkind == RELKIND_RELATION || relkind == RELKIND_TOASTVALUE)
{ {
old = MemoryContextSwitchTo(private_context); old = MemoryContextSwitchTo(private_context);
if (relcnt == 0) if (relcnt == 0)
...@@ -742,7 +740,7 @@ ReindexDatabase(const char *dbname, bool force, bool all) ...@@ -742,7 +740,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
{ {
StartTransactionCommand(); StartTransactionCommand();
if (reindex_relation(relids[i], force)) if (reindex_relation(relids[i], force))
elog(WARNING, "relation %u was reindexed", relids[i]); elog(NOTICE, "relation %u was reindexed", relids[i]);
CommitTransactionCommand(); CommitTransactionCommand();
} }
StartTransactionCommand(); StartTransactionCommand();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment