Set a snapshot before running analyze on a single table, to avoid a
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 28 Nov 2005 13:34:10 +0000 (13:34 +0000)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Mon, 28 Nov 2005 13:34:10 +0000 (13:34 +0000)
crash when analyzing tables with expressional indexes.

src/backend/postmaster/autovacuum.c

index cd4f27494681bdff5a6fb6a44ed9bdda513255a3..7969d8e98e5fafea241d3c86fbd3a370281442ac 100644 (file)
@@ -898,6 +898,14 @@ autovacuum_do_vac_analyze(List *relids, bool dovacuum, bool doanalyze,
        vacstmt->relation = NULL;       /* all tables, or not used if relids != NIL */
        vacstmt->va_cols = NIL;
 
+       /*
+        * Functions in indexes may want a snapshot set.  Note we only need
+        * to do this in limited cases, because it'll be done in vacuum()
+        * otherwise.
+        */
+       if (doanalyze && !dovacuum && relids != NIL)
+               ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
+
        vacuum(vacstmt, relids);
 
        pfree(vacstmt);