]> granicus.if.org Git - postgresql/commitdiff
Acquire appropriate locks when rewriting during RMV.
authorKevin Grittner <kgrittn@postgresql.org>
Sun, 3 Nov 2013 00:18:41 +0000 (19:18 -0500)
committerKevin Grittner <kgrittn@postgresql.org>
Sun, 3 Nov 2013 00:18:41 +0000 (19:18 -0500)
Since the query has not been freshly parsed when executing REFRESH
MATERIALIZED VIEW, locks must be explicitly taken before rewrite.

Backpatch to 9.3.

Andres Freund

src/backend/commands/matview.c

index d3195fc62e5a74741f49bda8fb2ad74bd7b40cf6..f7b3244752e1298da4f56848f32e7ad915c4ddde 100644 (file)
@@ -242,9 +242,12 @@ refresh_matview_datafill(DestReceiver *dest, Query *query,
        List       *rewritten;
        PlannedStmt *plan;
        QueryDesc  *queryDesc;
+       Query      *copied_query;
 
-       /* Rewrite, copying the given Query to make sure it's not changed */
-       rewritten = QueryRewrite((Query *) copyObject(query));
+       /* Lock and rewrite, using a copy to preserve the original query. */
+       copied_query = copyObject(query);
+       AcquireRewriteLocks(copied_query, false);
+       rewritten = QueryRewrite(copied_query);
 
        /* SELECT should never rewrite to more or less than one SELECT query */
        if (list_length(rewritten) != 1)