Skip to content

Prepare loose FK table for sliding partitioning

What does this MR do and why?

This MR updates the default value for the loose_foreign_keys_deleted_records table and moves the partition static schema.

Related to: #345993 (closed)

Database

Up:

== 20211118100959 ChangeDefaultValueOfLooseFkDeletedRecordsPartition: migrating
-- change_column_default(:loose_foreign_keys_deleted_records, :partition, {:from=>nil, :to=>1})
   -> 0.0035s
== 20211118100959 ChangeDefaultValueOfLooseFkDeletedRecordsPartition: migrated (0.0035s)

== 20211118103439 RemoveHardcodedPartitionFromLooseFkTriggerFunction: migrating
-- execute("CREATE OR REPLACE FUNCTION insert_into_loose_foreign_keys_deleted_records()\nRETURNS TRIGGER AS\n$$\nBEGIN\n  INSERT INTO loose_foreign_keys_deleted_records\n  (fully_qualified_table_name, primary_key_value)\n  SELECT TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table\n  ON CONFLICT DO NOTHING;\n\n  RETURN NULL;\nEND\n$$ LANGUAGE PLPGSQL\n")
   -> 0.0017s
== 20211118103439 RemoveHardcodedPartitionFromLooseFkTriggerFunction: migrated (0.0018s)

== 20211122113632 MoveLooseForeignKeysPartitionToDynamicSchema: migrating =====
-- execute("ALTER TABLE \"gitlab_partitions_static\".loose_foreign_keys_deleted_records_1\nSET SCHEMA \"gitlab_partitions_dynamic\";\n")
   -> 0.0104s
== 20211122113632 MoveLooseForeignKeysPartitionToDynamicSchema: migrated (0.0105s)

Down:

== 20211122113632 MoveLooseForeignKeysPartitionToDynamicSchema: reverting =====
-- execute("ALTER TABLE \"gitlab_partitions_dynamic\".loose_foreign_keys_deleted_records_1\nSET SCHEMA \"gitlab_partitions_static\";\n")
   -> 0.0020s
== 20211122113632 MoveLooseForeignKeysPartitionToDynamicSchema: reverted (0.0021s)


== 20211118100959 ChangeDefaultValueOfLooseFkDeletedRecordsPartition: reverting
-- change_column_default(:loose_foreign_keys_deleted_records, :partition, {:from=>1, :to=>nil})
   -> 0.0046s
== 20211118100959 ChangeDefaultValueOfLooseFkDeletedRecordsPartition: reverted (0.0109s)

== 20211118103439 RemoveHardcodedPartitionFromLooseFkTriggerFunction: reverting
-- execute("CREATE OR REPLACE FUNCTION insert_into_loose_foreign_keys_deleted_records()\nRETURNS TRIGGER AS\n$$\nBEGIN\n  INSERT INTO loose_foreign_keys_deleted_records\n  (partition, fully_qualified_table_name, primary_key_value)\n  SELECT 1, TG_TABLE_SCHEMA || '.' || TG_TABLE_NAME, old_table.id FROM old_table\n  ON CONFLICT DO NOTHING;\n\n  RETURN NULL;\nEND\n$$ LANGUAGE PLPGSQL\n")
   -> 0.0024s
== 20211118103439 RemoveHardcodedPartitionFromLooseFkTriggerFunction: reverted (0.0025s)

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #345993 (closed)

Edited by Adam Hegyi

Merge request reports