Skip to content

Commit 29e2f0f

Browse files
mprokopchuksb-abhish3k
authored andcommitted
Added performance indexes
1 parent 51c5249 commit 29e2f0f

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
-- Licensed to the Apache Software Foundation (ASF) under one
2+
-- or more contributor license agreements. See the NOTICE file
3+
-- distributed with this work for additional information
4+
-- regarding copyright ownership. The ASF licenses this file
5+
-- to you under the Apache License, Version 2.0 (the
6+
-- "License"); you may not use this file except in compliance
7+
-- with the License. You may obtain a copy of the License at
8+
--
9+
-- http://www.apache.org/licenses/LICENSE-2.0
10+
--
11+
-- Unless required by applicable law or agreed to in writing,
12+
-- software distributed under the License is distributed on an
13+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
-- KIND, either express or implied. See the License for the
15+
-- specific language governing permissions and limitations
16+
-- under the License.
17+
18+
-- Idempotent ADD INDEX
19+
DROP PROCEDURE IF EXISTS `cloud`.`IDEMPOTENT_ADD_INDEX`;
20+
CREATE PROCEDURE `cloud`.`IDEMPOTENT_ADD_INDEX` (
21+
IN in_index_name VARCHAR(200)
22+
,IN in_table_name VARCHAR(200)
23+
,IN in_index_definition VARCHAR(1000)
24+
)
25+
BEGIN
26+
DECLARE CONTINUE HANDLER FOR 1061 BEGIN END; SET @ddl = CONCAT('ALTER TABLE ', in_table_name, ' ADD INDEX ', in_index_name, ' ', in_index_definition, ', ALGORITHM=INPLACE, LOCK=NONE'); PREPARE stmt FROM @ddl; EXECUTE stmt; DEALLOCATE PREPARE stmt; END;

‎engine/schema/src/main/resources/META-INF/db/schema-42210to42220.sql‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,31 @@
1919
-- Schema upgrade from 4.22.1.0 to 4.22.2.0
2020
--;
2121

22+
-- Composite index on nics(instance_id, removed) to fix wrong-index pick in user_vm_view.
23+
-- The optimizer picks i_nics__removed over fk_nics__instance_id for the
24+
-- LEFT JOIN nics ON (vm_instance.id = nics.instance_id AND nics.removed IS NULL)
25+
-- because neither single-column index covers both predicates.
26+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_nics__instance_id_removed', 'cloud.nics', '(instance_id, removed)');
27+
-- account_view performance: covers all 10 resource_limit LEFT JOINs
28+
-- which filter on (account_id = ? AND type = ? AND tag IS NULL)
29+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_resource_limit__acct_type_tag', 'cloud.resource_limit', '(account_id, type, tag)');
30+
-- account_vmstats_view: enables index-only scan for GROUP BY account_id, state
31+
-- WHERE vm_type = 'User' AND removed IS NULL
32+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_vm_instance__account_id_state', 'cloud.vm_instance', '(account_id, state)');
33+
-- free_ip_view: covers WHERE state = 'Free' JOIN vlan ON vlan.id = vlan_db_id
34+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_user_ip_address__state_vlan', 'cloud.user_ip_address', '(state, vlan_db_id)');
35+
-- Prometheus/AlertManager IP count queries: covers WHERE data_center_id = ? AND removed IS NULL
36+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_user_ip_address__dc_removed_vlan', 'cloud.user_ip_address', '(data_center_id, removed, vlan_db_id)');
37+
-- event table: compound index for frequent Compute API queries
38+
-- (WHERE archived = 0 AND level = ? ORDER BY created)
39+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__archived_level_created', 'cloud.event', '(archived, level, created)');
40+
-- event table: default listEvents path (account + archived + sort)
41+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__account_archived_created', 'cloud.event', '(account_id, archived, created DESC)');
42+
-- event table: domain-scoped ACL queries (completely unindexed)
43+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__domain_id', 'cloud.event', '(domain_id)');
44+
-- event table: resource-based event lookups (added in 4.16.1 with no index)
45+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__resource', 'cloud.event', '(resource_id, resource_type)');
46+
-- event table: start_id for related-event queries and event_view self-join
47+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_event__start_id', 'cloud.event', '(start_id)');
48+
-- host table: covers findByName lookups (WHERE name = ? AND removed IS NULL)
49+
CALL `cloud`.`IDEMPOTENT_ADD_INDEX`('i_host__name_removed', 'cloud.host', '(name, removed)');

0 commit comments

Comments
 (0)