Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old constraint #872

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

squeaky-pl
Copy link
Contributor

@squeaky-pl squeaky-pl commented Sep 3, 2024

The table at this point looks like this:

CREATE TABLE `imapuid` (
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime NOT NULL,
  `deleted_at` datetime DEFAULT NULL,
  `id` bigint NOT NULL AUTO_INCREMENT,
  `account_id` bigint NOT NULL,
  `message_id` bigint NOT NULL,
  `msg_uid` bigint NOT NULL,
  `folder_id` bigint NOT NULL,
  `is_draft` tinyint(1) NOT NULL DEFAULT '0',
  `is_seen` tinyint(1) NOT NULL DEFAULT '0',
  `is_flagged` tinyint(1) NOT NULL DEFAULT '0',
  `is_recent` tinyint(1) NOT NULL DEFAULT '0',
  `is_answered` tinyint(1) NOT NULL DEFAULT '0',
  `extra_flags` varchar(255) COLLATE utf8mb4_general_ci NOT NULL,
  `g_labels` text COLLATE utf8mb4_general_ci,
  PRIMARY KEY (`id`),
  UNIQUE KEY `folder_id` (`folder_id`,`msg_uid`,`account_id`),
  UNIQUE KEY `ix_imapuid_account_id_folder_id_msg_uid_desc` (`account_id`,`folder_id`,`msg_uid` DESC),
  KEY `message_id` (`message_id`),
  KEY `account_id_folder_id` (`account_id`,`folder_id`),
  KEY `ix_imapuid_created_at` (`created_at`),
  KEY `ix_imapuid_msg_uid` (`msg_uid`),
  KEY `ix_imapuid_deleted_at` (`deleted_at`),
  KEY `ix_imapuid_updated_at` (`updated_at`),
  CONSTRAINT `imapuid_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `imapaccount` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT,
  CONSTRAINT `imapuid_ibfk_2` FOREIGN KEY (`message_id`) REFERENCES `message` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT,
  CONSTRAINT `imapuid_ibfk_3` FOREIGN KEY (`folder_id`) REFERENCES `folder` (`id`) ON DELETE CASCADE ON UPDATE RESTRICT
) ENGINE=InnoDB AUTO_INCREMENT=912221389 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci

Note that the old unique constraint UNIQUE KEY folder_id (folder_id,msg_uid,account_id) on the three columns is confusingly called folder_id. That's what you get when you don't name your constraints explicitly.

After merging #870 we are sure that the old index/constraint is not used for retrieving data. So we can drop it, but...

It also powers the foreign key constraint on folder_id column, so I'm adding a one column index to power that constraint.

It's most probable that the KEY account_id_folder_id (account_id,folder_id) can be dropped now as well because it's a prefix of UNIQUE KEY ix_imapuid_account_id_folder_id_msg_uid_desc (account_id,folder_id,msg_uid DESC), but again I want to keep PRs focused and I'll investigate and open another PR.

Migration

-- Running upgrade e3cf974d07a5 -> ac2d6f8489bb

CREATE INDEX folder_id_new ON imapuid (folder_id);

DROP INDEX folder_id ON imapuid;

ALTER TABLE imapuid RENAME INDEX folder_id_new TO folder_id;

SET SQL_SAFE_UPDATES = 0; -- quirk of production MySQL shell configuration

UPDATE alembic_version SET version_num='ac2d6f8489bb' WHERE alembic_version.version_num = 'e3cf974d07a5';

I'll open a separate PR in the downstream with all the steps needed to perform in the downstream.

Based on PR #870

Full chain of PRs as of 2024-09-03

@squeaky-pl squeaky-pl self-assigned this Sep 3, 2024
Base automatically changed from one-more-force-index to master September 3, 2024 15:15
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 3 times, most recently from 4d5cae1 to bdb3a47 Compare September 9, 2024 09:11
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 6 times, most recently from 921be30 to ca0cf85 Compare September 18, 2024 10:20
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 7 times, most recently from 325e3d9 to cbaad9e Compare September 25, 2024 07:28
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 4 times, most recently from 938edf8 to 06a7f64 Compare October 2, 2024 09:26
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch from 06a7f64 to 4d892a1 Compare October 4, 2024 16:11
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 5 times, most recently from df741c6 to da7ff90 Compare October 14, 2024 18:47
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 5 times, most recently from 0a74b35 to 0294080 Compare October 22, 2024 15:28
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 4 times, most recently from 7ca0518 to e71fdd1 Compare October 30, 2024 16:28
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch 2 times, most recently from 8fa5b90 to 1aec674 Compare November 5, 2024 15:14
@squeaky-pl squeaky-pl force-pushed the drop-old-imapuid-constraint branch from 1aec674 to 4ccdebe Compare November 6, 2024 15:57
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