88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.91 2002/10/19 20:15:08 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.92 2002/10/21 22:06:19 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -560,15 +560,10 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
560560{
561561Oid indOid ;
562562HeapTuple tuple ;
563- bool overwrite = false ;
563+ bool overwrite ;
564564
565- /*
566- * REINDEX within a transaction block is dangerous, because if the
567- * transaction is later rolled back we have no way to undo truncation
568- * of the index's physical file. Disallow it.
569- */
570- if (IsTransactionBlock ())
571- elog (ERROR ,"REINDEX cannot run inside a BEGIN/END block" );
565+ /* Choose in-place-or-not mode */
566+ overwrite = IsIgnoringSystemIndexes ();
572567
573568indOid = RangeVarGetRelid (indexRelation , false);
574569tuple = SearchSysCache (RELOID ,
@@ -595,8 +590,14 @@ ReindexIndex(RangeVar *indexRelation, bool force /* currently unused */ )
595590
596591ReleaseSysCache (tuple );
597592
598- if (IsIgnoringSystemIndexes ())
599- overwrite = true;
593+ /*
594+ * In-place REINDEX within a transaction block is dangerous, because
595+ * if the transaction is later rolled back we have no way to undo
596+ * truncation of the index's physical file. Disallow it.
597+ */
598+ if (overwrite )
599+ PreventTransactionChain ((void * )indexRelation ,"REINDEX" );
600+
600601if (!reindex_index (indOid ,force ,overwrite ))
601602elog (WARNING ,"index \"%s\" wasn't reindexed" ,indexRelation -> relname );
602603}
@@ -611,21 +612,24 @@ ReindexTable(RangeVar *relation, bool force)
611612Oid heapOid ;
612613char relkind ;
613614
614- /*
615- * REINDEX within a transaction block is dangerous, because if the
616- * transaction is later rolled back we have no way to undo truncation
617- * of the index's physical file. Disallow it.
618- */
619- if (IsTransactionBlock ())
620- elog (ERROR ,"REINDEX cannot run inside a BEGIN/END block" );
621-
622615heapOid = RangeVarGetRelid (relation , false);
623616relkind = get_rel_relkind (heapOid );
624617
625618if (relkind != RELKIND_RELATION && relkind != RELKIND_TOASTVALUE )
626619elog (ERROR ,"relation \"%s\" is of type \"%c\"" ,
627620relation -> relname ,relkind );
628621
622+ /*
623+ * In-place REINDEX within a transaction block is dangerous, because
624+ * if the transaction is later rolled back we have no way to undo
625+ * truncation of the index's physical file. Disallow it.
626+ *
627+ * XXX we assume that in-place reindex will only be done if
628+ * IsIgnoringSystemIndexes() is true.
629+ */
630+ if (IsIgnoringSystemIndexes ())
631+ PreventTransactionChain ((void * )relation ,"REINDEX" );
632+
629633if (!reindex_relation (heapOid ,force ))
630634elog (WARNING ,"table \"%s\" wasn't reindexed" ,relation -> relname );
631635}
@@ -666,12 +670,7 @@ ReindexDatabase(const char *dbname, bool force, bool all)
666670 * transaction, then our commit- and start-transaction-command calls
667671 * would not have the intended effect!
668672 */
669- if (IsTransactionBlock ())
670- elog (ERROR ,"REINDEX DATABASE cannot run inside a BEGIN/END block" );
671-
672- /* Running this from a function would free the function context */
673- if (!MemoryContextContains (QueryContext , (void * )dbname ))
674- elog (ERROR ,"REINDEX DATABASE cannot be executed from a function" );
673+ PreventTransactionChain ((void * )dbname ,"REINDEX" );
675674
676675/*
677676 * Create a memory context that will survive forced transaction