Skip to content

Commit 366ea12

Browse files
Merge pull request mattiasgeniar#3 from i5513/master
Delete orphaned rows from events table
2 parents 6196f75 + 868ae8b commit 366ea12

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

checkscript.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,8 @@ SELECT COUNT(itemid) FROM history_text WHERE itemid NOT IN (SELECT itemid FROM i
7474

7575
SELECT COUNT(itemid) FROM trends WHERE itemid NOT IN (SELECT itemid FROM items);
7676
SELECT COUNT(itemid) FROM trends_uint WHERE itemid NOT IN (SELECT itemid FROM items);
77+
78+
-- Count the amount of records in the events table for triggers/items that no longer exist
79+
SELECT COUNT(eventid) FROM events WHERE source = 0 and object = 0 and objectid not in (select triggerid from triggers);
80+
SELECT COUNT(eventid) FROM events WHERE source = 3 and object = 0 and objectid not in (select triggerid from triggers);
81+
SELECT COUNT(eventid) FROM events WHERE source = 3 and object = 4 and objectid not in (select itemid from items);

cleanup.sql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ DELETE FROM screens_items WHERE screenid NOT IN (SELECT screenid FROM screens);
6565
DELETE FROM trigger_depends WHERE triggerid_down NOT IN (SELECT triggerid FROM triggers);
6666
DELETE FROM trigger_depends WHERE triggerid_up NOT IN (SELECT triggerid FROM triggers);
6767

68-
-- Count the amount of records in the history/trends table for items that no longer exist
68+
-- Delete records in the history/trends table where items that no longer exist
6969
DELETE FROM history WHERE itemid NOT IN (SELECT itemid FROM items);
7070
DELETE FROM history_uint WHERE itemid NOT IN (SELECT itemid FROM items);
7171
DELETE FROM history_log WHERE itemid NOT IN (SELECT itemid FROM items);
@@ -74,3 +74,8 @@ DELETE FROM history_text WHERE itemid NOT IN (SELECT itemid FROM items);
7474

7575
DELETE FROM trends WHERE itemid NOT IN (SELECT itemid FROM items);
7676
DELETE FROM trends_uint WHERE itemid NOT IN (SELECT itemid FROM items);
77+
78+
-- Delete records in the events table where triggers/items that no longer exist
79+
DELETE FROM events WHERE source = 0 and object = 0 and objectid not in (select triggerid from triggers);
80+
DELETE FROM events WHERE source = 3 and object = 0 and objectid not in (select triggerid from triggers);
81+
DELETE FROM events WHERE source = 3 and object = 4 and objectid not in (select itemid from items);

0 commit comments

Comments
 (0)