88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.214 2003/08/04 02:39:58 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.215 2003/09/19 19:57:42 tgl Exp $
1212 *
1313 *
1414 * INTERFACE ROUTINES
@@ -76,7 +76,6 @@ static void UpdateIndexRelation(Oid indexoid, Oid heapoid,
7676 Oid * classOids ,
7777 bool primary );
7878static Oid IndexGetRelation (Oid indexId );
79- static bool activate_index (Oid indexId , bool activate , bool inplace );
8079
8180
8281static bool reindexing = false;
@@ -1690,23 +1689,8 @@ IndexGetRelation(Oid indexId)
16901689 return result ;
16911690}
16921691
1693- /* ---------------------------------
1694- * activate_index -- activate/deactivate the specified index.
1695- * Note that currently PostgreSQL doesn't hold the
1696- * status per index
1697- * ---------------------------------
1698- */
1699- static bool
1700- activate_index (Oid indexId , bool activate , bool inplace )
1701- {
1702- if (!activate ) /* Currently does nothing */
1703- return true;
1704- return reindex_index (indexId , false, inplace );
1705- }
1706-
1707- /* --------------------------------
1692+ /*
17081693 * reindex_index - This routine is used to recreate an index
1709- * --------------------------------
17101694 */
17111695bool
17121696reindex_index (Oid indexId , bool force , bool inplace )
@@ -1745,22 +1729,24 @@ reindex_index(Oid indexId, bool force, bool inplace)
17451729 * the relcache can't cope with changing its relfilenode.
17461730 *
17471731 * In either of these cases, we are definitely processing a system index,
1748- * so we'd better be ignoring system indexes.
1732+ * so we'd better be ignoring system indexes. (These checks are just
1733+ * for paranoia's sake --- upstream code should have disallowed reindex
1734+ * in such cases already.)
17491735 */
17501736 if (iRel -> rd_rel -> relisshared )
17511737 {
17521738 if (!IsIgnoringSystemIndexes ())
1753- ereport (ERROR ,
1754- ( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
1755- errmsg ( "the target relation %u is shared" , indexId )) );
1739+ elog (ERROR ,
1740+ "must be ignoring system indexes to reindex shared index %u" ,
1741+ indexId );
17561742 inplace = true;
17571743 }
17581744 if (iRel -> rd_isnailed )
17591745 {
17601746 if (!IsIgnoringSystemIndexes ())
1761- ereport (ERROR ,
1762- ( errcode ( ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ) ,
1763- errmsg ( "the target relation %u is nailed" , indexId )) );
1747+ elog (ERROR ,
1748+ "must be ignoring system indexes to reindex nailed index %u" ,
1749+ indexId );
17641750 inplace = true;
17651751 }
17661752
@@ -1801,13 +1787,12 @@ reindex_index(Oid indexId, bool force, bool inplace)
18011787 return true;
18021788}
18031789
1790+ #ifdef NOT_USED
18041791/*
1805- * ----------------------------
18061792 * activate_indexes_of_a_table
18071793 * activate/deactivate indexes of the specified table.
18081794 *
18091795 * Caller must already hold exclusive lock on the table.
1810- * ----------------------------
18111796 */
18121797bool
18131798activate_indexes_of_a_table (Relation heaprel , bool activate )
@@ -1829,11 +1814,11 @@ activate_indexes_of_a_table(Relation heaprel, bool activate)
18291814 }
18301815 return true;
18311816}
1817+ #endif /* NOT_USED */
18321818
1833- /* --------------------------------
1834- * reindex_relation - This routine is used to recreate indexes
1819+ /*
1820+ * reindex_relation - This routine is used to recreate all indexes
18351821 * of a relation.
1836- * --------------------------------
18371822 */
18381823bool
18391824reindex_relation (Oid relid , bool force )
@@ -1844,11 +1829,10 @@ reindex_relation(Oid relid, bool force)
18441829 HeapTuple indexTuple ;
18451830 bool old ,
18461831 reindexed ;
1847- bool deactivate_needed ,
1848- overwrite ;
1832+ bool overwrite ;
18491833 Relation rel ;
18501834
1851- overwrite = deactivate_needed = false;
1835+ overwrite = false;
18521836
18531837 /*
18541838 * Ensure to hold an exclusive lock throughout the transaction. The
@@ -1858,62 +1842,50 @@ reindex_relation(Oid relid, bool force)
18581842 rel = heap_open (relid , AccessExclusiveLock );
18591843
18601844 /*
1861- * ignore the indexes of the target system relation while processing
1862- * reindex.
1845+ * Should be ignoring system indexes if we are reindexing a system table.
1846+ * (This is elog not ereport because caller should have caught it.)
18631847 */
18641848 if (!IsIgnoringSystemIndexes () &&
18651849 IsSystemRelation (rel ) && !IsToastRelation (rel ))
1866- deactivate_needed = true;
1850+ elog (ERROR ,
1851+ "must be ignoring system indexes to reindex system table %u" ,
1852+ relid );
18671853
18681854 /*
18691855 * Shared system indexes must be overwritten because it's impossible
18701856 * to update pg_class tuples of all databases.
18711857 */
18721858 if (rel -> rd_rel -> relisshared )
18731859 {
1874- if (IsIgnoringSystemIndexes ())
1875- {
1876- overwrite = true;
1877- deactivate_needed = true;
1878- }
1879- else
1880- ereport (ERROR ,
1881- (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
1882- errmsg ("the target relation %u is shared" , relid )));
1860+ if (!IsIgnoringSystemIndexes ()) /* shouldn't happen */
1861+ elog (ERROR ,
1862+ "must be ignoring system indexes to reindex shared table %u" ,
1863+ relid );
1864+ overwrite = true;
18831865 }
18841866
18851867 old = SetReindexProcessing (true);
18861868
1887- if (deactivate_needed )
1888- {
1889- if (IndexesAreActive (rel ))
1890- {
1891- if (!force )
1892- {
1893- SetReindexProcessing (old );
1894- heap_close (rel , NoLock );
1895- return false;
1896- }
1897- activate_indexes_of_a_table (rel , false);
1898- CommandCounterIncrement ();
1899- }
1900- }
1901-
19021869 /*
19031870 * Continue to hold the lock.
19041871 */
19051872 heap_close (rel , NoLock );
19061873
1874+ /*
1875+ * Find table's indexes by looking in pg_index (not trusting indexes...)
1876+ */
19071877 indexRelation = heap_openr (IndexRelationName , AccessShareLock );
1908- ScanKeyEntryInitialize (& entry , 0 , Anum_pg_index_indrelid ,
1909- F_OIDEQ , ObjectIdGetDatum (relid ));
1878+ ScanKeyEntryInitialize (& entry , 0 ,
1879+ Anum_pg_index_indrelid ,
1880+ F_OIDEQ ,
1881+ ObjectIdGetDatum (relid ));
19101882 scan = heap_beginscan (indexRelation , SnapshotNow , 1 , & entry );
19111883 reindexed = false;
19121884 while ((indexTuple = heap_getnext (scan , ForwardScanDirection )) != NULL )
19131885 {
19141886 Form_pg_index index = (Form_pg_index ) GETSTRUCT (indexTuple );
19151887
1916- if (activate_index (index -> indexrelid , true , overwrite ))
1888+ if (reindex_index (index -> indexrelid , false , overwrite ))
19171889 reindexed = true;
19181890 else
19191891 {
@@ -1923,31 +1895,7 @@ reindex_relation(Oid relid, bool force)
19231895 }
19241896 heap_endscan (scan );
19251897 heap_close (indexRelation , AccessShareLock );
1926- if (reindexed )
1927- {
1928- /*
1929- * Ok,we could use the reindexed indexes of the target system
1930- * relation now.
1931- */
1932- if (deactivate_needed )
1933- {
1934- if (!overwrite && relid == RelOid_pg_class )
1935- {
1936- /*
1937- * For pg_class, relhasindex should be set to true here in
1938- * place.
1939- */
1940- setRelhasindex (relid , true, false, InvalidOid );
1941- CommandCounterIncrement ();
19421898
1943- /*
1944- * However the following setRelhasindex() is needed to
1945- * keep consistency with WAL.
1946- */
1947- }
1948- setRelhasindex (relid , true, false, InvalidOid );
1949- }
1950- }
19511899 SetReindexProcessing (old );
19521900
19531901 return reindexed ;
0 commit comments