Skip to content

Handle dump/restore/upgrade, take 2#140

Open
adamguo0 wants to merge 13 commits intosraoss:mainfrom
adamguo0:20250520_pr
Open

Handle dump/restore/upgrade, take 2#140
adamguo0 wants to merge 13 commits intosraoss:mainfrom
adamguo0:20250520_pr

Conversation

@adamguo0
Copy link

@adamguo0 adamguo0 commented May 21, 2025

(follow up on #128, re #118)

This is a second attempt at supporting pg_dump/pg_restore/pg_upgrade for this extension. This PR makes bigger design changes in order to provide a seamless dump/restore/upgrade experience. Users don't have to run any pre-dump or post-restore scripts in order to get their IMMVs working.

Summary of changes:

  • Replace the viewdef column with a querystring column that stores the fully-qualified query string of each IMMV.
  • Add a immvuuid column of uuid type. This is used as a unique identifier for IMMVs instead of the immvrelid.
  • Set the IMMV triggers to external instead of internal so that they are automatically dumped by pg_dump. Set the trigger argument to immvuuid instead of immvrelid and let the triggers look up the corresponding OID of the IMMV.
  • Create two C event triggers to keep the querystring up to date if any objects are renamed:
    • Before any ALTER RENAME statement, parse all IMMV query strings and store the Query nodes in a hash table.
    • After any ALTER RENAME statement, restore all Query nodes from the hash table back into pg_ivm_immv.

When users run pg_dump, the dump file contains the pg_ivm_immv table with the correct fully-qualified query strings, as well as the CREATE TRIGGER commands to re-create the IMMV triggers. The triggers use the immvuuid argument to look up the corresponding IMMV in pg_ivm_immv. The same goes for pg_upgrade. I ran some basic tests and it works so far with no user intervention needed.

Some todos:

  • Handle upgrading from 1.10 to 1.11 given the significant implementation changes.
  • Handle possible UUID collision (albeit very improbable).
  • Come up with more precise criteria for when to re-parse the query strings (instead of re-parsing on every ALTER RENAME statement).

Eager for any feedback, thanks!

@michaelpq
Copy link
Contributor

This patch set is very disorganized. Could it be possible to get a cleaned up branch with one or more commits and dedicated commit messages to understand a bit better what you are trying to achieve here? You could force push things, once the patch has been cleaned up, but it is not in a reviewable state as it stands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants