Skip to content

2.25.0.0-b240

@fizaaluthra fizaaluthra tagged this 31 Oct 22:03
Summary:
### Background:

Commit 2fb7ea649683574f7d6a62edaf0318166d5eb5a1 adds support for table rewrites by mapping the relfilenode of a relation to the DocDB table (instead of the relation oid).
The changes made by that commit operate under the assumption that when a table is created, its relation oid and relfilenode oid are the same, and that it is only after a table rewrite the two diverge.
However, this assumption is no longer true within the context of a YSQL major version upgrade. During such an upgrade, pg_dump will preserve the relfilenodes of rewritten relations using `binary_upgrade_next_heap_pg_class_relfilenode`. Therefore, the relations will be re-created with a mismatch between the relation oid and the relfilenode oid right from the very beginning.

### Solution:
Fix the problem by sending the appropriate relation oid and relfilenode oid at the time of create.
Code changes:
- Change in `YBCCreateTable`: The parameter `relationId` is being used to create the DocDB table. This naming is confusing because the DocDB table is created using the relfilenode oid, and the relation's oid maps to the pg_table_id stored in DocDB metadata. In other words, the param `relationId` is taking in a relfilenode right now.  Fix this by replacing the param `pgTableId` with `relfileNodeId`, and use `relationId` as the param that maps to pg_table_id. Modify the call to `YBCPgNewCreateTable` to reflect this change.
- Changes in `YBCCreateIndex`: Replace `pgTableId` with `indexRelfileNodeId`. Modify the call to `YBCPgNewCreateIndex`. Similar reasoning as above.
- In `DefineRelation`, move the `YBCCreateTable` call to after the declaration of `rel`, so that we can retrieve the relation's relfilenode oid. Also, change the call to correctly pass the relfilenode oid and the relation oid.
- Change the other `YBCCreateTable` call and all `YBCCreateIndex` calls to reflect the new ordering of the params.

Note: previously, the `pg_table_id` field in DocDB was only populated after a table rewrite. With this diff, the field will always be populated.
Jira: DB-13580

Test Plan:
Moved pg15_tests/test_upgrade_matview.sh and pg15_tests/test_upgrade_partition.sh to C++ tests.

./yb_build.sh release --cxx-test pg15_upgrade-test --gtest_filter Pg15UpgradeTest.Matviews
./yb_build.sh release --cxx-test pg15_upgrade-test --gtest_filter Pg15UpgradeTest.PartitionedTables

Reviewers: tfoucher, telgersma, hsunder

Reviewed By: telgersma, hsunder

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D39168
Assets 2
Loading