diff -ur zabbix-2.0.8-orig/include/db.h zabbix-2.0.8/include/db.h
--- zabbix-2.0.8-orig/include/db.h	2013-08-21 09:59:20.000000000 -0400
+++ zabbix-2.0.8/include/db.h	2013-09-18 10:55:15.404101594 -0400
@@ -564,8 +564,8 @@
 int	DBexecute_overflowed_sql(char **sql, size_t *sql_alloc, size_t *sql_offset);
 char	*DBget_unique_hostname_by_sample(const char *host_name_sample);
 
-const char	*DBsql_id_cmp(zbx_uint64_t id);
 const char	*DBsql_id_ins(zbx_uint64_t id);
+const char	*DBsql_id_cmp(zbx_uint64_t id);
 
 zbx_uint64_t	DBadd_interface(zbx_uint64_t hostid, unsigned char type,
 		unsigned char useip, const char *ip, const char *dns, unsigned short port);
diff -ur zabbix-2.0.8-orig/src/zabbix_server/operations.c zabbix-2.0.8/src/zabbix_server/operations.c
--- zabbix-2.0.8-orig/src/zabbix_server/operations.c	2013-08-21 09:59:21.000000000 -0400
+++ zabbix-2.0.8/src/zabbix_server/operations.c	2013-09-18 11:31:30.568032209 -0400
@@ -44,7 +44,7 @@
 	DB_RESULT	result;
 	DB_ROW		row;
 	zbx_uint64_t	hostid = 0;
-	char		sql[512];
+	char		*sql = NULL;
 
 	zabbix_log(LOG_LEVEL_DEBUG, "In %s() eventid:" ZBX_FS_UI64,
 			__function_name, event->eventid);
@@ -52,25 +52,31 @@
 	switch (event->object)
 	{
 		case EVENT_OBJECT_DHOST:
-			zbx_snprintf(sql, sizeof(sql),
+			sql = zbx_dsprintf(sql,
 				"select h.hostid"
-				" from hosts h,interface i,dservices ds"
+				" from hosts h,interface i,dservices ds,drules dr,dchecks dc"
 				" where h.hostid=i.hostid"
 					" and i.useip=1"
 					" and i.ip=ds.ip"
 					" and ds.dhostid=" ZBX_FS_UI64
+					" and ds.dcheckid=dc.dcheckid"
+					" and dr.druleid=dc.druleid"
+					" and " ZBX_SQL_NULLCMP("dr.proxy_hostid", "h.proxy_hostid")
 					DB_NODE
 				" order by i.hostid",
 				event->objectid, DBnode_local("i.interfaceid"));
 			break;
 		case EVENT_OBJECT_DSERVICE:
-			zbx_snprintf(sql, sizeof(sql),
+			sql = zbx_dsprintf(sql,
 				"select h.hostid"
-				" from hosts h,interface i,dservices ds"
+				" from hosts h,interface i,dservices ds,drules dr,dchecks dc"
 				" where h.hostid=i.hostid"
 					" and i.useip=1"
 					" and i.ip=ds.ip"
 					" and ds.dserviceid =" ZBX_FS_UI64
+					" and ds.dcheckid=dc.dcheckid"
+					" and dr.druleid=dc.druleid"
+					" and " ZBX_SQL_NULLCMP("dr.proxy_hostid", "h.proxy_hostid")
 					DB_NODE
 				" order by i.hostid",
 				event->objectid, DBnode_local("i.interfaceid"));
@@ -81,6 +87,8 @@
 
 	result = DBselectN(sql, 1);
 
+	zbx_free(sql);
+
 	if (NULL != (row = DBfetch(result)))
 		ZBX_STR2UINT64(hostid, row[0]);
 	DBfree_result(result);
@@ -195,7 +203,7 @@
 	DB_RESULT		result2;
 	DB_ROW			row;
 	DB_ROW			row2;
-	zbx_uint64_t		dhostid, hostid = 0, proxy_hostid, host_proxy_hostid;
+	zbx_uint64_t		dhostid, hostid = 0, proxy_hostid;
 	char			*host = NULL, *host_esc, *host_unique;
 	unsigned short		port;
 	zbx_uint64_t		groupid;
@@ -266,21 +274,21 @@
 			if (0 == hostid)
 			{
 				result2 = DBselect(
-						"select distinct h.hostid,h.proxy_hostid"
+						"select distinct h.hostid"
 						" from hosts h,interface i,dservices ds"
 						" where h.hostid=i.hostid"
+							" and h.proxy_hostid%s"
 							" and i.ip=ds.ip"
 							" and ds.dhostid=" ZBX_FS_UI64
 						       	DB_NODE
 						" order by h.hostid",
+						DBsql_id_cmp(proxy_hostid),
 						dhostid,
 						DBnode_local("h.hostid"));
 
 				if (NULL != (row2 = DBfetch(result2)))
-				{
 					ZBX_STR2UINT64(hostid, row2[0]);
-					ZBX_DBROW2UINT64(host_proxy_hostid, row2[1]);
-				}
+
 				DBfree_result(result2);
 			}
 
@@ -312,14 +320,6 @@
 			}
 			else
 			{
-				if (host_proxy_hostid != proxy_hostid)
-				{
-					DBexecute("update hosts"
-							" set proxy_hostid=%s"
-							" where hostid=" ZBX_FS_UI64,
-							DBsql_id_ins(proxy_hostid), hostid);
-				}
-
 				DBadd_interface(hostid, interface_type, 1, row[2], row[3], port);
 			}
 		}
@@ -335,7 +335,8 @@
 
 		if (NULL != (row = DBfetch(result)))
 		{
-			char	sql[512];
+			char		*sql = NULL;
+			zbx_uint64_t	host_proxy_hostid;
 
 			ZBX_DBROW2UINT64(proxy_hostid, row[0]);
 			host_esc = DBdyn_escape_string_len(row[1], HOST_HOST_LEN);
@@ -357,7 +358,7 @@
 			}
 			DBfree_result(result2);
 
-			zbx_snprintf(sql, sizeof(sql),
+			sql = zbx_dsprintf(sql,
 					"select hostid,proxy_hostid"
 					" from hosts"
 					" where host='%s'"
@@ -370,6 +371,8 @@
 
 			result2 = DBselectN(sql, 1);
 
+			zbx_free(sql);
+
 			if (NULL == (row2 = DBfetch(result2)))
 			{
 				hostid = DBget_maxid("hosts");
