View Full Version : Zabbix 1.5 - Invalid Query
Palmertree
20-03-2008, 14:08
I am seeing this every second almost in my database logs:
select g.groupid, g.name from groups g left join hosts_groups hg on g.groupid=hg.groupid and hg.hostid=100100000000171 where (g.groupid div 100000000000000) in (1) AND hg.hostid is NULL order by g.name,g.groupid;
Looks invalid since you can not compare a hostid number and also look for only ones that are NULL.
Palmertree
20-03-2008, 14:15
mysql> explain select g.groupid, g.name from groups g left join hosts_groups hg on g.groupid=hg.groupid and hg.hostid=100100000000264 where (g.groupid div 100000000000000) in (1) AND hg.hostid is NULL order by g.name,g.groupid;
+----+-------------+-------+-------+--------------------------------------+----------------+---------+------------------------+------+------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+--------------------------------------+----------------+---------+------------------------+------+------------------------------------------+
| 1 | SIMPLE | g | index | NULL | groups_1 | 66 | NULL | 113 | Using where; Using index; Using filesort |
| 1 | SIMPLE | hg | ref | hosts_groups_1,hosts_groups_2.custom | hosts_groups_1 | 16 | const,zabbix.g.groupid | 1 | Using where; Using index; Not exists |
+----+-------------+-------+-------+--------------------------------------+----------------+---------+------------------------+------+------------------------------------------+
2 rows in set
Palmertree
20-03-2008, 14:17
Got rid of the NULL in the where cause and it looks like this:
mysql> explain select g.groupid, g.name from groups g left join hosts_groups hg on g.groupid=hg.groupid and hg.hostid=100100000000264 where (g.groupid div 100000000000000) in (1)
order by g.name,g.groupid;
+----+-------------+-------+-------+--------------------------------------+----------------+---------+------------------------+------+------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+--------------------------------------+----------------+---------+------------------------+------+------------------------------------------+
| 1 | SIMPLE | g | index | NULL | groups_1 | 66 | NULL | 113 | Using where; Using index; Using filesort |
| 1 | SIMPLE | hg | ref | hosts_groups_1,hosts_groups_2.custom | hosts_groups_1 | 16 | const,zabbix.g.groupid | 1 | Using index |
+----+-------------+-------+-------+--------------------------------------+----------------+---------+------------------------+------+------------------------------------------+
2 rows in set
Looks like it is in hosts.php around line 847.
Palmertree
20-03-2008, 14:26
Never mind. I think that it is right. Looks like the group names that need to return are the ones that do not match up which the NULL statement does. Sorry for the post.