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/executor/execUtils.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/backend/executor/execUtils.c') 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; } /* ---------------------------------------------------------------- -- cgit v1.2.3