mirror of
https://github.com/postgres/postgres.git
synced 2025-06-29 10:41:53 +03:00
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.
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user