Summary:
FK reference cache is used to avoid read RPC in case particular row was added in context of same transaction.
Suppose `child` table references `parent` table.
```
BEGIN;
INSERT INTO parent VALUES(1);
INSERT INTO child VALUES(1, 1);
COMMIT;
```
It is not required to check that row = 1 exists in `parent` table. YSQL knows it exists because it was inserted in same transaction.
In case new row is inserted YSQL add entry into FK reference cache. The FK reference cache could take too much memory in case of large transaction which inserts huge number of rows.
Current diff introduces GUC variable `yb_fk_references_cache_limit` to limit the number of entries in FK references cache. Default value is `65535`
**Note:**
It is possible that actual number of entries in FK reference cache will be higher than a limit. When YSQL performs read RPC to check FK it also adds the value into FK reference cache to avoid doing same check again in case some other row in transaction references same FK. In this case actual size of FK reference cache is not checked.
Jira: DB-17338
Test Plan:
New unit test is introduced
```
./yb_build.sh --gtest_filter PgFKeyTest.FKReferenceCacheLimit
```
Reviewers: pjain, myang, fizaa, kramanathan
Reviewed By: kramanathan
Subscribers: smishra, yql
Tags: #jenkins-ready
Differential Revision: https://phorge.dev.yugabyte.com/D44796