* matchLocks - * match the list of locks and returns the matching rules */
| 1707 | * match the list of locks and returns the matching rules |
| 1708 | */ |
| 1709 | static List * |
| 1710 | matchLocks(CmdType event, |
| 1711 | RuleLock *rulelocks, |
| 1712 | int varno, |
| 1713 | Query *parsetree, |
| 1714 | bool *hasUpdate) |
| 1715 | { |
| 1716 | List *matching_locks = NIL; |
| 1717 | int nlocks; |
| 1718 | int i; |
| 1719 | |
| 1720 | if (rulelocks == NULL) |
| 1721 | return NIL; |
| 1722 | |
| 1723 | if (parsetree->commandType != CMD_SELECT) |
| 1724 | { |
| 1725 | if (parsetree->resultRelation != varno) |
| 1726 | return NIL; |
| 1727 | } |
| 1728 | |
| 1729 | nlocks = rulelocks->numLocks; |
| 1730 | |
| 1731 | for (i = 0; i < nlocks; i++) |
| 1732 | { |
| 1733 | RewriteRule *oneLock = rulelocks->rules[i]; |
| 1734 | |
| 1735 | if (oneLock->event == CMD_UPDATE) |
| 1736 | *hasUpdate = true; |
| 1737 | |
| 1738 | /* |
| 1739 | * Suppress ON INSERT/UPDATE/DELETE rules that are disabled or |
| 1740 | * configured to not fire during the current sessions replication |
| 1741 | * role. ON SELECT rules will always be applied in order to keep views |
| 1742 | * working even in LOCAL or REPLICA role. |
| 1743 | */ |
| 1744 | if (oneLock->event != CMD_SELECT) |
| 1745 | { |
| 1746 | if (SessionReplicationRole == SESSION_REPLICATION_ROLE_REPLICA) |
| 1747 | { |
| 1748 | if (oneLock->enabled == RULE_FIRES_ON_ORIGIN || |
| 1749 | oneLock->enabled == RULE_DISABLED) |
| 1750 | continue; |
| 1751 | } |
| 1752 | else /* ORIGIN or LOCAL ROLE */ |
| 1753 | { |
| 1754 | if (oneLock->enabled == RULE_FIRES_ON_REPLICA || |
| 1755 | oneLock->enabled == RULE_DISABLED) |
| 1756 | continue; |
| 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | if (oneLock->event == event) |
| 1761 | { |
| 1762 | if (parsetree->commandType != CMD_SELECT || |
| 1763 | rangeTableEntry_used((Node *) parsetree, varno, 0)) |
| 1764 | matching_locks = lappend(matching_locks, oneLock); |
| 1765 | } |
| 1766 | } |
no test coverage detected