diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2013-04-27 17:48:57 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2013-04-27 17:48:57 -0400 |
commit | 5194024d72f33fb209e10f9ab0ada7cc67df45b7 (patch) | |
tree | 81de10ef02d808084d0b62d2ed2bd609954be176 /src/backend/executor/execUtils.c | |
parent | f5d576c6d278a61beec282b9b276a3a3cb2aec50 (diff) | |
download | postgresql-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/executor/execUtils.c')
-rw-r--r-- | src/backend/executor/execUtils.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/backend/executor/execUtils.c b/src/backend/executor/execUtils.c index 11be62e9153..cf7fb72ffcf 100644 --- a/src/backend/executor/execUtils.c +++ b/src/backend/executor/execUtils.c @@ -798,8 +798,9 @@ ExecRelationIsTargetRelation(EState *estate, Index scanrelid) * ---------------------------------------------------------------- */ Relation -ExecOpenScanRelation(EState *estate, Index scanrelid) +ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags) { + Relation rel; Oid reloid; LOCKMODE lockmode; @@ -827,9 +828,24 @@ ExecOpenScanRelation(EState *estate, Index scanrelid) } } - /* OK, open the relation and acquire lock as needed */ + /* Open the relation and acquire lock as needed */ reloid = getrelid(scanrelid, estate->es_range_table); - return heap_open(reloid, lockmode); + rel = heap_open(reloid, lockmode); + + /* + * Complain if we're attempting a scan of an unscannable relation, except + * when the query won't actually be run. This is a slightly klugy place + * to do this, perhaps, but there is no better place. + */ + if ((eflags & (EXEC_FLAG_EXPLAIN_ONLY | EXEC_FLAG_WITH_NO_DATA)) == 0 && + !RelationIsScannable(rel)) + ereport(ERROR, + (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), + errmsg("materialized view \"%s\" has not been populated", + RelationGetRelationName(rel)), + errhint("Use the REFRESH MATERIALIZED VIEW command."))); + + return rel; } /* ---------------------------------------------------------------- |