diff options
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; } /* ---------------------------------------------------------------- |