MCPcopy Create free account
hub / github.com/apache/cloudberry / MaintainMaterializedViewStatus

Function MaintainMaterializedViewStatus

src/backend/executor/execMain.c:4279–4375  ·  view source on GitHub ↗

* Maintain the status of Materialized Views in response to write operations on the underlying relations. * * For partitioned tables, changes are tracked using the relations of their leaf partitions rather than * the parent tables themselves. This minimizes the impact on Materialized Views that depend on the * partition tree, ensuring only relevant partitions are affected. * * In the case of

Source from the content-addressed store, hash-verified

4277 * For non-partitioned tables, the status transition is handled based on the semantic relations.
4278 */
4279static void
4280MaintainMaterializedViewStatus(QueryDesc *queryDesc, CmdType operation)
4281{
4282 List *inserted = NULL;
4283 List *updated = NULL;
4284 List *deleted = NULL;
4285 List *unique_result_relations = NIL;
4286 List *rtable = queryDesc->plannedstmt->rtable;
4287 int length = list_length(rtable);
4288 ListCell *lc;
4289 Oid relid;
4290
4291 /*
4292 * Process epd first to get the affected relations.
4293 */
4294 ConsumeAndProcessExtendProtocolData_IUD(&inserted, &updated, &deleted);
4295
4296 foreach (lc, inserted)
4297 {
4298 relid = lfirst_oid(lc);
4299 /* Only need to transfer to UP direction. */
4300 SetRelativeMatviewAuxStatus(relid, MV_DATA_STATUS_EXPIRED_INSERT_ONLY,
4301 MV_DATA_STATUS_TRANSFER_DIRECTION_UP);
4302 }
4303
4304 foreach (lc, updated)
4305 {
4306 relid = lfirst_oid(lc);
4307 SetRelativeMatviewAuxStatus(relid, MV_DATA_STATUS_EXPIRED,
4308 MV_DATA_STATUS_TRANSFER_DIRECTION_UP);
4309
4310 }
4311
4312 foreach (lc, deleted)
4313 {
4314 relid = lfirst_oid(lc);
4315 SetRelativeMatviewAuxStatus(relid, MV_DATA_STATUS_EXPIRED,
4316 MV_DATA_STATUS_TRANSFER_DIRECTION_UP);
4317
4318 }
4319
4320 unique_result_relations = list_concat_unique_int(NIL, queryDesc->plannedstmt->resultRelations);
4321 foreach(lc, unique_result_relations)
4322 {
4323 int varno = lfirst_int(lc);
4324 RangeTblEntry *rte = rt_fetch(varno, rtable);
4325
4326 /* Avoid crash in case we don't find a rte. */
4327 if (varno > length + 1)
4328 {
4329 ereport(WARNING, (errmsg("could not find rte of varno: %u ", varno)));
4330 continue;
4331 }
4332
4333 if (RELKIND_PARTITIONED_TABLE == rte->relkind)
4334 {
4335 /*
4336 * There should be leaf paritions if we modifed a partitioned table

Callers 1

standard_ExecutorRunFunction · 0.85

Calls 7

list_lengthFunction · 0.85
list_concat_unique_intFunction · 0.85
get_rel_nameFunction · 0.85
foreachFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected