[ZBX-14696] Inefficient index causing full table scan on problem_tag table Created: 2018 Aug 08  Updated: 2024 Apr 10  Resolved: 2018 Aug 27

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 4.0.0alpha9
Fix Version/s: 4.0.0beta1, 4.0 (plan)

Type: Problem report Priority: Trivial
Reporter: Vladislavs Sokurenko Assignee: Andris Zeila
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Team: Team A
Team: Team A
Sprint: Sprint 40, Sprint 41
Story Points: 1

 Description   
| problem_tag | CREATE TABLE `problem_tag` (
  `problemtagid` bigint(20) unsigned NOT NULL,
  `eventid` bigint(20) unsigned NOT NULL,
  `tag` varchar(255) COLLATE utf8mb4_bin NOT NULL DEFAULT '',
  `value` varchar(255) COLLATE utf8_bin NOT NULL DEFAULT '',
  PRIMARY KEY (`problemtagid`),
  KEY `problem_tag_1` (`eventid`),
  KEY `problem_tag_2` (`tag`,`value`),
  CONSTRAINT `c_problem_tag_1` FOREIGN KEY (`eventid`) REFERENCES `problem` (`eventid`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_bin |
explain select eventid,tag,value from problem_tag where eventid in (2,3,6,7,10,12,13,15,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50) order by eventid;
+------+-------------+-------------+------+---------------+------+---------+------+------+-----------------------------+
| id   | select_type | table       | type | possible_keys | key  | key_len | ref  | rows | Extra                       |
+------+-------------+-------------+------+---------------+------+---------+------+------+-----------------------------+
|    1 | SIMPLE      | problem_tag | ALL  | problem_tag_1 | NULL | NULL    | NULL |   19 | Using where; Using filesort |
+------+-------------+-------------+------+---------------+------+---------+------+------+-----------------------------+

Suggested:

CREATE INDEX problem_tag_3 ON problem_tag (eventid,tag,value);
DROP INDEX problem_tag_1 ON problem_tag;
DROP INDEX problem_tag_2 ON problem_tag;
explain select eventid,tag,value from problem_tag where eventid in (2,3,6,7,10,12,13,15,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50) order by eventid;
+------+-------------+-------------+-------+---------------+---------------+---------+------+------+--------------------------+
| id   | select_type | table       | type  | possible_keys | key           | key_len | ref  | rows | Extra                    |
+------+-------------+-------------+-------+---------------+---------------+---------+------+------+--------------------------+
|    1 | SIMPLE      | problem_tag | index | problem_tag_3 | problem_tag_3 | 1542    | NULL |   19 | Using where; Using index |
+------+-------------+-------------+-------+---------------+---------------+---------+------+------+--------------------------+
1 row in set (0.00 sec)



 Comments   
Comment by Andris Zeila [ 2018 Aug 14 ]

Released in:

  • pre-4.0.0alpha10 r83764
Generated at Sat Apr 20 07:49:22 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.