[ZBX-4840] Adding another index on "zabbix.history" table greatly improves performance Created: 2012 Apr 05 Updated: 2017 May 30 Resolved: 2012 Apr 12 |
|
Status: | Closed |
Project: | ZABBIX BUGS AND ISSUES |
Component/s: | Server (S) |
Affects Version/s: | 1.9.8 (beta) |
Fix Version/s: | 2.0.0rc3 |
Type: | Incident report | Priority: | Minor |
Reporter: | Michael Tewner | Assignee: | Unassigned |
Resolution: | Fixed | Votes: | 0 |
Labels: | database, mysql | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified |
Description |
Hi Guys - As shown below, I added an index to the "history" table on the itemid, clock, and ns fields. This greatly improved performance of many of the common queries which were previously performing filesorts. One common query went from 200 seconds to <.03 seconds. There is a tradeoff that the index is on almost all of the fields. Perhaps an index-only table would help here (if they exist in MySQL). CREATE index history_itemid_clock_ns on history (itemid,clock,ns) mysql> show indexes from history ;
--------
-------- Before Index:
---
--- After Index:
---
--- And the performance gain: mysql> select value from history ignore index (history_itemid_clock_ns) where itemid=24847 and clock<1333520700 order by itemid,clock desc,ns desc limit 1;
------------
------------ mysql> select value from history where itemid=24847 and clock<1333520700 order by itemid,clock desc,ns desc limit 1;
------------
------------ |
Comments |
Comment by Alexey Pustovalov [ 2012 Apr 06 ] |
I think it worth to do it. |
Comment by Alexander Vladishev [ 2012 Apr 12 ] |
Fixed in the development branch svn://svn.zabbix.com/branches/dev/ZBX-4840. The problem was solved by change of SQL queries. The database schema remained without changes. |
Comment by dimir [ 2012 Apr 13 ] |
Successfully tested, excellent improvement. |
Comment by Alexander Vladishev [ 2012 Apr 13 ] |
Fixed in version pre-2.0.0rc3 revision 26813. |