Duplicate indexes in nova-db
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Compute (nova) |
Fix Released
|
Medium
|
Christian Rohmann |
Bug Description
Several nova db tables have duplicate indexes defined. This behavior was deprecated in MySQL 5.6 and presumably will fail on some future MySQL/MariaDB version. There are further some redundant indexes that overlap the left-most prefix over other indexes. The extra indexes have maintenance overhead that does become bothersome at larger scales and seems to be low hanging fruit.
The duplicate indexes are almost always caused by both flagging a field as unique and also specifying a UniqueConstraint in nova.db.
class Instance(BASE, NovaBase, models.
...
...
Examples below are from a 14.0.2 MariaDB 10.0.27 database. I believe this also affects a Postgres backend.
Here are some obvious candidates that are essentially exact duplicates. Pulled using Percona's pt-duplicate-
# #######
# nova.console_
# #######
# console_
# Key definitions:
# KEY `console_
# UNIQUE KEY `uniq_console_
# Column types:
# `token_hash` varchar(255) not null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
# #######
# nova.instances
# #######
# Uniqueness of uniq_instances0uuid ignored because uuid is a duplicate constraint
# uniq_instances0uuid is a duplicate of uuid
# Key definitions:
# UNIQUE KEY `uniq_instances
# UNIQUE KEY `uuid` (`uuid`),
# Column types:
# `uuid` varchar(36) not null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.`instances` DROP INDEX `uniq_instances
# #######
# nova.inventories
# #######
# inventories_
# Key definitions:
# KEY `inventories_
# UNIQUE KEY `uniq_inventori
# Column types:
# `resource_
# `resource_class_id` int(11) not null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
# #######
# nova.networks
# #######
# networks_
# Key definitions:
# KEY `networks_
# UNIQUE KEY `uniq_networks0
# Column types:
# `vlan` int(11) default null
# `deleted` int(11) default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.`networks` DROP INDEX `networks_
# #######
# nova.resource_
# #######
# resource_
# Key definitions:
# KEY `resource_
# UNIQUE KEY `uniq_resource_
# Column types:
# `name` varchar(200) character set utf8 default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
# resource_
# Key definitions:
# KEY `resource_
# UNIQUE KEY `uniq_resource_
# Column types:
# `uuid` varchar(36) not null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
And simply redundant indexes:
# #######
# nova.agent_builds
# #######
# agent_builds_
# Key definitions:
# KEY `agent_
# UNIQUE KEY `uniq_agent_
# Column types:
# `hypervisor` varchar(255) default null
# `os` varchar(255) default null
# `architecture` varchar(255) default null
# `deleted` int(11) default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
# #######
# nova.block_
# #######
# block_device_
# Key definitions:
# KEY `block_
# KEY `block_
# Column types:
# `instance_uuid` varchar(36) default null
# `volume_id` varchar(36) default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
# #######
# nova.fixed_ips
# #######
# address is a left-prefix of uniq_fixed_
# Key definitions:
# KEY `address` (`address`),
# UNIQUE KEY `uniq_fixed_
# Column types:
# `address` varchar(39) default null
# `deleted` int(11) default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.`fixed_ips` DROP INDEX `address`;
# network_id is a left-prefix of fixed_ips_
# Key definitions:
# KEY `network_id` (`network_id`),
# KEY `fixed_
# Column types:
# `network_id` int(11) default null
# `host` varchar(255) default null
# `deleted` int(11) default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.`fixed_ips` DROP INDEX `network_id`;
# #######
# nova.instance_
# #######
# instance_
# Key definitions:
# KEY `instance_
# UNIQUE KEY `uniq_instance_
# Column types:
# `instance_type_id` int(11) not null
# `key` varchar(255) collate utf8_bin default null
# `deleted` int(11) default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
# #######
# nova.instance_
# #######
# instance_type_id is a left-prefix of uniq_instance_
# Key definitions:
# KEY `instance_type_id` (`instance_
# UNIQUE KEY `uniq_instance_
# Column types:
# `instance_type_id` int(11) not null
# `project_id` varchar(255) default null
# `deleted` int(11) default null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
# #######
# nova.inventories
# #######
# inventories_
# Key definitions:
# KEY `inventories_
# UNIQUE KEY `uniq_inventori
# Column types:
# `resource_
# `resource_class_id` int(11) not null
# To remove this duplicate index, execute:
ALTER TABLE `nova`.
tags: | added: db |
Changed in nova: | |
status: | New → Confirmed |
Changed in nova: | |
assignee: | nobody → Andrew Garner (abg) |
status: | Confirmed → In Progress |
Changed in nova: | |
importance: | Undecided → Medium |
Changed in nova: | |
assignee: | Andrew Garner (abg) → nobody |
Changed in nova: | |
status: | In Progress → Confirmed |
Changed in nova: | |
assignee: | nobody → ABHAY (ankatare) |
Changed in nova: | |
status: | Confirmed → In Progress |
The issue is still very present for nova and placement tables:
NOVA:
########
Table: instances (https:/ /opendev. org/openstack/ nova/src/ commit/ c53ec4e48884235 566962bc934cbf2 92ad5b67b8/ nova/db/ main/models. py#L269)
Column: uuid
Indexes:
Unique Constraint: uniq_instances0uuid
Index: uuid
Table: console_auth_tokens (https:/ /opendev. org/openstack/ nova/src/ commit/ c53ec4e48884235 566962bc934cbf2 92ad5b67b8/ nova/db/ main/models. py#L1043) auth_tokens0tok en_hash auth_tokens_ token_hash_ idx
Column: token_hash
Indexes:
Unique Constraint: uniq_console_
Index: console_
Table: resource_providers (https:/ /opendev. org/openstack/ nova/src/ commit/ c53ec4e48884235 566962bc934cbf2 92ad5b67b8/ nova/db/ main/migrations /versions/ 8f2f1571d55b_ initial_ version. py#L1299) providers0name providers_ name_idx
Column: name
Indexes:
Unique Constraint: uniq_resource_
Index: resource_
Table: resource_providers (https:/ /opendev. org/openstack/ nova/src/ commit/ c53ec4e48884235 566962bc934cbf2 92ad5b67b8/ nova/db/ main/migrations /versions/ 8f2f1571d55b_ initial_ version. py#L1298) providers0uuid providers_ uuid_idx
Column: uuid
Indexes:
Unique Constraint: uniq_resource_
Index: resource_
PLACEMENT:
############
Placement /opendev. org/openstack/ placement/ src/commit/ d723f225c194659 961ce5adaeaaf05 15497a48a8/ placement/ db/sqlalchemy/ models. py#L85) provider_ id, resource_class_id s0resource_ provider_ resource_ class resource_ provider_ resource_ class_idx
Table: inventories (https:/
Column: resource_
Indexes:
Unique Constraint: uniq_inventorie
Index: inventories_
Table: placement_ aggregates (https:/ /opendev. org/openstack/ placement/ src/commit/ d723f225c194659 961ce5adaeaaf05 15497a48a8/ placement/ db/sqlalchemy/ models. py#L150) aggregates0uuid aggregates_ uuid
Column: uuid
Indexes:
Unique Constraint: uniq_placement_
Index: ix_placement_
Table: resource_providers (https:/ /opendev. org/openstack/ placement/ src/commit/ d723f225c194659 961ce5adaeaaf05 15497a48a8/ placement/ db/sqlalchemy/ models. py#L55) providers0name providers_ name_idx
Column: name
Indexes:
Unique Constraint: uniq_resource_
Index: resource_
Table: resource_providers (https:/ /opendev. org/openstack/ placement/ src/commit/ d723f225c194659 961ce5adaeaaf05 15497a48a8/ placement/ db/sqlalchemy/ models. py#L53) providers0uuid providers_ uuid_idx
Column: uuid
Indexes:
Unique Constraint: uniq_resource_
Index: resource_