Index: include/db.h
===================================================================
--- include/db.h	(revision 20279)
+++ include/db.h	(working copy)
@@ -208,11 +208,11 @@
 #define HTTPSTEP_REQUIRED_LEN		255
 #define HTTPSTEP_REQUIRED_LEN_MAX	HTTPSTEP_REQUIRED_LEN+1
 
-#define ZBX_SQL_ITEM_FIELDS	"i.itemid,i.key_,h.host,i.type,i.history,i.lastvalue,"		\
-				"i.prevvalue,i.hostid,i.value_type,i.delta,i.prevorgvalue,"	\
-				"i.lastclock,i.units,i.multiplier,i.formula,i.status,"		\
+#define ZBX_SQL_ITEM_FIELDS	"i.itemid,i.key_,h.host,i.type,i.history,its.lastvalue,"	\
+				"its.prevvalue,i.hostid,i.value_type,i.delta,its.prevorgvalue,"	\
+				"its.lastclock,i.units,i.multiplier,i.formula,i.status,"	\
 				"i.valuemapid,i.trends,i.data_type"
-#define ZBX_SQL_ITEM_TABLES	"hosts h,items i"
+#define ZBX_SQL_ITEM_TABLES	"hosts h,items i,items_state its"
 #define ZBX_SQL_ITEM_FIELDS_NUM	19
 #define ZBX_SQL_ITEM_SELECT	ZBX_SQL_ITEM_FIELDS " from " ZBX_SQL_ITEM_TABLES
 
Index: src/zabbix_server/poller/checks_calculated.c
===================================================================
--- src/zabbix_server/poller/checks_calculated.c	(revision 20279)
+++ src/zabbix_server/poller/checks_calculated.c	(working copy)
@@ -209,6 +209,7 @@
 	zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 512,
 			"select %s"
 			" where h.hostid=i.hostid"
+				" and its.itemid = i.itemid"
 				" and h.status=%d"
 				" and i.status=%d"
 				" and (",
Index: src/zabbix_server/trapper/active.c
===================================================================
--- src/zabbix_server/trapper/active.c	(revision 20279)
+++ src/zabbix_server/trapper/active.c	(working copy)
@@ -168,8 +168,8 @@
 	buffer = zbx_malloc(buffer, buffer_alloc);
 
 	buffer_offset = 0;
-	zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 1024,
-			"select i.key_,i.delay,i.lastlogsize from items i,hosts h"
+	zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 1042,
+			"select i.key_,i.delay,its.lastlogsize from items i,items_state its,hosts h"
 			" where i.hostid=h.hostid and h.status=%d and i.type=%d and h.hostid=" ZBX_FS_UI64
 			" and h.proxy_hostid is null",
 			HOST_STATUS_MONITORED,
@@ -178,8 +178,8 @@
 
 	if (0 != CONFIG_REFRESH_UNSUPPORTED)
 	{
-		zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 256,
-				" and (i.status=%d or (i.status=%d and i.lastclock+%d<=%d))",
+		zbx_snprintf_alloc(&buffer, &buffer_alloc, &buffer_offset, 258,
+				" and (i.status=%d or (i.status=%d and its.lastclock+%d<=%d))",
 				ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED,
 				CONFIG_REFRESH_UNSUPPORTED, time(NULL));
 	}
@@ -314,17 +314,17 @@
 	name_esc = DBdyn_escape_string(host);
 
 	sql_offset = 0;
-	zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 1024,
-			"select i.key_,i.delay,i.lastlogsize,i.mtime"
-			" from items i,hosts h"
-			" where i.hostid=h.hostid and h.status=%d and i.type=%d and h.hostid=" ZBX_FS_UI64
+	zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 1068,
+			"select i.key_,i.delay,i.lastlogsize,its.mtime"
+			" from items i,items_state its,hosts h"
+			" where i.hostid=h.hostid and its.itemid = i.itemid and h.status=%d and i.type=%d and h.hostid=" ZBX_FS_UI64
 			" and h.proxy_hostid is null",
 			HOST_STATUS_MONITORED,
 			ITEM_TYPE_ZABBIX_ACTIVE,
 			hostid);
 
 	if (0 != CONFIG_REFRESH_UNSUPPORTED)
-		zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 256, " and (i.status=%d or (i.status=%d and i.lastclock+%d<=%d))",
+		zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 256, " and (i.status=%d or (i.status=%d and its.lastclock+%d<=%d))",
 				ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED,
 				CONFIG_REFRESH_UNSUPPORTED, time(NULL));
 	else
Index: src/libs/zbxserver/expression.c
===================================================================
--- src/libs/zbxserver/expression.c	(revision 20279)
+++ src/libs/zbxserver/expression.c	(working copy)
@@ -1318,9 +1318,9 @@
 		goto fail;
 
 	result = DBselect(
-			"select i.itemid,i.value_type,i.valuemapid,i.units,i.lastvalue"
-			" from items i,functions f"
-			" where i.itemid=f.itemid"
+			"select i.itemid,i.value_type,i.valuemapid,i.units,its.lastvalue"
+			" from items i,items_state its,functions f"
+			" where i.itemid=f.itemid and i.itemid = its.itemid"
 				" and f.functionid=" ZBX_FS_UI64,
 			functionid);
 
@@ -2710,7 +2710,7 @@
 
 			result = DBselect(
 					"select distinct %s,f.function,f.parameter,h.status from %s,functions f"
-					" where i.hostid=h.hostid and i.itemid=f.itemid and f.functionid=%s",
+					" where i.hostid=h.hostid and i.itemid=f.itemid and i.itemid = its.itemid and f.functionid=%s",
 					ZBX_SQL_ITEM_FIELDS,
 					ZBX_SQL_ITEM_TABLES,
 					functionid);
Index: src/libs/zbxserver/evalfunc.c
===================================================================
--- src/libs/zbxserver/evalfunc.c	(revision 20279)
+++ src/libs/zbxserver/evalfunc.c	(working copy)
@@ -2507,7 +2507,7 @@
 	result = DBselect(
 			"select %s"
 			" where h.host='%s'"
-				" and h.hostid=i.hostid"
+				" and h.hostid=i.hostid and i.itemid = its.itemid"
 				" and i.key_='%s'"
 				DB_NODE,
 			ZBX_SQL_ITEM_SELECT, host_esc, key_esc, DBnode_local("h.hostid"));
Index: src/libs/zbxdbcache/dbcache.c
===================================================================
--- src/libs/zbxdbcache/dbcache.c	(revision 20279)
+++ src/libs/zbxdbcache/dbcache.c	(working copy)
@@ -999,11 +999,12 @@
 {
 	char	*value_esc;
 
-	zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 56, "update items set lastclock=%d,lastns=%d",
+	zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 56, "update items_state set lastclock=%d,lastns=%d",
 			h->clock, h->ns);
 
-	if (ITEM_STATUS_NOTSUPPORTED == h->status)
+	if (ITEM_STATUS_NOTSUPPORTED == h->status) {
 		goto notsupported;
+	}
 
 	switch (h->value_type)
 	{
@@ -1144,14 +1145,6 @@
 notsupported:
 	if (ITEM_STATUS_NOTSUPPORTED == h->status)
 	{
-		if (ITEM_STATUS_NOTSUPPORTED != item->status)
-		{
-			zabbix_log(LOG_LEVEL_WARNING, "Item [%s] became not supported: %s",
-					zbx_host_key_string(h->itemid), h->value_orig.err);
-
-			zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 20, ",status=%d", (int)h->status);
-		}
-
 		if (0 != strcmp(item->error, h->value_orig.err))
 		{
 			value_esc = DBdyn_escape_string_len(h->value_orig.err, ITEM_ERROR_LEN);
@@ -1166,12 +1159,35 @@
 	{
 		if (ITEM_STATUS_NOTSUPPORTED == item->status)
 		{
-			zabbix_log(LOG_LEVEL_WARNING, "Item [%s] became supported", zbx_host_key_string(item->itemid));
-
-			zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 32, ",status=%d,error=''", (int)h->status);
+			zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 32, ",error=''");
 		}
 	}
 
+        if (ITEM_STATUS_NOTSUPPORTED == h->status)
+        {
+                if (ITEM_STATUS_NOTSUPPORTED != item->status)
+                {
+                        zabbix_log(LOG_LEVEL_WARNING, "Item [%s] became not supported: %s",
+                                        zbx_host_key_string(h->itemid), h->value_orig.err);
+
+	                zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 32, " where itemid=" ZBX_FS_UI64 ";\n", item->itemid);
+
+    		        zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 64, "update items set status=%d", (int)h->status);
+
+                }
+        }
+        else
+        {
+                if (ITEM_STATUS_NOTSUPPORTED == item->status)
+                {
+                        zabbix_log(LOG_LEVEL_WARNING, "Item [%s] became supported", zbx_host_key_string(item->itemid));
+
+	                zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 32, " where itemid=" ZBX_FS_UI64 ";\n", item->itemid);
+
+    		        zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 64, "update items set status=%d", (int)h->status);
+                }
+        }
+
 	zbx_snprintf_alloc(&sql, &sql_allocated, sql_offset, 32, " where itemid=" ZBX_FS_UI64 ";\n", item->itemid);
 }
 
@@ -1249,11 +1265,13 @@
 	for (i = 0; i < history_num; i++)
 		uint64_array_add(&ids, &ids_alloc, &ids_num, history[i].itemid, 64);
 
-	zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 247,
-			"select i.itemid,i.status,i.lastclock,i.prevorgvalue,i.delta,i.multiplier,i.formula,"
-				"i.history,i.trends,i.lastns,i.hostid,i.profile_link,hp.profile_mode,i.valuemapid,"
-				"i.units,i.error"
+	zbx_snprintf_alloc(&sql, &sql_allocated, &sql_offset, 305,
+			"select i.itemid,i.status,its.lastclock,its.prevorgvalue,i.delta,i.multiplier,i.formula,"
+				"i.history,i.trends,its.lastns,i.hostid,i.profile_link,hp.profile_mode,i.valuemapid,"
+				"i.units,its.error"
 			" from items i"
+				" left join items_state its"
+					" on its.itemid=i.itemid"
 				" left join host_profile hp"
 					" on hp.hostid=i.hostid"
 			" where");
Index: src/libs/zbxdbhigh/proxy.c
===================================================================
--- src/libs/zbxdbhigh/proxy.c	(revision 20279)
+++ src/libs/zbxdbhigh/proxy.c	(working copy)
@@ -2634,14 +2634,18 @@
 					" (" ZBX_FS_UI64 ",'%s','%s'," ZBX_FS_UI64 ",%d,%d,%d,"
 					"%d,'%s',%d,%d,%d,'%s','%s',%d,%d,'%s','%s',%s,'%s','%s',"
 					"'%s','%s','%s','%s',%d,'%s','%s',%d,'%s','%s','%s',"
-					"'%s','%s'," ZBX_FS_UI64 ",%d);\n",
+					"'%s','%s'," ZBX_FS_UI64 ",%d);\n"
+				"insert into items_state"
+					" (itemid)"
+				" values"
+					" (" ZBX_FS_UI64 ");\n",
 				new_itemid, name_esc, key_esc, hostid, (int)type, (int)value_type, (int)data_type,
 				delay, delay_flex_esc, history, trends, (int)status, trapper_hosts_esc, units_esc,
 				multiplier, delta, formula_esc, logtimefmt_esc, DBsql_id_ins(valuemapid), params_esc,
 				ipmi_sensor_esc, snmp_community_esc, snmp_oid_esc, port_esc,
 				snmpv3_securityname_esc, (int)snmpv3_securitylevel, snmpv3_authpassphrase_esc,
 				snmpv3_privpassphrase_esc, (int)authtype, username_esc, password_esc, publickey_esc,
-				privatekey_esc, description_esc, interfaceid, ZBX_FLAG_DISCOVERY_CREATED);
+				privatekey_esc, description_esc, interfaceid, ZBX_FLAG_DISCOVERY_CREATED,new_itemid);
 
 		zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, 256 + strlen(key_proto_esc),
 				"insert into item_discovery"
Index: src/libs/zbxdbhigh/db.c
===================================================================
--- src/libs/zbxdbhigh/db.c	(revision 20279)
+++ src/libs/zbxdbhigh/db.c	(working copy)
@@ -617,9 +617,10 @@
 		trigger_error = row[4];
 
 		result2 = DBselect(
-				"select distinct i.itemid,i.type,i.lastclock,i.delay,i.delay_flex,i.interfaceid"
-				" from items i,functions f,triggers t"
+				"select distinct i.itemid,i.type,its.lastclock,i.delay,i.delay_flex,i.interfaceid"
+				" from items i,items_state its, functions f,triggers t"
 				" where i.itemid=f.itemid"
+					" and its.itemid = i.itemid"
 					" and f.triggerid=t.triggerid"
 					" and i.type not in (%d)"
 					" and t.triggerid=" ZBX_FS_UI64,
@@ -817,16 +818,17 @@
 	now = time(NULL);
 
 	result = DBselect(
-			"select i.itemid,i.type,i.delay,i.delay_flex,i.lastclock,i.interfaceid,h.proxy_hostid"
-			" from items i,hosts h"
+			"select i.itemid,i.type,i.delay,i.delay_flex,its.lastclock,i.interfaceid,h.proxy_hostid"
+			" from items i,items_state its,hosts h"
 			" where i.hostid=h.hostid"
+				" and its.itemid = i.itemid"
 				" and h.status=%d"
 				" and i.status=%d"
 				" and i.value_type not in (%d)"
 				" and i.key_ not in ('%s','%s')"
 				" and ("
-					"i.lastclock is not null"
-					" and i.lastclock<%d"
+					"its.lastclock is not null"
+					" and its.lastclock<%d"
 					")"
 				" and ("
 					"i.type in (%d,%d,%d,%d,%d,%d,%d,%d,%d)"
Index: src/libs/zbxdbhigh/host.c
===================================================================
--- src/libs/zbxdbhigh/host.c	(revision 20279)
+++ src/libs/zbxdbhigh/host.c	(working copy)
@@ -2766,7 +2766,11 @@
 						" (" ZBX_FS_UI64 ",'%s','%s'," ZBX_FS_UI64 ",%d,%s,%s,"
 						"%s,'%s',%s,%s,%s,'%s','%s',%s,%s,'%s','%s',%s,'%s','%s',"
 						"'%s','%s','%s',%s,'%s','%s',%s,'%s','%s','%s',"
-						"'%s'," ZBX_FS_UI64 ",%d,'%s','%s',%s,%s);\n",
+						"'%s'," ZBX_FS_UI64 ",%d,'%s','%s',%s,%s);\n"
+					"insert into items_state"
+						" (itemid)"
+					" values"
+						" (" ZBX_FS_UI64 ");\n",
 					itemid,
 					name_esc,
 					key_esc,
@@ -2804,7 +2808,8 @@
 					filter_esc,
 					description_esc,
 					row[34],	/* profile_link */
-					DBsql_id_ins(interfaceid));
+					DBsql_id_ins(interfaceid),
+					itemid);
 
 			zbx_free(key_esc);
 
Index: create/schema/schema.sql
===================================================================
--- create/schema/schema.sql	(revision 20279)
+++ create/schema/schema.sql	(working copy)
@@ -765,23 +765,17 @@
 FIELD		|delay		|t_integer	|'0'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|history	|t_integer	|'90'	|NOT NULL	|ZBX_SYNC
 FIELD		|trends		|t_integer	|'365'	|NOT NULL	|ZBX_SYNC
-FIELD		|lastvalue	|t_varchar(255)	|	|NULL		|0
-FIELD		|lastclock	|t_time		|	|NULL		|0
-FIELD		|prevvalue	|t_varchar(255)	|	|NULL		|0
 FIELD		|status		|t_integer	|'0'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|value_type	|t_integer	|'0'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|trapper_hosts	|t_varchar(255)	|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|units		|t_varchar(255)	|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|multiplier	|t_integer	|'0'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|delta		|t_integer	|'0'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
-FIELD		|prevorgvalue	|t_varchar(255)	|	|NULL		|0
 FIELD		|snmpv3_securityname|t_varchar(64)|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|snmpv3_securitylevel|t_integer	|'0'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|snmpv3_authpassphrase|t_varchar(64)|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|snmpv3_privpassphrase|t_varchar(64)|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|formula	|t_varchar(255)	|'1'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
-FIELD		|error		|t_varchar(128)	|''	|NOT NULL	|ZBX_SYNC
-FIELD		|lastlogsize	|t_integer	|'0'	|NOT NULL	|0
 FIELD		|logtimefmt	|t_varchar(64)	|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|templateid	|t_id		|	|NULL		|ZBX_SYNC		|2|items	|itemid
 FIELD		|valuemapid	|t_id		|	|NULL		|ZBX_SYNC		|3|valuemaps	|		|RESTRICT
@@ -794,8 +788,6 @@
 FIELD		|password	|t_varchar(64)	|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|publickey	|t_varchar(64)	|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|privatekey	|t_varchar(64)	|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
-FIELD		|mtime		|t_integer	|'0'	|NOT NULL	|0
-FIELD		|lastns		|t_nanosec	|	|NULL		|0
 FIELD		|flags		|t_integer	|'0'	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|filter		|t_varchar(255)	|''	|NOT NULL	|ZBX_SYNC,ZBX_PROXY
 FIELD		|interfaceid	|t_id		|	|NULL		|ZBX_SYNC,ZBX_PROXY	|4|interface	|		|RESTRICT
@@ -807,6 +799,17 @@
 INDEX		|4		|templateid
 INDEX		|5		|valuemapid
 
+TABLE|items_state|itemid|ZBX_SYNC
+FIELD		|itemid		|t_id		|	|NOT NULL	|0		|1|items	|itemid
+FIELD		|lastvalue	|t_varchar(255)	|	|NULL		|0
+FIELD		|lastclock	|t_time		|	|NULL		|0
+FIELD		|prevvalue	|t_varchar(255)	|	|NULL		|0
+FIELD		|prevorgvalue	|t_varchar(255)	|	|NULL		|0
+FIELD		|lastlogsize	|t_integer	|'0'	|NOT NULL	|0
+FIELD		|mtime		|t_integer	|'0'	|NOT NULL	|0
+FIELD		|lastns		|t_nanosec	|	|NULL		|0
+FIELD		|error		|t_varchar(128) |''	|NOT NULL	|ZBX_SYNC
+
 TABLE|item_discovery|itemdiscoveryid|ZBX_SYNC
 FIELD		|itemdiscoveryid|t_id		|	|NOT NULL	|0
 FIELD		|itemid		|t_id		|	|NOT NULL	|ZBX_SYNC		|1|items
Index: create/data/create_data_sql/data_sql_blacklist.txt
===================================================================
--- create/data/create_data_sql/data_sql_blacklist.txt	(revision 20279)
+++ create/data/create_data_sql/data_sql_blacklist.txt	(working copy)
@@ -5,6 +5,6 @@
 functions lastvalue
 hosts disable_until error available errors_from lastaccess inbytes outbytes ipmi_disable_until ipmi_available snmp_disable_until snmp_available maintenanceid maintenance_status maintenance_type maintenance_from ipmi_errors_from snmp_errors_from ipmi_error snmp_error
 httptest lastcheck nextcheck curstate curstep lastfailedstep error time
-items lastvalue lastclock prevvalue error lastlogsize prevorgvalue mtime
+items_state lastvalue lastclock prevvalue error lastlogsize prevorgvalue mtime
 triggers lastchange value error
 users attempt_failed attempt_ip attempt_clock
