stack queries by name or tenant are inefficient
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Heat |
Fix Released
|
Medium
|
Miguel Grinberg |
Bug Description
Issuing a "heat stack-show <stack-name>" command currently requires all the stacks in the database to be inspected. Below is the SQL analysis of the query (for a stack table with 113 stacks in it):
mysql> explain select * from stack where deleted_at=NULL AND name='stack57';
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | stack | ALL | NULL | NULL | NULL | NULL | 113 | Using where |
+----+-
1 row in set (0.00 sec)
Note how MySQL had to review all 113 entries to find the one that was requested.
Likewise, a "heat stack-list" query, requires all stacks to be inspected to find those that belong to the user's tenant. MySQL analysis (there are only 13 stacks on the specified tenant):
mysql> explain select * from stack where deleted_at=NULL AND tenant=
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | stack | ALL | NULL | NULL | NULL | NULL | 113 | Using where |
+----+-
1 row in set (0.00 sec)
Adding indexes for the name and tenant columns improves queries significantly:
mysql> create index stack_name on stack (name);
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> create index stack_tenant on stack(tenant);
Query OK, 0 rows affected, 2 warnings (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 2
mysql> explain select * from stack where deleted_at=NULL AND name='stack57';
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | stack | ref | stack_name | stack_name | 768 | const | 1 | Using where |
+----+-
1 row in set (0.00 sec)
mysql> explain select * from stack where deleted_at=NULL AND tenant=
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | stack | ref | stack_tenant | stack_tenant | 768 | const | 13 | Using where |
+----+-
1 row in set (0.00 sec)
Changed in heat: | |
assignee: | nobody → Miguel Grinberg (miguelgrinberg) |
Changed in heat: | |
status: | Triaged → In Progress |
Changed in heat: | |
milestone: | none → kilo-3 |
status: | Fix Committed → Fix Released |
Changed in heat: | |
milestone: | kilo-3 → 2015.1.0 |
see bug 1421885 and https:/ /review. openstack. org/#/c/ 57086/ for a previous discussion on indexes