[#12516] improvement(scripts): Add IF NOT EXISTS to CREATE INDEX in upgrade SQL scripts for idempotency - #12968
Conversation
|
@LiJie20190102 |
…ade SQL scripts for idempotency PostgreSQL: add IF NOT EXISTS to 5 CREATE INDEX statements in upgrade-1.1.0-to-1.2.0-postgresql.sql. MySQL: use prepared statements with information_schema check to make 7 CREATE [UNIQUE] INDEX statements idempotent across 2 upgrade scripts (upgrade-1.2.0-to-1.3.0-mysql.sql and upgrade-1.3.0-to-2.0.0-mysql.sql), since MySQL 8.0 does not support CREATE INDEX IF NOT EXISTS. Add testUpgradeSQLScriptIdempotency to TestSQLScripts to verify that re-running upgrade scripts does not fail on index-creation statements.
dd399c7 to
bec300a
Compare
Okay, it has been resolved |
|
Thanks for the fix. I suggest keeping only the PostgreSQL changes in this PR and discussing the MySQL changes separately. The MySQL checks can avoid creating the same index again, but other statements, such as ADD COLUMN and DROP INDEX, can still fail when we run the script again. So the extra SQL does not yet solve the upgrade retry problem. Could we first clarify which retry case we want to support? For the test, please check that the indexes exist and have the expected columns and uniqueness. If we only want to test running the index statements twice, please make that scope clear. Ignoring errors from other DDL statements does not show that the whole upgrade script can be run again safely. |
Code Coverage Report
Files |
Thanks for the detailed review, @yuqi1129 . I've reverted the MySQL changes from this PR as you suggested. |
What changes were proposed in this pull request?
PostgreSQL: add IF NOT EXISTS to 5 CREATE INDEX statements in upgrade-1.1.0-to-1.2.0-postgresql.sql.
MySQL: use prepared statements with information_schema check to make 7 CREATE [UNIQUE] INDEX statements idempotent across 2 upgrade scripts (upgrade-1.2.0-to-1.3.0-mysql.sql and upgrade-1.3.0-to-2.0.0-mysql.sql), since MySQL 8.0 does not support CREATE INDEX IF NOT EXISTS.
Add testUpgradeSQLScriptIdempotency to TestSQLScripts to verify that re-running upgrade scripts does not fail on index-creation statements.
Why are the changes needed?
(Please clarify why the changes are needed. For instance,
Fix: #12516
Does this PR introduce any user-facing change?
(Please list the user-facing changes introduced by your change, including
How was this patch tested?
Execute the method
org.apache.gravitino.storage.TestSQLScripts#testUpgradeSQLScriptIdempotency