Commit f5c5c3c6 authored by Hiroshi Inoue's avatar Hiroshi Inoue

Putting back the previous change must be the first thing.

ALso put back a #ifndef ENABLE_REINDEX_NAILED_RELATIONS
which was removed about a year ago.
parent 0b1ee9b5
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.215 2003/09/19 19:57:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.216 2003/09/23 01:51:09 inoue Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -76,6 +76,7 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid, ...@@ -76,6 +76,7 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
Oid *classOids, Oid *classOids,
bool primary); bool primary);
static Oid IndexGetRelation(Oid indexId); static Oid IndexGetRelation(Oid indexId);
static bool activate_index(Oid indexId, bool activate, bool inplace);
static bool reindexing = false; static bool reindexing = false;
...@@ -1689,8 +1690,23 @@ IndexGetRelation(Oid indexId) ...@@ -1689,8 +1690,23 @@ IndexGetRelation(Oid indexId)
return result; return result;
} }
/* /* ---------------------------------
* activate_index -- activate/deactivate the specified index.
* Note that currently PostgreSQL doesn't hold the
* status per index
* ---------------------------------
*/
static bool
activate_index(Oid indexId, bool activate, bool inplace)
{
if (!activate) /* Currently does nothing */
return true;
return reindex_index(indexId, false, inplace);
}
/* --------------------------------
* reindex_index - This routine is used to recreate an index * reindex_index - This routine is used to recreate an index
* --------------------------------
*/ */
bool bool
reindex_index(Oid indexId, bool force, bool inplace) reindex_index(Oid indexId, bool force, bool inplace)
...@@ -1729,26 +1745,26 @@ reindex_index(Oid indexId, bool force, bool inplace) ...@@ -1729,26 +1745,26 @@ reindex_index(Oid indexId, bool force, bool inplace)
* the relcache can't cope with changing its relfilenode. * the relcache can't cope with changing its relfilenode.
* *
* In either of these cases, we are definitely processing a system index, * In either of these cases, we are definitely processing a system index,
* so we'd better be ignoring system indexes. (These checks are just * so we'd better be ignoring system indexes.
* for paranoia's sake --- upstream code should have disallowed reindex
* in such cases already.)
*/ */
if (iRel->rd_rel->relisshared) if (iRel->rd_rel->relisshared)
{ {
if (!IsIgnoringSystemIndexes()) if (!IsIgnoringSystemIndexes())
elog(ERROR, ereport(ERROR,
"must be ignoring system indexes to reindex shared index %u", (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
indexId); errmsg("the target relation %u is shared", indexId)));
inplace = true; inplace = true;
} }
#ifndef ENABLE_REINDEX_NAILED_RELATIONS
if (iRel->rd_isnailed) if (iRel->rd_isnailed)
{ {
if (!IsIgnoringSystemIndexes()) if (!IsIgnoringSystemIndexes())
elog(ERROR, ereport(ERROR,
"must be ignoring system indexes to reindex nailed index %u", (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
indexId); errmsg("the target relation %u is nailed", indexId)));
inplace = true; inplace = true;
} }
#endif /* ENABLE_REINDEX_NAILED_RELATIONS */
/* Fetch info needed for index_build */ /* Fetch info needed for index_build */
indexInfo = BuildIndexInfo(iRel); indexInfo = BuildIndexInfo(iRel);
...@@ -1787,12 +1803,13 @@ reindex_index(Oid indexId, bool force, bool inplace) ...@@ -1787,12 +1803,13 @@ reindex_index(Oid indexId, bool force, bool inplace)
return true; return true;
} }
#ifdef NOT_USED
/* /*
* ----------------------------
* activate_indexes_of_a_table * activate_indexes_of_a_table
* activate/deactivate indexes of the specified table. * activate/deactivate indexes of the specified table.
* *
* Caller must already hold exclusive lock on the table. * Caller must already hold exclusive lock on the table.
* ----------------------------
*/ */
bool bool
activate_indexes_of_a_table(Relation heaprel, bool activate) activate_indexes_of_a_table(Relation heaprel, bool activate)
...@@ -1814,11 +1831,11 @@ activate_indexes_of_a_table(Relation heaprel, bool activate) ...@@ -1814,11 +1831,11 @@ activate_indexes_of_a_table(Relation heaprel, bool activate)
} }
return true; return true;
} }
#endif /* NOT_USED */
/* /* --------------------------------
* reindex_relation - This routine is used to recreate all indexes * reindex_relation - This routine is used to recreate indexes
* of a relation. * of a relation.
* --------------------------------
*/ */
bool bool
reindex_relation(Oid relid, bool force) reindex_relation(Oid relid, bool force)
...@@ -1829,10 +1846,11 @@ reindex_relation(Oid relid, bool force) ...@@ -1829,10 +1846,11 @@ reindex_relation(Oid relid, bool force)
HeapTuple indexTuple; HeapTuple indexTuple;
bool old, bool old,
reindexed; reindexed;
bool overwrite; bool deactivate_needed,
overwrite;
Relation rel; Relation rel;
overwrite = false; overwrite = deactivate_needed = false;
/* /*
* Ensure to hold an exclusive lock throughout the transaction. The * Ensure to hold an exclusive lock throughout the transaction. The
...@@ -1842,14 +1860,12 @@ reindex_relation(Oid relid, bool force) ...@@ -1842,14 +1860,12 @@ reindex_relation(Oid relid, bool force)
rel = heap_open(relid, AccessExclusiveLock); rel = heap_open(relid, AccessExclusiveLock);
/* /*
* Should be ignoring system indexes if we are reindexing a system table. * ignore the indexes of the target system relation while processing
* (This is elog not ereport because caller should have caught it.) * reindex.
*/ */
if (!IsIgnoringSystemIndexes() && if (!IsIgnoringSystemIndexes() &&
IsSystemRelation(rel) && !IsToastRelation(rel)) IsSystemRelation(rel) && !IsToastRelation(rel))
elog(ERROR, deactivate_needed = true;
"must be ignoring system indexes to reindex system table %u",
relid);
/* /*
* Shared system indexes must be overwritten because it's impossible * Shared system indexes must be overwritten because it's impossible
...@@ -1857,35 +1873,49 @@ reindex_relation(Oid relid, bool force) ...@@ -1857,35 +1873,49 @@ reindex_relation(Oid relid, bool force)
*/ */
if (rel->rd_rel->relisshared) if (rel->rd_rel->relisshared)
{ {
if (!IsIgnoringSystemIndexes()) /* shouldn't happen */ if (IsIgnoringSystemIndexes())
elog(ERROR, {
"must be ignoring system indexes to reindex shared table %u", overwrite = true;
relid); deactivate_needed = true;
overwrite = true; }
else
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("the target relation %u is shared", relid)));
} }
old = SetReindexProcessing(true); old = SetReindexProcessing(true);
if (deactivate_needed)
{
if (IndexesAreActive(rel))
{
if (!force)
{
SetReindexProcessing(old);
heap_close(rel, NoLock);
return false;
}
activate_indexes_of_a_table(rel, false);
CommandCounterIncrement();
}
}
/* /*
* Continue to hold the lock. * Continue to hold the lock.
*/ */
heap_close(rel, NoLock); heap_close(rel, NoLock);
/*
* Find table's indexes by looking in pg_index (not trusting indexes...)
*/
indexRelation = heap_openr(IndexRelationName, AccessShareLock); indexRelation = heap_openr(IndexRelationName, AccessShareLock);
ScanKeyEntryInitialize(&entry, 0, ScanKeyEntryInitialize(&entry, 0, Anum_pg_index_indrelid,
Anum_pg_index_indrelid, F_OIDEQ, ObjectIdGetDatum(relid));
F_OIDEQ,
ObjectIdGetDatum(relid));
scan = heap_beginscan(indexRelation, SnapshotNow, 1, &entry); scan = heap_beginscan(indexRelation, SnapshotNow, 1, &entry);
reindexed = false; reindexed = false;
while ((indexTuple = heap_getnext(scan, ForwardScanDirection)) != NULL) while ((indexTuple = heap_getnext(scan, ForwardScanDirection)) != NULL)
{ {
Form_pg_index index = (Form_pg_index) GETSTRUCT(indexTuple); Form_pg_index index = (Form_pg_index) GETSTRUCT(indexTuple);
if (reindex_index(index->indexrelid, false, overwrite)) if (activate_index(index->indexrelid, true, overwrite))
reindexed = true; reindexed = true;
else else
{ {
...@@ -1895,7 +1925,31 @@ reindex_relation(Oid relid, bool force) ...@@ -1895,7 +1925,31 @@ reindex_relation(Oid relid, bool force)
} }
heap_endscan(scan); heap_endscan(scan);
heap_close(indexRelation, AccessShareLock); heap_close(indexRelation, AccessShareLock);
if (reindexed)
{
/*
* Ok,we could use the reindexed indexes of the target system
* relation now.
*/
if (deactivate_needed)
{
if (!overwrite && relid == RelOid_pg_class)
{
/*
* For pg_class, relhasindex should be set to true here in
* place.
*/
setRelhasindex(relid, true, false, InvalidOid);
CommandCounterIncrement();
/*
* However the following setRelhasindex() is needed to
* keep consistency with WAL.
*/
}
setRelhasindex(relid, true, false, InvalidOid);
}
}
SetReindexProcessing(old); SetReindexProcessing(old);
return reindexed; return reindexed;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.107 2003/09/19 19:57:42 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.108 2003/09/23 01:51:09 inoue Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -658,41 +658,17 @@ void ...@@ -658,41 +658,17 @@ void
ReindexTable(RangeVar *relation, bool force) ReindexTable(RangeVar *relation, bool force)
{ {
Oid heapOid; Oid heapOid;
HeapTuple tuple; char relkind;
heapOid = RangeVarGetRelid(relation, false); heapOid = RangeVarGetRelid(relation, false);
tuple = SearchSysCache(RELOID, relkind = get_rel_relkind(heapOid);
ObjectIdGetDatum(heapOid),
0, 0, 0);
if (!HeapTupleIsValid(tuple)) /* shouldn't happen */
elog(ERROR, "cache lookup failed for relation %u", heapOid);
if (((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_RELATION && if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE)
((Form_pg_class) GETSTRUCT(tuple))->relkind != RELKIND_TOASTVALUE)
ereport(ERROR, ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE), (errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("relation \"%s\" is not a table", errmsg("relation \"%s\" is not a table",
relation->relname))); relation->relname)));
if (IsSystemClass((Form_pg_class) GETSTRUCT(tuple)) &&
!IsToastClass((Form_pg_class) GETSTRUCT(tuple)))
{
if (!allowSystemTableMods)
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied: \"%s\" is a system table",
relation->relname),
errhint("Do REINDEX in standalone postgres with -O -P options.")));
if (!IsIgnoringSystemIndexes())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("permission denied: \"%s\" is a system table",
relation->relname),
errhint("Do REINDEX in standalone postgres with -P -O options.")));
}
ReleaseSysCache(tuple);
/* /*
* In-place REINDEX within a transaction block is dangerous, because * In-place REINDEX within a transaction block is dangerous, because
* if the transaction is later rolled back we have no way to undo * if the transaction is later rolled back we have no way to undo
......
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