68 const char *queryString);
71 int save_sec_context);
100 elog(
ERROR,
"cache lookup failed for relation %u",
150 uint64 processed = 0;
155 int save_sec_context;
160 concurrent =
stmt->concurrent;
170 relowner = matviewRel->
rd_rel->relowner;
183 if (matviewRel->
rd_rel->relkind != RELKIND_MATVIEW)
185 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
186 errmsg(
"\"%s\" is not a materialized view",
192 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
193 errmsg(
"CONCURRENTLY cannot be used when the materialized view is not populated")));
196 if (concurrent &&
stmt->skipData)
198 (
errcode(ERRCODE_SYNTAX_ERROR),
199 errmsg(
"%s and %s options cannot be used together",
200 "CONCURRENTLY",
"WITH NO DATA")));
206 if (matviewRel->
rd_rel->relhasrules ==
false ||
209 "materialized view \"%s\" is missing rewrite information",
214 "materialized view \"%s\" has too many rules",
220 "the rule for materialized view \"%s\" is not a SELECT INSTEAD OF rule",
223 actions =
rule->actions;
226 "the rule for materialized view \"%s\" is not a single action",
237 bool hasUniqueIndex =
false;
239 foreach(indexoidscan, indexoidlist)
255 (
errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
256 errmsg(
"cannot refresh materialized view \"%s\" concurrently",
259 errhint(
"Create a unique index with no WHERE clause on one or more columns of the materialized view.")));
287 relpersistence = RELPERSISTENCE_TEMP;
291 tableSpace = matviewRel->
rd_rel->reltablespace;
292 relpersistence = matviewRel->
rd_rel->relpersistence;
301 matviewRel->
rd_rel->relam,
377 const char *queryString)
392 elog(
ERROR,
"unexpected rewrite result for REFRESH MATERIALIZED VIEW");
413 dest, NULL, NULL, 0);
444 self->transientoid = transientoid;
585 int save_sec_context)
594 bool foundUniqueIndex;
633 "SELECT newdata.*::%s FROM %s newdata "
634 "WHERE newdata.* IS NOT NULL AND EXISTS "
635 "(SELECT 1 FROM %s newdata2 WHERE newdata2.* IS NOT NULL "
636 "AND newdata2.* OPERATOR(pg_catalog.*=) newdata.* "
637 "AND newdata2.ctid OPERATOR(pg_catalog.<>) "
639 tempname, tempname, tempname);
652 (
errcode(ERRCODE_CARDINALITY_VIOLATION),
653 errmsg(
"new data for materialized view \"%s\" contains duplicate rows without any null columns",
665 "CREATE TEMP TABLE %s AS "
666 "SELECT mv.ctid AS tid, newdata.*::%s AS newdata "
667 "FROM %s mv FULL JOIN %s newdata ON (",
668 diffname, tempname, matviewname, tempname);
676 tupdesc = matviewRel->
rd_att;
678 foundUniqueIndex =
false;
682 foreach(indexoidscan, indexoidlist)
691 int indnkeyatts = indexStruct->indnkeyatts;
699 Anum_pg_index_indclass);
703 for (
i = 0;
i < indnkeyatts;
i++)
705 int attnum = indexStruct->indkey.values[
i];
708 Oid attrtype = attr->atttypid;
723 elog(
ERROR,
"cache lookup failed for opclass %u", opclass);
725 Assert(cla_tup->opcmethod == BTREE_AM_OID);
726 opfamily = cla_tup->opcfamily;
727 opcintype = cla_tup->opcintype;
733 elog(
ERROR,
"missing operator %d(%u,%u) in opfamily %u",
747 if (opUsedForQual[
attnum - 1] == op)
749 opUsedForQual[
attnum - 1] = op;
754 if (foundUniqueIndex)
767 foundUniqueIndex =
true;
787 " AND newdata.* OPERATOR(pg_catalog.*=) mv.*) "
788 "WHERE newdata.* IS NULL OR mv.* IS NULL "
814 "DELETE FROM %s mv WHERE ctid OPERATOR(pg_catalog.=) ANY "
815 "(SELECT diff.tid FROM %s diff "
816 "WHERE diff.tid IS NOT NULL "
817 "AND diff.newdata IS NULL)",
818 matviewname, diffname);
825 "INSERT INTO %s SELECT (diff.newdata).* "
826 "FROM %s diff WHERE tid IS NULL",
827 matviewname, diffname);
875 if (indexStruct->indisunique &&
876 indexStruct->indimmediate &&
877 indexRel->
rd_rel->relam == BTREE_AM_OID &&
878 indexStruct->indisvalid &&
880 indexStruct->indnatts > 0)
889 int numatts = indexStruct->indnatts;
892 for (
i = 0;
i < numatts;
i++)
894 int attnum = indexStruct->indkey.values[
i];
Oid GetDefaultTablespace(char relpersistence, bool partitioned)
#define InvalidBlockNumber
#define OidIsValid(objectId)
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)
Oid make_new_heap(Oid OIDOldHeap, Oid NewTableSpace, Oid NewAccessMethod, char relpersistence, LOCKMODE lockmode)
static void SetQueryCompletion(QueryCompletion *qc, CommandTag commandTag, uint64 nprocessed)
elog(ERROR, "%s: %s", p2, msg)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void ExecutorEnd(QueryDesc *queryDesc)
void ExecutorFinish(QueryDesc *queryDesc)
void ExecutorStart(QueryDesc *queryDesc, int eflags)
void ExecutorRun(QueryDesc *queryDesc, ScanDirection direction, uint64 count, bool execute_once)
int NewGUCNestLevel(void)
void AtEOXact_GUC(bool isCommit, int nestLevel)
BulkInsertState GetBulkInsertState(void)
void FreeBulkInsertState(BulkInsertState bistate)
void heap_freetuple(HeapTuple htup)
#define HeapTupleIsValid(tuple)
void index_close(Relation relation, LOCKMODE lockmode)
Relation index_open(Oid relationId, LOCKMODE lockmode)
void CatalogTupleUpdate(Relation heapRel, ItemPointer otid, HeapTuple tup)
Assert(fmt[strlen(fmt) - 1] !='\n')
void list_free(List *list)
void LockRelationOid(Oid relid, LOCKMODE lockmode)
#define AccessExclusiveLock
char * get_namespace_name(Oid nspid)
Oid get_opfamily_member(Oid opfamily, Oid lefttype, Oid righttype, int16 strategy)
static void transientrel_destroy(DestReceiver *self)
static void transientrel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
static uint64 refresh_matview_datafill(DestReceiver *dest, Query *query, const char *queryString)
static char * make_temptable_name_n(char *tempname, int n)
static void refresh_by_match_merge(Oid matviewOid, Oid tempOid, Oid relowner, int save_sec_context)
DestReceiver * CreateTransientRelDestReceiver(Oid transientoid)
static bool is_usable_unique_index(Relation indexRel)
bool MatViewIncrementalMaintenanceIsEnabled(void)
static void CloseMatViewIncrementalMaintenance(void)
static void OpenMatViewIncrementalMaintenance(void)
void SetMatViewPopulatedState(Relation relation, bool newstate)
static int matview_maintenance_depth
static void refresh_by_heap_swap(Oid matviewOid, Oid OIDNewHeap, char relpersistence)
ObjectAddress ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ParamListInfo params, QueryCompletion *qc)
static bool transientrel_receive(TupleTableSlot *slot, DestReceiver *self)
static void transientrel_shutdown(DestReceiver *self)
void pfree(void *pointer)
void * palloc0(Size size)
#define SECURITY_RESTRICTED_OPERATION
#define CHECK_FOR_INTERRUPTS()
#define SECURITY_LOCAL_USERID_CHANGE
void GetUserIdAndSecContext(Oid *userid, int *sec_context)
void SetUserIdAndSecContext(Oid userid, int sec_context)
MultiXactId ReadNextMultiXactId(void)
Oid RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode, uint32 flags, RangeVarGetRelidCallback callback, void *callback_arg)
#define ObjectAddressSet(addr, class_id, object_id)
#define CURSOR_OPT_PARALLEL_OK
FormData_pg_attribute * Form_pg_attribute
FormData_pg_class * Form_pg_class
FormData_pg_index * Form_pg_index
static int list_length(const List *l)
#define linitial_node(type, l)
FormData_pg_opclass * Form_pg_opclass
void pgstat_count_heap_insert(Relation rel, PgStat_Counter n)
void pgstat_count_truncate(Relation rel)
PlannedStmt * pg_plan_query(Query *querytree, const char *query_string, int cursorOptions, ParamListInfo boundParams)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
void FreeQueryDesc(QueryDesc *qdesc)
QueryDesc * CreateQueryDesc(PlannedStmt *plannedstmt, const char *sourceText, Snapshot snapshot, Snapshot crosscheck_snapshot, DestReceiver *dest, ParamListInfo params, QueryEnvironment *queryEnv, int instrument_options)
static struct state * newstate(struct nfa *nfa)
#define RelationGetRelid(relation)
#define RelationGetNumberOfAttributes(relation)
#define RelationGetRelationName(relation)
#define RelationGetTargetBlock(relation)
#define RelationIsPopulated(relation)
#define RelationGetNamespace(relation)
List * RelationGetIndexList(Relation relation)
List * RelationGetIndexPredicate(Relation relation)
void AcquireRewriteLocks(Query *parsetree, bool forExecute, bool forUpdatePushedDown)
List * QueryRewrite(Query *parsetree)
char * quote_qualified_identifier(const char *qualifier, const char *ident)
void generate_operator_clause(StringInfo buf, const char *leftop, Oid leftoptype, Oid opoid, const char *rightop, Oid rightoptype)
void UpdateActiveSnapshotCommandId(void)
void PopActiveSnapshot(void)
void PushCopiedSnapshot(Snapshot snapshot)
Snapshot GetActiveSnapshot(void)
SPITupleTable * SPI_tuptable
int SPI_exec(const char *src, long tcount)
char * SPI_getvalue(HeapTuple tuple, TupleDesc tupdesc, int fnumber)
int SPI_execute(const char *src, bool read_only, long tcount)
#define BTEqualStrategyNumber
void resetStringInfo(StringInfo str)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoString(StringInfo str, const char *s)
void initStringInfo(StringInfo str)
struct HeapTupleData * rd_indextuple
Oid values[FLEXIBLE_ARRAY_MEMBER]
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Datum SysCacheGetAttrNotNull(int cacheId, HeapTuple tup, AttrNumber attributeNumber)
#define SearchSysCacheCopy1(cacheId, key1)
void table_close(Relation relation, LOCKMODE lockmode)
Relation table_open(Oid relationId, LOCKMODE lockmode)
#define TABLE_INSERT_FROZEN
#define TABLE_INSERT_SKIP_FSM
static void table_finish_bulk_insert(Relation rel, int options)
static void table_tuple_insert(Relation rel, TupleTableSlot *slot, CommandId cid, int options, struct BulkInsertStateData *bistate)
void RangeVarCallbackOwnsTable(const RangeVar *relation, Oid relId, Oid oldRelId, void *arg)
void CheckTableNotInUse(Relation rel, const char *stmt)
#define TupleDescAttr(tupdesc, i)
void CommandCounterIncrement(void)
CommandId GetCurrentCommandId(bool used)