ceilometer sample-list with limit does a table scan and takes long time to complete, needs optimization
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Ceilometer |
Incomplete
|
Undecided
|
Rohit Jaiswal |
Bug Description
ceilometer sample-list -m instance -l 20 results in the following sql query -
SELECT sample.id AS id, meter.name AS counter_name, meter.type AS counter_type, meter.unit AS counter_unit, sample.volume AS counter_volume, resource.
Running explain plan on it generates the following plan -
+----+-
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | SIMPLE | meter | ref | PRIMARY,
| 1 | SIMPLE | sample | ref | ix_sample_
| 1 | SIMPLE | resource | eq_ref | PRIMARY | PRIMARY | 4 | ceilometer.
+----+-
The number 3363398 denotes all the rows being scanned by the join in the sample table even when only 20 results are expected.
There should be a better way to perform this query so that the number of rows scanned is minimized and use the indexes in a better way to achieve that.
description: | updated |
Changed in ceilometer: | |
status: | New → In Progress |
Changed in ceilometer: | |
assignee: | nobody → Rohit Jaiswal (rohit-jaiswal-3) |
description: | updated |
summary: |
- ceilometer sample-list does a table scan and takes long time to - complete, needs optimization + ceilometer sample-list with limit does a table scan and takes long time + to complete, needs optimization |
With the fix in place, ceilometer sample-list -m instance -l 20 generates the following query -
SELECT sample.id AS id, meter.name AS counter_name, meter.type AS counter_type, meter.unit AS counter_unit, sample.volume AS counter_volume, resource. resource_ id AS resource_id, resource.source_id AS source_id, resource.user_id AS user_id, resource.project_id AS project_id, resource. resource_ metadata AS resource_metadata, resource. internal_ id AS internal_id, sample.timestamp AS timestamp, sample.message_id AS message_id, sample. message_ signature AS message_signature, sample.recorded_at AS recorded_at FROM sample INNER JOIN (select * from meter where meter.name = 'instance') as meter ON sample.meter_id = meter.id INNER JOIN resource ON sample.resource_id = resource. internal_ id ORDER BY sample.timestamp DESC limit 20;
Running explain on it generates the following plan -
+----+- ------- -----+- ------- ----+-- ------+ ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ---+--- ------- ------- ----+-- ------- +------ ------- ------- ------- ----+-- -----+- ------- ------- ------- ----+ ------- -----+- ------- ----+-- ------+ ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ---+--- ------- ------- ----+-- ------- +------ ------- ------- ------- ----+-- -----+- ------- ------- ------- ----+ meter_id, ix_sample_ resource_ id,ix_sample_ meter_id_ resource_ id | ix_sample_timestamp | 11 | NULL | 15927 | Using where | sample. resource_ id | 1 | | ix_meter_ name | def_unique | 767 | | 1 | Using where; Using index | ------- -----+- ------- ----+-- ------+ ------- ------- ------- ------- ------- ------- ------- ------- ------- ------- ---+--- ------- ------- ----+-- ------- +------ ------- ------- ------- ----+-- -----+- ------- ------- ------- ----+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-
| 1 | PRIMARY | <derived2> | system | NULL | NULL | NULL | NULL | 1 | |
| 1 | PRIMARY | sample | index | ix_sample_
| 1 | PRIMARY | resource | eq_ref | PRIMARY | PRIMARY | 4 | ceilometer.
| 2 | DERIVED | meter | ref | def_unique,
+----+-
The number of rows scanned in the sample table has gone down to 15,927.
From the plan, it also seems that the file sort and temporary table are not needed any more.
Querying with meter as image gives the following query -
SELECT sample.id AS id, meter.name AS counter_name, meter.type AS counter_type, meter.unit AS counter_unit, sample.volume AS counter_volume, resource. resource_ id AS resource_id, resource.source_id AS source_id, resource.user_id AS user_id, resource.project_id AS project_id, resource. resource_ metadata AS resource_metadata, resource. internal_ id AS internal_id, samp...