Source
/* MySQL automatically creates index and might not remove it on some conditions */
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
int delete_problems_with_nonexistent_object(void)
{
zbx_db_result_t result;
zbx_vector_uint64_t eventids;
zbx_db_row_t row;
zbx_uint64_t eventid;
int sources[] = {EVENT_SOURCE_TRIGGERS, EVENT_SOURCE_INTERNAL};
int objects[] = {EVENT_OBJECT_ITEM, EVENT_OBJECT_LLDRULE}, i;
zbx_vector_uint64_create(&eventids);
for (i = 0; i < (int)ARRSIZE(sources); i++)
{
result = zbx_db_select(
"select p.eventid"
" from problem p"
" where p.source=%d and p.object=%d and not exists ("
"select null"
" from triggers t"
" where t.triggerid=p.objectid"
")",
sources[i], EVENT_OBJECT_TRIGGER);
while (NULL != (row = zbx_db_fetch(result)))
{
ZBX_STR2UINT64(eventid, row[0]);
zbx_vector_uint64_append(&eventids, eventid);
}
zbx_db_free_result(result);
}
for (i = 0; i < (int)ARRSIZE(objects); i++)
{
result = zbx_db_select(
"select p.eventid"
" from problem p"
" where p.source=%d and p.object=%d and not exists ("
"select null"