aboutsummaryrefslogtreecommitdiff
path: root/src/backend/rewrite/rewriteHandler.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-04-27 17:48:57 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2013-04-27 17:48:57 -0400
commit5194024d72f33fb209e10f9ab0ada7cc67df45b7 (patch)
tree81de10ef02d808084d0b62d2ed2bd609954be176 /src/backend/rewrite/rewriteHandler.c
parentf5d576c6d278a61beec282b9b276a3a3cb2aec50 (diff)
downloadpostgresql-5194024d72f33fb209e10f9ab0ada7cc67df45b7.tar.gz
postgresql-5194024d72f33fb209e10f9ab0ada7cc67df45b7.zip
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.
Diffstat (limited to 'src/backend/rewrite/rewriteHandler.c')
-rw-r--r--src/backend/rewrite/rewriteHandler.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index 4209b4c6d0f..83f26e3f42e 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -1580,6 +1580,19 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
continue;
/*
+ * Always ignore RIR rules for materialized views referenced in
+ * queries. (This does not prevent refreshing MVs, since they aren't
+ * referenced in their own query definitions.)
+ *
+ * Note: in the future we might want to allow MVs to be conditionally
+ * expanded as if they were regular views, if they are not scannable.
+ * In that case this test would need to be postponed till after we've
+ * opened the rel, so that we could check its state.
+ */
+ if (rte->relkind == RELKIND_MATVIEW)
+ continue;
+
+ /*
* If the table is not referenced in the query, then we ignore it.
* This prevents infinite expansion loop due to new rtable entries
* inserted by expansion of a rule. A table is referenced if it is
@@ -1605,24 +1618,6 @@ fireRIRrules(Query *parsetree, List *activeRIRs, bool forUpdatePushedDown)
rel = heap_open(rte->relid, NoLock);
/*
- * Ignore RIR rules for a materialized view, if it is scannable.
- *
- * NOTE: This is assuming that if an MV is scannable then we always
- * want to use the existing contents, and if it is not scannable we
- * cannot have gotten to this point unless it is being populated
- * (otherwise an error should be thrown). It would be nice to have
- * some way to confirm that we're doing the right thing here, but rule
- * expansion doesn't give us a lot to work with, so we are trusting
- * earlier validations to throw error if needed.
- */
- if (rel->rd_rel->relkind == RELKIND_MATVIEW &&
- RelationIsScannable(rel))
- {
- heap_close(rel, NoLock);
- continue;
- }
-
- /*
* Collect the RIR rules that we must apply
*/
rules = rel->rd_rules;