From 5194024d72f33fb209e10f9ab0ada7cc67df45b7 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sat, 27 Apr 2013 17:48:57 -0400 Subject: Incidental cleanup of matviews code. Move checking for unscannable matviews into ExecOpenScanRelation, which is a better place for it first because the open relation is already available (saving a relcache lookup cycle), and second because this eliminates the problem of telling the difference between rangetable entries that will or will not be scanned by the query. In particular we can get rid of the not-terribly-well-thought-out-or-implemented isResultRel field that the initial matviews patch added to RangeTblEntry. Also get rid of entirely unnecessary scannability check in the rewriter, and a bogus decision about whether RefreshMatViewStmt requires a parse-time snapshot. catversion bump due to removal of a RangeTblEntry field, which changes stored rules. --- src/backend/commands/matview.c | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'src/backend/commands/matview.c') diff --git a/src/backend/commands/matview.c b/src/backend/commands/matview.c index ac7719e40da..da373045cc0 100644 --- a/src/backend/commands/matview.c +++ b/src/backend/commands/matview.c @@ -215,10 +215,8 @@ refresh_matview_datafill(DestReceiver *dest, Query *query, List *rewritten; PlannedStmt *plan; QueryDesc *queryDesc; - List *rtable; - RangeTblEntry *initial_rte; - RangeTblEntry *second_rte; + /* Rewrite, copying the given Query to make sure it's not changed */ rewritten = QueryRewrite((Query *) copyObject(query)); /* SELECT should never rewrite to more or less than one SELECT query */ @@ -229,26 +227,6 @@ refresh_matview_datafill(DestReceiver *dest, Query *query, /* Check for user-requested abort. */ CHECK_FOR_INTERRUPTS(); - /* - * Kludge here to allow refresh of a materialized view which is invalid - * (that is, it was created or refreshed WITH NO DATA. We flag the first - * two RangeTblEntry list elements, which were added to the front of the - * rewritten Query to keep the rules system happy, with the isResultRel - * flag to indicate that it is OK if they are flagged as invalid. See - * UpdateRangeTableOfViewParse() for details. - * - * NOTE: The rewrite has switched the frist two RTEs, but they are still - * in the first two positions. If that behavior changes, the asserts here - * will fail. - */ - rtable = query->rtable; - initial_rte = ((RangeTblEntry *) linitial(rtable)); - Assert(strcmp(initial_rte->alias->aliasname, "new")); - initial_rte->isResultRel = true; - second_rte = ((RangeTblEntry *) lsecond(rtable)); - Assert(strcmp(second_rte->alias->aliasname, "old")); - second_rte->isResultRel = true; - /* Plan the query which will generate data for the refresh. */ plan = pg_plan_query(query, 0, NULL); -- cgit v1.2.3