Index could be added on product_price_history
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Financial controlling and costing |
Fix Released
|
Undecided
|
Guewen Baconnier @ Camptocamp |
Bug Description
Going through a performance / index analysis, I used this query (from http://
SELECT relname, seq_scan-idx_scan AS too_much_seq, case when seq_scan-idx_scan>0 THEN 'Missing Index?' ELSE 'OK' END, pg_relation_
FROM pg_stat_all_tables
WHERE schemaname='public' AND pg_relation_
And it appeared that product_
I also noticed in the logs that the SELECT queries on this table is always in this form:
SELECT DISTINCT ON (product_id, name) datetime, product_id, name, amount FROM product_
3 AND name IN ('standard_price') AND datetime <= '2014-05-03 09:34:30' ORDER BY product_id, name, datetime DESC, id DESC;
So, it could be nice to add an index on the 4 fields.
Explain plan before:
-------
Unique (cost=329.
-> Sort (cost=329.
Sort Key: datetime, id
Sort Method: quicksort Memory: 25kB
-> Seq Scan on product_
Total runtime: 4.905 ms
Explain plan after index
create index product_
-------
Unique (cost=8.29..8.30 rows=1 width=32) (actual time=0.135..0.136 rows=1 loops=1)
-> Sort (cost=8.29..8.29 rows=1 width=32) (actual time=0.133..0.134 rows=1 loops=1)
Sort Key: datetime, id
Sort Method: quicksort Memory: 25kB
-> Index Scan using product_
Total runtime: 0.190 ms
Related branches
- Yannick Vaucher @ Camptocamp: Approve (code review, no test)
- Pedro Manuel Baeza: Approve (code review)
-
Diff: 26 lines (+12/-1)1 file modifiedproduct_price_history/product_price_history.py (+12/-1)
Changed in margin-analysis: | |
assignee: | nobody → Guewen Baconnier @ Camptocamp (gbaconnier-c2c) |
status: | New → In Progress |
description: | updated |
Changed in margin-analysis: | |
status: | In Progress → Fix Committed |
Changed in margin-analysis: | |
status: | Fix Committed → Fix Released |