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

Report unique indices that cover nullable columns #162

Open
macbre opened this issue Mar 10, 2020 · 0 comments
Open

Report unique indices that cover nullable columns #162

macbre opened this issue Mar 10, 2020 · 0 comments
Labels
Milestone

Comments

@macbre
Copy link
Owner

macbre commented Mar 10, 2020

https://dev.mysql.com/doc/refman/8.0/en/create-index.html#create-index-unique

A UNIQUE index permits multiple NULL values for columns that can contain NULL.

Links

Examples

CREATE TABLE `progress` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `plan_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `question_id` int(10) unsigned NOT NULL,
  `resolved_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_plan_progress_unique` (`user_id`,`question_id`,`deleted_at`),
  KEY `users_plan_progress_plan_id_index` (`plan_id`)
) ENGINE=InnoDB;

Fixed

CREATE TABLE `progress` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `plan_id` int(10) unsigned NOT NULL,
  `user_id` int(10) unsigned NOT NULL,
  `question_id` int(10) unsigned NOT NULL,
  `resolved_at` timestamp NULL DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `is_not_archived` tinyint(4) GENERATED ALWAYS AS (if((`deleted_at` is null),1,NULL)) VIRTUAL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `users_plan_progress_unique` (`user_id`,`question_id`,`is_not_archived`),
  KEY `users_plan_progress_plan_id_index` (`plan_id`)
) ENGINE=InnoDB;
@macbre macbre added the linters label Mar 10, 2020
@macbre macbre added this to the v1.3 milestone Mar 10, 2020
@macbre macbre modified the milestones: v1.3, v1.4.0 Aug 22, 2020
@macbre macbre modified the milestones: v1.4.0, v1.5.0 Dec 24, 2020
@macbre macbre modified the milestones: v1.5.0, v1.6.0 Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant