-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#26205] YSQL: Fix REFRESH MV CONCURRENTLY to use 1 XID per statement…
…/txn Summary: **The problem** `REFRESH MATERIALIZED VIEW CONCURRENTLY` generates 1 Postgres Transaction ID (XID) per row in the refreshed view. This can lead to an exhaustion of XIDs in YugabyteDB when the view contains a large number of tables, and is refreshed frequently. This exhaustion happens because committed XIDs are not vacuumed in order to reclaim XIDs. To delay the exhaustion of XIDs, it is beneficial to generate 1 XID per concurrent refresh. **Current State** To understand why 1 XID is generated per row in case of a concurrent refresh, consider the table below which describes the current behavior. | Operation | IsCurrentTxnWithPGRel() | Is XID set on pgproc | | REFRESH MV [NONONCURRENTLY] | No | No | | REFRESH MV CONCURRENTLY | No | Yes | | INSERT/UPDATE/DELETE on TEMP TABLE | Yes | Yes | - IsCurrentTxnWithPGRel() determines whether a commit log is written for the current transaction (and its subtransactions). When set to false (as in the case of `REFRESH MATERIALIZED VIEW`), writing a commit log is skipped. A commit log is needed by postgres whenever an XID is generated for a transaction. - In terms of transactional handling of materialized views, the main difference between concurrent and non-concurrent refreshes is whether an XID is generated for the transaction. Currently, `REFRESH MATERIALIZED VIEW CONCURRENTLY` generates an XID each time postgres' `heap_insert()` is invoked (once per row). It is then cleared immediately, so when the transaction is about to commit, there is no XID associated with the transaction. Therefore writing to the commit log is skipped. `REFRESH MATERIALIZED VIEW [NONONCURRENTLY]` does not generate an XID as postgres' `heap_insert()` is not invoked. So, there is no log to be written at commit time. In this manner, both refreshes behave identically with respect to writing to the commit log (ie. they don't). **The fix** - To fix the problem mentioned above, this revision skips clearing the XID after `heap_insert()`. - This further requires clearing the XID from its pgproc entry at commit time. In the absence of this future statements/transactions will be incorrectly associated with this refresh which has already committed. - In order to run this cleanup only when `REFRESH MATERIALIZED VIEW CONCURRENTLY` (aside from temp tables) is involved, `isYBTxnWithPostgresRel` is expanded to distinguish between cases where `REFRESH MATERIALIZED VIEW` is invoked concurrently and non-concurrently, aside from the existing distinction for temp tables. This struct member is renamed to `ybPostgresOpsInTxn` in the process. Note that a commit log entry is not written for any flavor of `REFRESH MATERIALIZED VIEW` to keep things as close as possible to current behavior. Jira: DB-15551 Test Plan: Run the following tests: ``` ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressPgMatview' ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressMatview' ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressFeature' ./yb_build.sh --java-test 'org.yb.pgsql.TestPgRegressDml#schedule' ``` Jenkins: urgent Reviewers: fizaa, hsunder, pjain, smishra, amartsinchyk Reviewed By: fizaa, amartsinchyk Subscribers: amartsinchyk, mihnea, smishra, yql Tags: #jenkins-ready Differential Revision: https://phorge.dev.yugabyte.com/D42159
- Loading branch information
1 parent
0ae37fd
commit 0ff1f71
Showing
15 changed files
with
879 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.