88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.141 2000/02/24 04:34:38 inoue Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.142 2000/03/08 23:41:00 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -144,6 +144,7 @@ PortalVariableMemory CommonSpecialPortalGetMemory(void)
144144{
145145return PortalGetVariableMemory (vc_portal );
146146}
147+
147148bool CommonSpecialPortalIsOpen (void )
148149{
149150return CommonSpecialPortalInUse ;
153154vacuum (char * vacrel ,bool verbose ,bool analyze ,List * va_spec )
154155{
155156NameData VacRel ;
157+ Name VacRelName ;
156158PortalVariableMemory pmem ;
157159MemoryContext old ;
158160List * le ;
@@ -173,17 +175,22 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
173175if (IsTransactionBlock ())
174176elog (ERROR ,"VACUUM cannot run inside a BEGIN/END block" );
175177
176- /* initialize vacuum cleaner, particularly vc_portal */
177- vc_init ();
178-
179178if (verbose )
180179MESSAGE_LEVEL = NOTICE ;
181180else
182181MESSAGE_LEVEL = DEBUG ;
183182
184- /* vacrel gets de-allocated on transaction commit, so copy it */
183+ /* Create special portal for cross-transaction storage */
184+ CommonSpecialPortalOpen ();
185+
186+ /* vacrel gets de-allocated on xact commit, so copy it to safe storage */
185187if (vacrel )
186- strcpy (NameStr (VacRel ),vacrel );
188+ {
189+ namestrcpy (& VacRel ,vacrel );
190+ VacRelName = & VacRel ;
191+ }
192+ else
193+ VacRelName = NULL ;
187194
188195/* must also copy the column list, if any, to safe storage */
189196pmem = CommonSpecialPortalGetMemory ();
@@ -196,11 +203,18 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
196203}
197204MemoryContextSwitchTo (old );
198205
206+ /*
207+ * Start up the vacuum cleaner.
208+ *
209+ * NOTE: since this commits the current transaction, the memory holding
210+ * any passed-in parameters gets freed here. We must have already copied
211+ * pass-by-reference parameters to safe storage. Don't make me fix this
212+ * again!
213+ */
214+ vc_init ();
215+
199216/* vacuum the database */
200- if (vacrel )
201- vc_vacuum (& VacRel ,analyze ,va_cols );
202- else
203- vc_vacuum (NULL ,analyze ,NIL );
217+ vc_vacuum (VacRelName ,analyze ,va_cols );
204218
205219/* clean up */
206220vc_shutdown ();
@@ -229,8 +243,6 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
229243static void
230244vc_init ()
231245{
232- CommonSpecialPortalOpen ();
233-
234246/* matches the StartTransaction in PostgresMain() */
235247CommitTransactionCommand ();
236248}
@@ -252,6 +264,7 @@ vc_shutdown()
252264 */
253265unlink (RELCACHE_INIT_FILENAME );
254266
267+ /* Clean up working storage */
255268CommonSpecialPortalClose ();
256269
257270/* matches the CommitTransaction in PostgresMain() */