mirror of
https://github.com/postgres/postgres.git
synced 2025-07-08 11:42:09 +03:00
Add a materialized view relations.
A materialized view has a rule just like a view and a heap and other physical properties like a table. The rule is only used to populate the table, references in queries refer to the materialized data. This is a minimal implementation, but should still be useful in many cases. Currently data is only populated "on demand" by the CREATE MATERIALIZED VIEW and REFRESH MATERIALIZED VIEW statements. It is expected that future releases will add incremental updates with various timings, and that a more refined concept of defining what is "fresh" data will be developed. At some point it may even be possible to have queries use a materialized in place of references to underlying tables, but that requires the other above-mentioned features to be working first. Much of the documentation work by Robert Haas. Review by Noah Misch, Thom Brown, Robert Haas, Marko Tiikkaja Security review by KaiGai Kohei, with a decision on how best to implement sepgsql still pending.
This commit is contained in:
@ -29,6 +29,7 @@
|
||||
#include "catalog/namespace.h"
|
||||
#include "catalog/toasting.h"
|
||||
#include "commands/cluster.h"
|
||||
#include "commands/matview.h"
|
||||
#include "commands/tablecmds.h"
|
||||
#include "commands/vacuum.h"
|
||||
#include "miscadmin.h"
|
||||
@ -378,6 +379,19 @@ cluster_rel(Oid tableOid, Oid indexOid, bool recheck, bool verbose,
|
||||
if (OidIsValid(indexOid))
|
||||
check_index_is_clusterable(OldHeap, indexOid, recheck, AccessExclusiveLock);
|
||||
|
||||
/*
|
||||
* Quietly ignore the request if the a materialized view is not scannable.
|
||||
* No harm is done because there is nothing no data to deal with, and we
|
||||
* don't want to throw an error if this is part of a multi-relation
|
||||
* request -- for example, CLUSTER was run on the entire database.
|
||||
*/
|
||||
if (OldHeap->rd_rel->relkind == RELKIND_MATVIEW &&
|
||||
!OldHeap->rd_isscannable)
|
||||
{
|
||||
relation_close(OldHeap, AccessExclusiveLock);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* All predicate locks on the tuples or pages are about to be made
|
||||
* invalid, because we move tuples around. Promote them to relation
|
||||
@ -901,6 +915,10 @@ copy_heap_data(Oid OIDNewHeap, Oid OIDOldHeap, Oid OIDOldIndex,
|
||||
get_namespace_name(RelationGetNamespace(OldHeap)),
|
||||
RelationGetRelationName(OldHeap))));
|
||||
|
||||
if (OldHeap->rd_rel->relkind == RELKIND_MATVIEW)
|
||||
/* Make sure the heap looks good even if no rows are written. */
|
||||
SetRelationIsScannable(NewHeap);
|
||||
|
||||
/*
|
||||
* Scan through the OldHeap, either in OldIndex order or sequentially;
|
||||
* copy each tuple into the NewHeap, or transiently to the tuplesort
|
||||
|
Reference in New Issue
Block a user