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

Function RevalidateCachedQuery

src/backend/utils/cache/plancache.c:564–810  ·  view source on GitHub ↗

* RevalidateCachedQuery: ensure validity of analyzed-and-rewritten query tree. * * What we do here is re-acquire locks and redo parse analysis if necessary. * On return, the query_list is valid and we have sufficient locks to begin * planning. * * If any parse analysis activity is required, the caller's memory context is * used for that work. * * The result value is the transient analyzed

Source from the content-addressed store, hash-verified

562 * GPDB: See GetCachedPlan() for why intoClause is added here.
563 */
564static List *
565RevalidateCachedQuery(CachedPlanSource *plansource,
566 QueryEnvironment *queryEnv,
567 IntoClause *intoClause)
568{
569 bool snapshot_set;
570 RawStmt *rawtree;
571 List *tlist; /* transient query-tree list */
572 List *qlist; /* permanent query-tree list */
573 TupleDesc resultDesc;
574 MemoryContext querytree_context;
575 MemoryContext oldcxt;
576
577 /*
578 * For one-shot plans, we do not support revalidation checking; it's
579 * assumed the query is parsed, planned, and executed in one transaction,
580 * so that no lock re-acquisition is necessary. Also, there is never any
581 * need to revalidate plans for transaction control commands (and we
582 * mustn't risk any catalog accesses when handling those).
583 */
584 if (plansource->is_oneshot || IsTransactionStmtPlan(plansource))
585 {
586 Assert(plansource->is_valid);
587 return NIL;
588 }
589
590 /*
591 * If the query is currently valid, we should have a saved search_path ---
592 * check to see if that matches the current environment. If not, we want
593 * to force replan.
594 */
595 if (plansource->is_valid)
596 {
597 Assert(plansource->search_path != NULL);
598 if (!OverrideSearchPathMatchesCurrent(plansource->search_path))
599 {
600 /* Invalidate the querytree and generic plan */
601 plansource->is_valid = false;
602 if (plansource->gplan)
603 plansource->gplan->is_valid = false;
604 }
605 }
606
607 /*
608 * If the query rewrite phase had a possible RLS dependency, we must redo
609 * it if either the role or the row_security setting has changed.
610 */
611 if (plansource->is_valid && plansource->dependsOnRLS &&
612 (plansource->rewriteRoleId != GetUserId() ||
613 plansource->rewriteRowSecurity != row_security))
614 plansource->is_valid = false;
615
616 /*
617 * If the query is currently valid, acquire locks on the referenced
618 * objects; then check again. We need to do it this way to cover the race
619 * condition that an invalidation message arrives before we get the locks.
620 */
621 if (plansource->is_valid && intoClause == NULL)

Callers 3

BuildCachedPlanFunction · 0.85
GetCachedPlanFunction · 0.85
CachedPlanGetTargetListFunction · 0.85

Calls 15

GetUserIdFunction · 0.85
AcquirePlannerLocksFunction · 0.85
ReleaseGenericPlanFunction · 0.85
ActiveSnapshotSetFunction · 0.85
PushActiveSnapshotFunction · 0.85
GetTransactionSnapshotFunction · 0.85
pg_analyze_and_rewriteFunction · 0.85
list_lengthFunction · 0.85
PopActiveSnapshotFunction · 0.85

Tested by

no test coverage detected