PostgreSQL Source Code git master
matview.c File Reference
#include "postgres.h"
#include "access/genam.h"
#include "access/heapam.h"
#include "access/htup_details.h"
#include "access/multixact.h"
#include "access/tableam.h"
#include "access/xact.h"
#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_am.h"
#include "catalog/pg_opclass.h"
#include "commands/cluster.h"
#include "commands/matview.h"
#include "commands/tablecmds.h"
#include "commands/tablespace.h"
#include "executor/executor.h"
#include "executor/spi.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "rewrite/rewriteHandler.h"
#include "storage/lmgr.h"
#include "tcop/tcopprot.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
#include "utils/rel.h"
#include "utils/snapmgr.h"
#include "utils/syscache.h"
Include dependency graph for matview.c:

Go to the source code of this file.

Data Structures

struct  DR_transientrel
 

Functions

static void transientrel_startup (DestReceiver *self, int operation, TupleDesc typeinfo)
 
static bool transientrel_receive (TupleTableSlot *slot, DestReceiver *self)
 
static void transientrel_shutdown (DestReceiver *self)
 
static void transientrel_destroy (DestReceiver *self)
 
static uint64 refresh_matview_datafill (DestReceiver *dest, Query *query, const char *queryString, bool is_create)
 
static void refresh_by_match_merge (Oid matviewOid, Oid tempOid, Oid relowner, int save_sec_context)
 
static void refresh_by_heap_swap (Oid matviewOid, Oid OIDNewHeap, char relpersistence)
 
static bool is_usable_unique_index (Relation indexRel)
 
static void OpenMatViewIncrementalMaintenance (void)
 
static void CloseMatViewIncrementalMaintenance (void)
 
void SetMatViewPopulatedState (Relation relation, bool newstate)
 
ObjectAddress ExecRefreshMatView (RefreshMatViewStmt *stmt, const char *queryString, QueryCompletion *qc)
 
ObjectAddress RefreshMatViewByOid (Oid matviewOid, bool is_create, bool skipData, bool concurrent, const char *queryString, QueryCompletion *qc)
 
DestReceiverCreateTransientRelDestReceiver (Oid transientoid)
 
bool MatViewIncrementalMaintenanceIsEnabled (void)
 

Variables

static int matview_maintenance_depth = 0
 

Function Documentation

◆ CloseMatViewIncrementalMaintenance()

static void CloseMatViewIncrementalMaintenance ( void  )
static

Definition at line 964 of file matview.c.

965{
968}
Assert(PointerIsAligned(start, uint64))
static int matview_maintenance_depth
Definition: matview.c:56

References Assert(), and matview_maintenance_depth.

Referenced by refresh_by_match_merge().

◆ CreateTransientRelDestReceiver()

DestReceiver * CreateTransientRelDestReceiver ( Oid  transientoid)

Definition at line 464 of file matview.c.

465{
467
473 self->transientoid = transientoid;
474
475 return (DestReceiver *) self;
476}
@ DestTransientRel
Definition: dest.h:97
static void transientrel_destroy(DestReceiver *self)
Definition: matview.c:553
static void transientrel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: matview.c:482
static bool transientrel_receive(TupleTableSlot *slot, DestReceiver *self)
Definition: matview.c:508
static void transientrel_shutdown(DestReceiver *self)
Definition: matview.c:536
void * palloc0(Size size)
Definition: mcxt.c:1395
DestReceiver pub
Definition: matview.c:47
Oid transientoid
Definition: matview.c:48
void(* rStartup)(DestReceiver *self, int operation, TupleDesc typeinfo)
Definition: dest.h:121
void(* rShutdown)(DestReceiver *self)
Definition: dest.h:124
bool(* receiveSlot)(TupleTableSlot *slot, DestReceiver *self)
Definition: dest.h:118
void(* rDestroy)(DestReceiver *self)
Definition: dest.h:126
CommandDest mydest
Definition: dest.h:128

References DestTransientRel, _DestReceiver::mydest, palloc0(), DR_transientrel::pub, _DestReceiver::rDestroy, _DestReceiver::receiveSlot, _DestReceiver::rShutdown, _DestReceiver::rStartup, DR_transientrel::transientoid, transientrel_destroy(), transientrel_receive(), transientrel_shutdown(), and transientrel_startup().

Referenced by CreateDestReceiver(), and RefreshMatViewByOid().

◆ ExecRefreshMatView()

ObjectAddress ExecRefreshMatView ( RefreshMatViewStmt stmt,
const char *  queryString,
QueryCompletion qc 
)

Definition at line 120 of file matview.c.

122{
123 Oid matviewOid;
124 LOCKMODE lockmode;
125
126 /* Determine strength of lock needed. */
127 lockmode = stmt->concurrent ? ExclusiveLock : AccessExclusiveLock;
128
129 /*
130 * Get a lock until end of transaction.
131 */
132 matviewOid = RangeVarGetRelidExtended(stmt->relation,
133 lockmode, 0,
135 NULL);
136
137 return RefreshMatViewByOid(matviewOid, false, stmt->skipData,
138 stmt->concurrent, queryString, qc);
139}
#define stmt
Definition: indent_codes.h:59
int LOCKMODE
Definition: lockdefs.h:26
#define AccessExclusiveLock
Definition: lockdefs.h:43
#define ExclusiveLock
Definition: lockdefs.h:42
ObjectAddress RefreshMatViewByOid(Oid matviewOid, bool is_create, bool skipData, bool concurrent, const char *queryString, QueryCompletion *qc)
Definition: matview.c:164
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
Definition: namespace.c:440
unsigned int Oid
Definition: postgres_ext.h:32
void RangeVarCallbackMaintainsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
Definition: tablecmds.c:19484

References AccessExclusiveLock, ExclusiveLock, RangeVarCallbackMaintainsTable(), RangeVarGetRelidExtended(), RefreshMatViewByOid(), and stmt.

Referenced by ProcessUtilitySlow().

◆ is_usable_unique_index()

static bool is_usable_unique_index ( Relation  indexRel)
static

Definition at line 903 of file matview.c.

904{
905 Form_pg_index indexStruct = indexRel->rd_index;
906
907 /*
908 * Must be unique, valid, immediate, non-partial, and be defined over
909 * plain user columns (not expressions).
910 */
911 if (indexStruct->indisunique &&
912 indexStruct->indimmediate &&
913 indexStruct->indisvalid &&
914 RelationGetIndexPredicate(indexRel) == NIL &&
915 indexStruct->indnatts > 0)
916 {
917 /*
918 * The point of groveling through the index columns individually is to
919 * reject both index expressions and system columns. Currently,
920 * matviews couldn't have OID columns so there's no way to create an
921 * index on a system column; but maybe someday that wouldn't be true,
922 * so let's be safe.
923 */
924 int numatts = indexStruct->indnatts;
925 int i;
926
927 for (i = 0; i < numatts; i++)
928 {
929 int attnum = indexStruct->indkey.values[i];
930
931 if (attnum <= 0)
932 return false;
933 }
934 return true;
935 }
936 return false;
937}
int i
Definition: isn.c:77
int16 attnum
Definition: pg_attribute.h:74
FormData_pg_index * Form_pg_index
Definition: pg_index.h:70
#define NIL
Definition: pg_list.h:68
List * RelationGetIndexPredicate(Relation relation)
Definition: relcache.c:5210
Form_pg_index rd_index
Definition: rel.h:192

References attnum, i, NIL, RelationData::rd_index, and RelationGetIndexPredicate().

Referenced by refresh_by_match_merge(), and RefreshMatViewByOid().

◆ MatViewIncrementalMaintenanceIsEnabled()

bool MatViewIncrementalMaintenanceIsEnabled ( void  )

Definition at line 952 of file matview.c.

953{
954 return matview_maintenance_depth > 0;
955}

References matview_maintenance_depth.

Referenced by CheckValidResultRel().

◆ OpenMatViewIncrementalMaintenance()

static void OpenMatViewIncrementalMaintenance ( void  )
static

Definition at line 958 of file matview.c.

959{
961}

References matview_maintenance_depth.

Referenced by refresh_by_match_merge().

◆ refresh_by_heap_swap()

static void refresh_by_heap_swap ( Oid  matviewOid,
Oid  OIDNewHeap,
char  relpersistence 
)
static

Definition at line 893 of file matview.c.

894{
895 finish_heap_swap(matviewOid, OIDNewHeap, false, false, true, true,
896 RecentXmin, ReadNextMultiXactId(), relpersistence);
897}
void finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap, bool is_system_catalog, bool swap_toast_by_content, bool check_constraints, bool is_internal, TransactionId frozenXid, MultiXactId cutoffMulti, char newrelpersistence)
Definition: cluster.c:1445
MultiXactId ReadNextMultiXactId(void)
Definition: multixact.c:762
TransactionId RecentXmin
Definition: snapmgr.c:160

References finish_heap_swap(), ReadNextMultiXactId(), and RecentXmin.

Referenced by RefreshMatViewByOid().

◆ refresh_by_match_merge()

static void refresh_by_match_merge ( Oid  matviewOid,
Oid  tempOid,
Oid  relowner,
int  save_sec_context 
)
static

Definition at line 591 of file matview.c.

593{
594 StringInfoData querybuf;
595 Relation matviewRel;
596 Relation tempRel;
597 char *matviewname;
598 char *tempname;
599 char *diffname;
600 char *temprelname;
601 char *diffrelname;
602 char *nsp;
603 TupleDesc tupdesc;
604 bool foundUniqueIndex;
605 List *indexoidlist;
606 ListCell *indexoidscan;
607 int16 relnatts;
608 Oid *opUsedForQual;
609
610 initStringInfo(&querybuf);
611 matviewRel = table_open(matviewOid, NoLock);
613 RelationGetRelationName(matviewRel));
614 tempRel = table_open(tempOid, NoLock);
615
616 /*
617 * Build qualified names of the temporary table and the diff table. The
618 * only difference between them is the "_2" suffix on the diff table name.
619 */
621 temprelname = RelationGetRelationName(tempRel);
622 diffrelname = psprintf("%s_2", temprelname);
623
624 tempname = quote_qualified_identifier(nsp, temprelname);
625 diffname = quote_qualified_identifier(nsp, diffrelname);
626
627 relnatts = RelationGetNumberOfAttributes(matviewRel);
628
629 /* Open SPI context. */
630 SPI_connect();
631
632 /* Analyze the temp table with the new contents. */
633 appendStringInfo(&querybuf, "ANALYZE %s", tempname);
634 if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY)
635 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
636
637 /*
638 * We need to ensure that there are not duplicate rows without NULLs in
639 * the new data set before we can count on the "diff" results. Check for
640 * that in a way that allows showing the first duplicated row found. Even
641 * after we pass this test, a unique index on the materialized view may
642 * find a duplicate key problem.
643 *
644 * Note: here and below, we use "tablename.*::tablerowtype" as a hack to
645 * keep ".*" from being expanded into multiple columns in a SELECT list.
646 * Compare ruleutils.c's get_variable().
647 */
648 resetStringInfo(&querybuf);
649 appendStringInfo(&querybuf,
650 "SELECT newdata.*::%s FROM %s newdata "
651 "WHERE newdata.* IS NOT NULL AND EXISTS "
652 "(SELECT 1 FROM %s newdata2 WHERE newdata2.* IS NOT NULL "
653 "AND newdata2.* OPERATOR(pg_catalog.*=) newdata.* "
654 "AND newdata2.ctid OPERATOR(pg_catalog.<>) "
655 "newdata.ctid)",
656 tempname, tempname, tempname);
657 if (SPI_execute(querybuf.data, false, 1) != SPI_OK_SELECT)
658 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
659 if (SPI_processed > 0)
660 {
661 /*
662 * Note that this ereport() is returning data to the user. Generally,
663 * we would want to make sure that the user has been granted access to
664 * this data. However, REFRESH MAT VIEW is only able to be run by the
665 * owner of the mat view (or a superuser) and therefore there is no
666 * need to check for access to data in the mat view.
667 */
669 (errcode(ERRCODE_CARDINALITY_VIOLATION),
670 errmsg("new data for materialized view \"%s\" contains duplicate rows without any null columns",
671 RelationGetRelationName(matviewRel)),
672 errdetail("Row: %s",
674 }
675
676 /*
677 * Create the temporary "diff" table.
678 *
679 * Temporarily switch out of the SECURITY_RESTRICTED_OPERATION context,
680 * because you cannot create temp tables in SRO context. For extra
681 * paranoia, add the composite type column only after switching back to
682 * SRO context.
683 */
684 SetUserIdAndSecContext(relowner,
685 save_sec_context | SECURITY_LOCAL_USERID_CHANGE);
686 resetStringInfo(&querybuf);
687 appendStringInfo(&querybuf,
688 "CREATE TEMP TABLE %s (tid pg_catalog.tid)",
689 diffname);
690 if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY)
691 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
692 SetUserIdAndSecContext(relowner,
693 save_sec_context | SECURITY_RESTRICTED_OPERATION);
694 resetStringInfo(&querybuf);
695 appendStringInfo(&querybuf,
696 "ALTER TABLE %s ADD COLUMN newdata %s",
697 diffname, tempname);
698 if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY)
699 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
700
701 /* Start building the query for populating the diff table. */
702 resetStringInfo(&querybuf);
703 appendStringInfo(&querybuf,
704 "INSERT INTO %s "
705 "SELECT mv.ctid AS tid, newdata.*::%s AS newdata "
706 "FROM %s mv FULL JOIN %s newdata ON (",
707 diffname, tempname, matviewname, tempname);
708
709 /*
710 * Get the list of index OIDs for the table from the relcache, and look up
711 * each one in the pg_index syscache. We will test for equality on all
712 * columns present in all unique indexes which only reference columns and
713 * include all rows.
714 */
715 tupdesc = matviewRel->rd_att;
716 opUsedForQual = (Oid *) palloc0(sizeof(Oid) * relnatts);
717 foundUniqueIndex = false;
718
719 indexoidlist = RelationGetIndexList(matviewRel);
720
721 foreach(indexoidscan, indexoidlist)
722 {
723 Oid indexoid = lfirst_oid(indexoidscan);
724 Relation indexRel;
725
726 indexRel = index_open(indexoid, RowExclusiveLock);
727 if (is_usable_unique_index(indexRel))
728 {
729 Form_pg_index indexStruct = indexRel->rd_index;
730 int indnkeyatts = indexStruct->indnkeyatts;
731 oidvector *indclass;
732 Datum indclassDatum;
733 int i;
734
735 /* Must get indclass the hard way. */
736 indclassDatum = SysCacheGetAttrNotNull(INDEXRELID,
737 indexRel->rd_indextuple,
738 Anum_pg_index_indclass);
739 indclass = (oidvector *) DatumGetPointer(indclassDatum);
740
741 /* Add quals for all columns from this index. */
742 for (i = 0; i < indnkeyatts; i++)
743 {
744 int attnum = indexStruct->indkey.values[i];
745 Oid opclass = indclass->values[i];
746 Form_pg_attribute attr = TupleDescAttr(tupdesc, attnum - 1);
747 Oid attrtype = attr->atttypid;
748 HeapTuple cla_ht;
749 Form_pg_opclass cla_tup;
750 Oid opfamily;
751 Oid opcintype;
752 Oid op;
753 const char *leftop;
754 const char *rightop;
755
756 /*
757 * Identify the equality operator associated with this index
758 * column. First we need to look up the column's opclass.
759 */
760 cla_ht = SearchSysCache1(CLAOID, ObjectIdGetDatum(opclass));
761 if (!HeapTupleIsValid(cla_ht))
762 elog(ERROR, "cache lookup failed for opclass %u", opclass);
763 cla_tup = (Form_pg_opclass) GETSTRUCT(cla_ht);
764 opfamily = cla_tup->opcfamily;
765 opcintype = cla_tup->opcintype;
766 ReleaseSysCache(cla_ht);
767
768 op = get_opfamily_member_for_cmptype(opfamily, opcintype, opcintype, COMPARE_EQ);
769 if (!OidIsValid(op))
770 elog(ERROR, "missing equality operator for (%u,%u) in opfamily %u",
771 opcintype, opcintype, opfamily);
772
773 /*
774 * If we find the same column with the same equality semantics
775 * in more than one index, we only need to emit the equality
776 * clause once.
777 *
778 * Since we only remember the last equality operator, this
779 * code could be fooled into emitting duplicate clauses given
780 * multiple indexes with several different opclasses ... but
781 * that's so unlikely it doesn't seem worth spending extra
782 * code to avoid.
783 */
784 if (opUsedForQual[attnum - 1] == op)
785 continue;
786 opUsedForQual[attnum - 1] = op;
787
788 /*
789 * Actually add the qual, ANDed with any others.
790 */
791 if (foundUniqueIndex)
792 appendStringInfoString(&querybuf, " AND ");
793
794 leftop = quote_qualified_identifier("newdata",
795 NameStr(attr->attname));
796 rightop = quote_qualified_identifier("mv",
797 NameStr(attr->attname));
798
799 generate_operator_clause(&querybuf,
800 leftop, attrtype,
801 op,
802 rightop, attrtype);
803
804 foundUniqueIndex = true;
805 }
806 }
807
808 /* Keep the locks, since we're about to run DML which needs them. */
809 index_close(indexRel, NoLock);
810 }
811
812 list_free(indexoidlist);
813
814 /*
815 * There must be at least one usable unique index on the matview.
816 *
817 * ExecRefreshMatView() checks that after taking the exclusive lock on the
818 * matview. So at least one unique index is guaranteed to exist here
819 * because the lock is still being held. (One known exception is if a
820 * function called as part of refreshing the matview drops the index.
821 * That's a pretty silly thing to do.)
822 */
823 if (!foundUniqueIndex)
825 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
826 errmsg("could not find suitable unique index on materialized view \"%s\"",
827 RelationGetRelationName(matviewRel)));
828
829 appendStringInfoString(&querybuf,
830 " AND newdata.* OPERATOR(pg_catalog.*=) mv.*) "
831 "WHERE newdata.* IS NULL OR mv.* IS NULL "
832 "ORDER BY tid");
833
834 /* Populate the temporary "diff" table. */
835 if (SPI_exec(querybuf.data, 0) != SPI_OK_INSERT)
836 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
837
838 /*
839 * We have no further use for data from the "full-data" temp table, but we
840 * must keep it around because its type is referenced from the diff table.
841 */
842
843 /* Analyze the diff table. */
844 resetStringInfo(&querybuf);
845 appendStringInfo(&querybuf, "ANALYZE %s", diffname);
846 if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY)
847 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
848
850
851 /* Deletes must come before inserts; do them first. */
852 resetStringInfo(&querybuf);
853 appendStringInfo(&querybuf,
854 "DELETE FROM %s mv WHERE ctid OPERATOR(pg_catalog.=) ANY "
855 "(SELECT diff.tid FROM %s diff "
856 "WHERE diff.tid IS NOT NULL "
857 "AND diff.newdata IS NULL)",
858 matviewname, diffname);
859 if (SPI_exec(querybuf.data, 0) != SPI_OK_DELETE)
860 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
861
862 /* Inserts go last. */
863 resetStringInfo(&querybuf);
864 appendStringInfo(&querybuf,
865 "INSERT INTO %s SELECT (diff.newdata).* "
866 "FROM %s diff WHERE tid IS NULL",
867 matviewname, diffname);
868 if (SPI_exec(querybuf.data, 0) != SPI_OK_INSERT)
869 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
870
871 /* We're done maintaining the materialized view. */
873 table_close(tempRel, NoLock);
874 table_close(matviewRel, NoLock);
875
876 /* Clean up temp tables. */
877 resetStringInfo(&querybuf);
878 appendStringInfo(&querybuf, "DROP TABLE %s, %s", diffname, tempname);
879 if (SPI_exec(querybuf.data, 0) != SPI_OK_UTILITY)
880 elog(ERROR, "SPI_exec failed: %s", querybuf.data);
881
882 /* Close SPI context. */
883 if (SPI_finish() != SPI_OK_FINISH)
884 elog(ERROR, "SPI_finish failed");
885}
#define NameStr(name)
Definition: c.h:756
int16_t int16
Definition: c.h:538
#define OidIsValid(objectId)
Definition: c.h:779
@ COMPARE_EQ
Definition: cmptype.h:36
int errdetail(const char *fmt,...)
Definition: elog.c:1216
int errcode(int sqlerrcode)
Definition: elog.c:863
int errmsg(const char *fmt,...)
Definition: elog.c:1080
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define ereport(elevel,...)
Definition: elog.h:150
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
Definition: htup_details.h:728
void index_close(Relation relation, LOCKMODE lockmode)
Definition: indexam.c:177
Relation index_open(Oid relationId, LOCKMODE lockmode)
Definition: indexam.c:133
void list_free(List *list)
Definition: list.c:1546
#define NoLock
Definition: lockdefs.h:34
#define RowExclusiveLock
Definition: lockdefs.h:38
Oid get_opfamily_member_for_cmptype(Oid opfamily, Oid lefttype, Oid righttype, CompareType cmptype)
Definition: lsyscache.c:197
char * get_namespace_name(Oid nspid)
Definition: lsyscache.c:3533
static bool is_usable_unique_index(Relation indexRel)
Definition: matview.c:903
static void CloseMatViewIncrementalMaintenance(void)
Definition: matview.c:964
static void OpenMatViewIncrementalMaintenance(void)
Definition: matview.c:958
#define SECURITY_RESTRICTED_OPERATION
Definition: miscadmin.h:319
#define SECURITY_LOCAL_USERID_CHANGE
Definition: miscadmin.h:318
void SetUserIdAndSecContext(Oid userid, int sec_context)
Definition: miscinit.c:619
FormData_pg_attribute * Form_pg_attribute
Definition: pg_attribute.h:202
#define lfirst_oid(lc)
Definition: pg_list.h:174
FormData_pg_opclass * Form_pg_opclass
Definition: pg_opclass.h:83
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
uint64_t Datum
Definition: postgres.h:70
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:322
char * psprintf(const char *fmt,...)
Definition: psprintf.c:43
#define RelationGetNumberOfAttributes(relation)
Definition: rel.h:521
#define RelationGetRelationName(relation)
Definition: rel.h:549
#define RelationGetNamespace(relation)
Definition: rel.h:556
List * RelationGetIndexList(Relation relation)
Definition: relcache.c:4836
char * quote_qualified_identifier(const char *qualifier, const char *ident)
Definition: ruleutils.c:13146
void generate_operator_clause(StringInfo buf, const char *leftop, Oid leftoptype, Oid opoid, const char *rightop, Oid rightoptype)
Definition: ruleutils.c:13474
uint64 SPI_processed
Definition: spi.c:44
SPITupleTable * SPI_tuptable
Definition: spi.c:45
int SPI_connect(void)
Definition: spi.c:94
int SPI_finish(void)
Definition: spi.c:182
int SPI_exec(const char *src, long tcount)
Definition: spi.c:630
char * SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
Definition: spi.c:1220
int SPI_execute(const char *src, bool read_only, long tcount)
Definition: spi.c:596
#define SPI_OK_UTILITY
Definition: spi.h:85
#define SPI_OK_INSERT
Definition: spi.h:88
#define SPI_OK_DELETE
Definition: spi.h:89
#define SPI_OK_FINISH
Definition: spi.h:83
#define SPI_OK_SELECT
Definition: spi.h:86
void resetStringInfo(StringInfo str)
Definition: stringinfo.c:126
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:230
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
Definition: pg_list.h:54
struct HeapTupleData * rd_indextuple
Definition: rel.h:194
TupleDesc rd_att
Definition: rel.h:112
TupleDesc tupdesc
Definition: spi.h:25
HeapTuple * vals
Definition: spi.h:26
Definition: c.h:736
Oid values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:743
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:264
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:220
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
Definition: syscache.c:625
void table_close(Relation relation, LOCKMODE lockmode)
Definition: table.c:126
Relation table_open(Oid relationId, LOCKMODE lockmode)
Definition: table.c:40
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
Definition: tupdesc.h:160

References appendStringInfo(), appendStringInfoString(), attnum, CloseMatViewIncrementalMaintenance(), COMPARE_EQ, StringInfoData::data, DatumGetPointer(), elog, ereport, errcode(), errdetail(), errmsg(), ERROR, generate_operator_clause(), get_namespace_name(), get_opfamily_member_for_cmptype(), GETSTRUCT(), HeapTupleIsValid, i, index_close(), index_open(), initStringInfo(), is_usable_unique_index(), lfirst_oid, list_free(), NameStr, NoLock, ObjectIdGetDatum(), OidIsValid, OpenMatViewIncrementalMaintenance(), palloc0(), psprintf(), quote_qualified_identifier(), RelationData::rd_att, RelationData::rd_index, RelationData::rd_indextuple, RelationGetIndexList(), RelationGetNamespace, RelationGetNumberOfAttributes, RelationGetRelationName, ReleaseSysCache(), resetStringInfo(), RowExclusiveLock, SearchSysCache1(), SECURITY_LOCAL_USERID_CHANGE, SECURITY_RESTRICTED_OPERATION, SetUserIdAndSecContext(), SPI_connect(), SPI_exec(), SPI_execute(), SPI_finish(), SPI_getvalue(), SPI_OK_DELETE, SPI_OK_FINISH, SPI_OK_INSERT, SPI_OK_SELECT, SPI_OK_UTILITY, SPI_processed, SPI_tuptable, SysCacheGetAttrNotNull(), table_close(), table_open(), SPITupleTable::tupdesc, TupleDescAttr(), SPITupleTable::vals, and oidvector::values.

Referenced by RefreshMatViewByOid().

◆ refresh_matview_datafill()

static uint64 refresh_matview_datafill ( DestReceiver dest,
Query query,
const char *  queryString,
bool  is_create 
)
static

Definition at line 404 of file matview.c.

406{
407 List *rewritten;
409 QueryDesc *queryDesc;
410 Query *copied_query;
411 uint64 processed;
412
413 /* Lock and rewrite, using a copy to preserve the original query. */
414 copied_query = copyObject(query);
415 AcquireRewriteLocks(copied_query, true, false);
416 rewritten = QueryRewrite(copied_query);
417
418 /* SELECT should never rewrite to more or less than one SELECT query */
419 if (list_length(rewritten) != 1)
420 elog(ERROR, "unexpected rewrite result for %s",
421 is_create ? "CREATE MATERIALIZED VIEW " : "REFRESH MATERIALIZED VIEW");
422 query = (Query *) linitial(rewritten);
423
424 /* Check for user-requested abort. */
426
427 /* Plan the query which will generate data for the refresh. */
428 plan = pg_plan_query(query, queryString, CURSOR_OPT_PARALLEL_OK, NULL, NULL);
429
430 /*
431 * Use a snapshot with an updated command ID to ensure this query sees
432 * results of any previously executed queries. (This could only matter if
433 * the planner executed an allegedly-stable function that changed the
434 * database contents, but let's do it anyway to be safe.)
435 */
438
439 /* Create a QueryDesc, redirecting output to our tuple receiver */
440 queryDesc = CreateQueryDesc(plan, queryString,
442 dest, NULL, NULL, 0);
443
444 /* call ExecutorStart to prepare the plan for execution */
445 ExecutorStart(queryDesc, 0);
446
447 /* run the plan */
448 ExecutorRun(queryDesc, ForwardScanDirection, 0);
449
450 processed = queryDesc->estate->es_processed;
451
452 /* and clean up */
453 ExecutorFinish(queryDesc);
454 ExecutorEnd(queryDesc);
455
456 FreeQueryDesc(queryDesc);
457
459
460 return processed;
461}
uint64_t uint64
Definition: c.h:544
void ExecutorEnd(QueryDesc *queryDesc)
Definition: execMain.c:466
void ExecutorFinish(QueryDesc *queryDesc)
Definition: execMain.c:406
void ExecutorStart(QueryDesc *queryDesc, int eflags)
Definition: execMain.c:122
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count)
Definition: execMain.c:297
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:123
#define copyObject(obj)
Definition: nodes.h:232
#define CURSOR_OPT_PARALLEL_OK
Definition: parsenodes.h:3396
static int list_length(const List *l)
Definition: pg_list.h:152
#define linitial(l)
Definition: pg_list.h:178
#define plan(x)
Definition: pg_regress.c:161
PlannedStmt * pg_plan_query(Query *querytree, const char *query_string, int cursorOptions, ParamListInfo boundParams, ExplainState *es)
Definition: postgres.c:887
void FreeQueryDesc(QueryDesc *qdesc)
Definition: pquery.c:106
QueryDesc * CreateQueryDesc(PlannedStmt *plannedstmt, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, QueryEnvironment *queryEnv, int instrument_options)
Definition: pquery.c:68
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
List * QueryRewrite(Query *parsetree)
@ ForwardScanDirection
Definition: sdir.h:28
void UpdateActiveSnapshotCommandId(void)
Definition: snapmgr.c:745
void PopActiveSnapshot(void)
Definition: snapmgr.c:776
void PushCopiedSnapshot(Snapshot snapshot)
Definition: snapmgr.c:733
Snapshot GetActiveSnapshot(void)
Definition: snapmgr.c:801
#define InvalidSnapshot
Definition: snapshot.h:119
uint64 es_processed
Definition: execnodes.h:714
EState * estate
Definition: execdesc.h:48

References AcquireRewriteLocks(), CHECK_FOR_INTERRUPTS, copyObject, CreateQueryDesc(), CURSOR_OPT_PARALLEL_OK, generate_unaccent_rules::dest, elog, ERROR, EState::es_processed, QueryDesc::estate, ExecutorEnd(), ExecutorFinish(), ExecutorRun(), ExecutorStart(), ForwardScanDirection, FreeQueryDesc(), GetActiveSnapshot(), InvalidSnapshot, linitial, list_length(), pg_plan_query(), plan, PopActiveSnapshot(), PushCopiedSnapshot(), QueryRewrite(), and UpdateActiveSnapshotCommandId().

Referenced by RefreshMatViewByOid().

◆ RefreshMatViewByOid()

ObjectAddress RefreshMatViewByOid ( Oid  matviewOid,
bool  is_create,
bool  skipData,
bool  concurrent,
const char *  queryString,
QueryCompletion qc 
)

Definition at line 164 of file matview.c.

167{
168 Relation matviewRel;
170 List *actions;
171 Query *dataQuery;
172 Oid tableSpace;
173 Oid relowner;
174 Oid OIDNewHeap;
175 uint64 processed = 0;
176 char relpersistence;
177 Oid save_userid;
178 int save_sec_context;
179 int save_nestlevel;
180 ObjectAddress address;
181
182 matviewRel = table_open(matviewOid, NoLock);
183 relowner = matviewRel->rd_rel->relowner;
184
185 /*
186 * Switch to the owner's userid, so that any functions are run as that
187 * user. Also lock down security-restricted operations and arrange to
188 * make GUC variable changes local to this command.
189 */
190 GetUserIdAndSecContext(&save_userid, &save_sec_context);
191 SetUserIdAndSecContext(relowner,
192 save_sec_context | SECURITY_RESTRICTED_OPERATION);
193 save_nestlevel = NewGUCNestLevel();
195
196 /* Make sure it is a materialized view. */
197 if (matviewRel->rd_rel->relkind != RELKIND_MATVIEW)
199 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
200 errmsg("\"%s\" is not a materialized view",
201 RelationGetRelationName(matviewRel))));
202
203 /* Check that CONCURRENTLY is not specified if not populated. */
204 if (concurrent && !RelationIsPopulated(matviewRel))
206 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
207 errmsg("CONCURRENTLY cannot be used when the materialized view is not populated")));
208
209 /* Check that conflicting options have not been specified. */
210 if (concurrent && skipData)
212 (errcode(ERRCODE_SYNTAX_ERROR),
213 errmsg("%s and %s options cannot be used together",
214 "CONCURRENTLY", "WITH NO DATA")));
215
216 /*
217 * Check that everything is correct for a refresh. Problems at this point
218 * are internal errors, so elog is sufficient.
219 */
220 if (matviewRel->rd_rel->relhasrules == false ||
221 matviewRel->rd_rules->numLocks < 1)
222 elog(ERROR,
223 "materialized view \"%s\" is missing rewrite information",
224 RelationGetRelationName(matviewRel));
225
226 if (matviewRel->rd_rules->numLocks > 1)
227 elog(ERROR,
228 "materialized view \"%s\" has too many rules",
229 RelationGetRelationName(matviewRel));
230
231 rule = matviewRel->rd_rules->rules[0];
232 if (rule->event != CMD_SELECT || !(rule->isInstead))
233 elog(ERROR,
234 "the rule for materialized view \"%s\" is not a SELECT INSTEAD OF rule",
235 RelationGetRelationName(matviewRel));
236
237 actions = rule->actions;
238 if (list_length(actions) != 1)
239 elog(ERROR,
240 "the rule for materialized view \"%s\" is not a single action",
241 RelationGetRelationName(matviewRel));
242
243 /*
244 * Check that there is a unique index with no WHERE clause on one or more
245 * columns of the materialized view if CONCURRENTLY is specified.
246 */
247 if (concurrent)
248 {
249 List *indexoidlist = RelationGetIndexList(matviewRel);
250 ListCell *indexoidscan;
251 bool hasUniqueIndex = false;
252
253 Assert(!is_create);
254
255 foreach(indexoidscan, indexoidlist)
256 {
257 Oid indexoid = lfirst_oid(indexoidscan);
258 Relation indexRel;
259
260 indexRel = index_open(indexoid, AccessShareLock);
261 hasUniqueIndex = is_usable_unique_index(indexRel);
262 index_close(indexRel, AccessShareLock);
263 if (hasUniqueIndex)
264 break;
265 }
266
267 list_free(indexoidlist);
268
269 if (!hasUniqueIndex)
271 (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
272 errmsg("cannot refresh materialized view \"%s\" concurrently",
274 RelationGetRelationName(matviewRel))),
275 errhint("Create a unique index with no WHERE clause on one or more columns of the materialized view.")));
276 }
277
278 /*
279 * The stored query was rewritten at the time of the MV definition, but
280 * has not been scribbled on by the planner.
281 */
282 dataQuery = linitial_node(Query, actions);
283
284 /*
285 * Check for active uses of the relation in the current transaction, such
286 * as open scans.
287 *
288 * NB: We count on this to protect us against problems with refreshing the
289 * data using TABLE_INSERT_FROZEN.
290 */
291 CheckTableNotInUse(matviewRel,
292 is_create ? "CREATE MATERIALIZED VIEW" :
293 "REFRESH MATERIALIZED VIEW");
294
295 /*
296 * Tentatively mark the matview as populated or not (this will roll back
297 * if we fail later).
298 */
299 SetMatViewPopulatedState(matviewRel, !skipData);
300
301 /* Concurrent refresh builds new data in temp tablespace, and does diff. */
302 if (concurrent)
303 {
304 tableSpace = GetDefaultTablespace(RELPERSISTENCE_TEMP, false);
305 relpersistence = RELPERSISTENCE_TEMP;
306 }
307 else
308 {
309 tableSpace = matviewRel->rd_rel->reltablespace;
310 relpersistence = matviewRel->rd_rel->relpersistence;
311 }
312
313 /*
314 * Create the transient table that will receive the regenerated data. Lock
315 * it against access by any other process until commit (by which time it
316 * will be gone).
317 */
318 OIDNewHeap = make_new_heap(matviewOid, tableSpace,
319 matviewRel->rd_rel->relam,
320 relpersistence, ExclusiveLock);
322
323 /* Generate the data, if wanted. */
324 if (!skipData)
325 {
327
329 processed = refresh_matview_datafill(dest, dataQuery, queryString,
330 is_create);
331 }
332
333 /* Make the matview match the newly generated data. */
334 if (concurrent)
335 {
336 int old_depth = matview_maintenance_depth;
337
338 PG_TRY();
339 {
340 refresh_by_match_merge(matviewOid, OIDNewHeap, relowner,
341 save_sec_context);
342 }
343 PG_CATCH();
344 {
345 matview_maintenance_depth = old_depth;
346 PG_RE_THROW();
347 }
348 PG_END_TRY();
349 Assert(matview_maintenance_depth == old_depth);
350 }
351 else
352 {
353 refresh_by_heap_swap(matviewOid, OIDNewHeap, relpersistence);
354
355 /*
356 * Inform cumulative stats system about our activity: basically, we
357 * truncated the matview and inserted some new data. (The concurrent
358 * code path above doesn't need to worry about this because the
359 * inserts and deletes it issues get counted by lower-level code.)
360 */
361 pgstat_count_truncate(matviewRel);
362 if (!skipData)
363 pgstat_count_heap_insert(matviewRel, processed);
364 }
365
366 table_close(matviewRel, NoLock);
367
368 /* Roll back any GUC changes */
369 AtEOXact_GUC(false, save_nestlevel);
370
371 /* Restore userid and security context */
372 SetUserIdAndSecContext(save_userid, save_sec_context);
373
374 ObjectAddressSet(address, RelationRelationId, matviewOid);
375
376 /*
377 * Save the rowcount so that pg_stat_statements can track the total number
378 * of rows processed by REFRESH MATERIALIZED VIEW command. Note that we
379 * still don't display the rowcount in the command completion tag output,
380 * i.e., the display_rowcount flag of CMDTAG_REFRESH_MATERIALIZED_VIEW
381 * command tag is left false in cmdtaglist.h. Otherwise, the change of
382 * completion tag output might break applications using it.
383 *
384 * When called from CREATE MATERIALIZED VIEW command, the rowcount is
385 * displayed with the command tag CMDTAG_SELECT.
386 */
387 if (qc)
389 is_create ? CMDTAG_SELECT : CMDTAG_REFRESH_MATERIALIZED_VIEW,
390 processed);
391
392 return address;
393}
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
Definition: tablespace.c:1143
Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, char relpersistence, LOCKMODE lockmode)
Definition: cluster.c:705
static void SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
Definition: cmdtag.h:37
int errhint(const char *fmt,...)
Definition: elog.c:1330
#define PG_RE_THROW()
Definition: elog.h:405
#define PG_TRY(...)
Definition: elog.h:372
#define PG_END_TRY(...)
Definition: elog.h:397
#define PG_CATCH(...)
Definition: elog.h:382
int NewGUCNestLevel(void)
Definition: guc.c:2110
void RestrictSearchPath(void)
Definition: guc.c:2121
void AtEOXact_GUC(bool isCommit, int nestLevel)
Definition: guc.c:2137
bool CheckRelationOidLockedByMe(Oid relid, LOCKMODE lockmode, bool orstronger)
Definition: lmgr.c:351
#define AccessShareLock
Definition: lockdefs.h:36
DestReceiver * CreateTransientRelDestReceiver(Oid transientoid)
Definition: matview.c:464
static void refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, int save_sec_context)
Definition: matview.c:591
static uint64 refresh_matview_datafill(DestReceiver *dest, Query *query, const char *queryString, bool is_create)
Definition: matview.c:404
void SetMatViewPopulatedState(Relation relation, bool newstate)
Definition: matview.c:78
static void refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap, char relpersistence)
Definition: matview.c:893
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
Definition: miscinit.c:612
@ CMD_SELECT
Definition: nodes.h:275
#define ObjectAddressSet(addr, class_id, object_id)
Definition: objectaddress.h:40
#define linitial_node(type, l)
Definition: pg_list.h:181
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
void pgstat_count_truncate(Relation rel)
#define RelationIsPopulated(relation)
Definition: rel.h:687
RuleLock * rd_rules
Definition: rel.h:115
Form_pg_class rd_rel
Definition: rel.h:111
RewriteRule ** rules
Definition: prs2lock.h:43
int numLocks
Definition: prs2lock.h:42
Definition: localtime.c:73
void CheckTableNotInUse(Relation rel, const char *stmt)
Definition: tablecmds.c:4408

References AccessExclusiveLock, AccessShareLock, Assert(), AtEOXact_GUC(), CheckRelationOidLockedByMe(), CheckTableNotInUse(), CMD_SELECT, CreateTransientRelDestReceiver(), generate_unaccent_rules::dest, elog, ereport, errcode(), errhint(), errmsg(), ERROR, ExclusiveLock, get_namespace_name(), GetDefaultTablespace(), GetUserIdAndSecContext(), index_close(), index_open(), is_usable_unique_index(), lfirst_oid, linitial_node, list_free(), list_length(), make_new_heap(), matview_maintenance_depth, NewGUCNestLevel(), NoLock, RuleLock::numLocks, ObjectAddressSet, PG_CATCH, PG_END_TRY, PG_RE_THROW, PG_TRY, pgstat_count_heap_insert(), pgstat_count_truncate(), quote_qualified_identifier(), RelationData::rd_rel, RelationData::rd_rules, refresh_by_heap_swap(), refresh_by_match_merge(), refresh_matview_datafill(), RelationGetIndexList(), RelationGetNamespace, RelationGetRelationName, RelationIsPopulated, RestrictSearchPath(), RuleLock::rules, SECURITY_RESTRICTED_OPERATION, SetMatViewPopulatedState(), SetQueryCompletion(), SetUserIdAndSecContext(), table_close(), and table_open().

Referenced by ExecCreateTableAs(), and ExecRefreshMatView().

◆ SetMatViewPopulatedState()

void SetMatViewPopulatedState ( Relation  relation,
bool  newstate 
)

Definition at line 78 of file matview.c.

79{
80 Relation pgrel;
81 HeapTuple tuple;
82
83 Assert(relation->rd_rel->relkind == RELKIND_MATVIEW);
84
85 /*
86 * Update relation's pg_class entry. Crucial side-effect: other backends
87 * (and this one too!) are sent SI message to make them rebuild relcache
88 * entries.
89 */
90 pgrel = table_open(RelationRelationId, RowExclusiveLock);
91 tuple = SearchSysCacheCopy1(RELOID,
93 if (!HeapTupleIsValid(tuple))
94 elog(ERROR, "cache lookup failed for relation %u",
95 RelationGetRelid(relation));
96
97 ((Form_pg_class) GETSTRUCT(tuple))->relispopulated = newstate;
98
99 CatalogTupleUpdate(pgrel, &tuple->t_self, tuple);
100
101 heap_freetuple(tuple);
103
104 /*
105 * Advance command counter to make the updated pg_class row locally
106 * visible.
107 */
109}
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1435
void CatalogTupleUpdate(Relation heapRel, const ItemPointerData *otid, HeapTuple tup)
Definition: indexing.c:313
FormData_pg_class * Form_pg_class
Definition: pg_class.h:156
static struct state * newstate(struct nfa *nfa)
Definition: regc_nfa.c:137
#define RelationGetRelid(relation)
Definition: rel.h:515
ItemPointerData t_self
Definition: htup.h:65
#define SearchSysCacheCopy1(cacheId, key1)
Definition: syscache.h:91
void CommandCounterIncrement(void)
Definition: xact.c:1101

References Assert(), CatalogTupleUpdate(), CommandCounterIncrement(), elog, ERROR, GETSTRUCT(), heap_freetuple(), HeapTupleIsValid, newstate(), ObjectIdGetDatum(), RelationData::rd_rel, RelationGetRelid, RowExclusiveLock, SearchSysCacheCopy1, HeapTupleData::t_self, table_close(), and table_open().

Referenced by intorel_startup(), and RefreshMatViewByOid().

◆ transientrel_destroy()

static void transientrel_destroy ( DestReceiver self)
static

Definition at line 553 of file matview.c.

554{
555 pfree(self);
556}
void pfree(void *pointer)
Definition: mcxt.c:1594

References pfree().

Referenced by CreateTransientRelDestReceiver().

◆ transientrel_receive()

static bool transientrel_receive ( TupleTableSlot slot,
DestReceiver self 
)
static

Definition at line 508 of file matview.c.

509{
510 DR_transientrel *myState = (DR_transientrel *) self;
511
512 /*
513 * Note that the input slot might not be of the type of the target
514 * relation. That's supported by table_tuple_insert(), but slightly less
515 * efficient than inserting with the right slot - but the alternative
516 * would be to copy into a slot of the right type, which would not be
517 * cheap either. This also doesn't allow accessing per-AM data (say a
518 * tuple's xmin), but since we don't do that here...
519 */
520
522 slot,
523 myState->output_cid,
524 myState->ti_options,
525 myState->bistate);
526
527 /* We know this is a newly created relation, so there are no indexes */
528
529 return true;
530}
Relation transientrel
Definition: matview.c:50
BulkInsertState bistate
Definition: matview.c:53
CommandId output_cid
Definition: matview.c:51
int ti_options
Definition: matview.c:52
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, BulkInsertStateData *bistate)
Definition: tableam.h:1377

References DR_transientrel::bistate, DR_transientrel::output_cid, table_tuple_insert(), DR_transientrel::ti_options, and DR_transientrel::transientrel.

Referenced by CreateTransientRelDestReceiver().

◆ transientrel_shutdown()

static void transientrel_shutdown ( DestReceiver self)
static

Definition at line 536 of file matview.c.

537{
538 DR_transientrel *myState = (DR_transientrel *) self;
539
541
543
544 /* close transientrel, but keep lock until commit */
546 myState->transientrel = NULL;
547}
void FreeBulkInsertState(BulkInsertState bistate)
Definition: heapam.c:2053
static void table_finish_bulk_insert(Relation rel, int options)
Definition: tableam.h:1574

References DR_transientrel::bistate, FreeBulkInsertState(), NoLock, table_close(), table_finish_bulk_insert(), DR_transientrel::ti_options, and DR_transientrel::transientrel.

Referenced by CreateTransientRelDestReceiver().

◆ transientrel_startup()

static void transientrel_startup ( DestReceiver self,
int  operation,
TupleDesc  typeinfo 
)
static

Definition at line 482 of file matview.c.

483{
484 DR_transientrel *myState = (DR_transientrel *) self;
485 Relation transientrel;
486
487 transientrel = table_open(myState->transientoid, NoLock);
488
489 /*
490 * Fill private fields of myState for use by later routines
491 */
492 myState->transientrel = transientrel;
493 myState->output_cid = GetCurrentCommandId(true);
495 myState->bistate = GetBulkInsertState();
496
497 /*
498 * Valid smgr_targblock implies something already wrote to the relation.
499 * This may be harmless, but this function hasn't planned for it.
500 */
502}
#define InvalidBlockNumber
Definition: block.h:33
BulkInsertState GetBulkInsertState(void)
Definition: heapam.c:2036
#define RelationGetTargetBlock(relation)
Definition: rel.h:611
#define TABLE_INSERT_FROZEN
Definition: tableam.h:260
#define TABLE_INSERT_SKIP_FSM
Definition: tableam.h:259
CommandId GetCurrentCommandId(bool used)
Definition: xact.c:830

References Assert(), DR_transientrel::bistate, GetBulkInsertState(), GetCurrentCommandId(), InvalidBlockNumber, NoLock, DR_transientrel::output_cid, RelationGetTargetBlock, TABLE_INSERT_FROZEN, TABLE_INSERT_SKIP_FSM, table_open(), DR_transientrel::ti_options, DR_transientrel::transientoid, and DR_transientrel::transientrel.

Referenced by CreateTransientRelDestReceiver().

Variable Documentation

◆ matview_maintenance_depth

int matview_maintenance_depth = 0
static