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

Function fireRules

src/backend/rewrite/rewriteHandler.c:2416–2495  ·  view source on GitHub ↗

* fireRules - * Iterate through rule locks applying rules. * * Input arguments: * parsetree - original query * rt_index - RT index of result relation in original query * event - type of rule event * locks - list of rules to fire * Output arguments: * *instead_flag - set true if any unqualified INSTEAD rule is found * (must be initialized to false) * *returning_flag - set true if

Source from the content-addressed store, hash-verified

2414 * we find both, the modified original query is discarded too.
2415 */
2416static List *
2417fireRules(Query *parsetree,
2418 int rt_index,
2419 CmdType event,
2420 List *locks,
2421 bool *instead_flag,
2422 bool *returning_flag,
2423 Query **qual_product)
2424{
2425 List *results = NIL;
2426 ListCell *l;
2427
2428 foreach(l, locks)
2429 {
2430 RewriteRule *rule_lock = (RewriteRule *) lfirst(l);
2431 Node *event_qual = rule_lock->qual;
2432 List *actions = rule_lock->actions;
2433 QuerySource qsrc;
2434 ListCell *r;
2435
2436 /* Determine correct QuerySource value for actions */
2437 if (rule_lock->isInstead)
2438 {
2439 if (event_qual != NULL)
2440 qsrc = QSRC_QUAL_INSTEAD_RULE;
2441 else
2442 {
2443 qsrc = QSRC_INSTEAD_RULE;
2444 *instead_flag = true; /* report unqualified INSTEAD */
2445 }
2446 }
2447 else
2448 qsrc = QSRC_NON_INSTEAD_RULE;
2449
2450 if (qsrc == QSRC_QUAL_INSTEAD_RULE)
2451 {
2452 /*
2453 * If there are INSTEAD rules with qualifications, the original
2454 * query is still performed. But all the negated rule
2455 * qualifications of the INSTEAD rules are added so it does its
2456 * actions only in cases where the rule quals of all INSTEAD rules
2457 * are false. Think of it as the default action in a case. We save
2458 * this in *qual_product so RewriteQuery() can add it to the query
2459 * list after we mangled it up enough.
2460 *
2461 * If we have already found an unqualified INSTEAD rule, then
2462 * *qual_product won't be used, so don't bother building it.
2463 */
2464 if (!*instead_flag)
2465 {
2466 if (*qual_product == NULL)
2467 *qual_product = copyObject(parsetree);
2468 *qual_product = CopyAndAddInvertedQual(*qual_product,
2469 event_qual,
2470 rt_index,
2471 event);
2472 }
2473 }

Callers 1

RewriteQueryFunction · 0.85

Calls 4

CopyAndAddInvertedQualFunction · 0.85
rewriteRuleActionFunction · 0.85
lappendFunction · 0.85
foreachFunction · 0.50

Tested by

no test coverage detected