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

Function CopyAndAddInvertedQual

src/backend/rewrite/rewriteHandler.c:2346–2385  ·  view source on GitHub ↗

* Modify the given query by adding 'AND rule_qual IS NOT TRUE' to its * qualification. This is used to generate suitable "else clauses" for * conditional INSTEAD rules. (Unfortunately we must use "x IS NOT TRUE", * not just "NOT x" which the planner is much smarter about, else we will * do the wrong thing when the qual evaluates to NULL.) * * The rule_qual may contain references to OLD or

Source from the content-addressed store, hash-verified

2344 * of the related entries in the query's own targetlist.
2345 */
2346static Query *
2347CopyAndAddInvertedQual(Query *parsetree,
2348 Node *rule_qual,
2349 int rt_index,
2350 CmdType event)
2351{
2352 /* Don't scribble on the passed qual (it's in the relcache!) */
2353 Node *new_qual = copyObject(rule_qual);
2354 acquireLocksOnSubLinks_context context;
2355
2356 context.for_execute = true;
2357
2358 /*
2359 * In case there are subqueries in the qual, acquire necessary locks and
2360 * fix any deleted JOIN RTE entries. (This is somewhat redundant with
2361 * rewriteRuleAction, but not entirely ... consider restructuring so that
2362 * we only need to process the qual this way once.)
2363 */
2364 (void) acquireLocksOnSubLinks(new_qual, &context);
2365
2366 /* Fix references to OLD */
2367 ChangeVarNodes(new_qual, PRS2_OLD_VARNO, rt_index, 0);
2368 /* Fix references to NEW */
2369 if (event == CMD_INSERT || event == CMD_UPDATE)
2370 new_qual = ReplaceVarsFromTargetList(new_qual,
2371 PRS2_NEW_VARNO,
2372 0,
2373 rt_fetch(rt_index,
2374 parsetree->rtable),
2375 parsetree->targetList,
2376 (event == CMD_UPDATE) ?
2377 REPLACEVARS_CHANGE_VARNO :
2378 REPLACEVARS_SUBSTITUTE_NULL,
2379 rt_index,
2380 &parsetree->hasSubLinks);
2381 /* And attach the fixed qual */
2382 AddInvertedQual(parsetree, new_qual);
2383
2384 return parsetree;
2385}
2386
2387
2388/*

Callers 1

fireRulesFunction · 0.85

Calls 4

acquireLocksOnSubLinksFunction · 0.85
ChangeVarNodesFunction · 0.85
AddInvertedQualFunction · 0.85

Tested by

no test coverage detected