Uploaded image for project: 'ZABBIX BUGS AND ISSUES'
  1. ZABBIX BUGS AND ISSUES
  2. ZBX-25495

"Escalation canceled" event create a lot of slow query with MySQL

XMLWordPrintable

    • Support backlog

      Steps to reproduce:

      1. Insert more then 1,000,000 rows into alerts table
      2. Create a test action with multiple steps (1, 2, 3-0)
      3. Trigger some trigger
      4. After first step, disable the host

      Result:
      A lot of similar log in zabbix_server.log:

        1263:20241101:125231.015 slow query: 148.064865 sec, "select userid,mediatypeid,subject,message,esc_step from alerts where alertid in (select max(alertid) from alerts where actionid=316 and mediatypeid is not null and alerttype=0 and acknowledgeid is null and eventid=265058805 group by userid,mediatypeid,esc_step) order by userid,mediatypeid,esc_step desc" 

      And slow log mysql (after analyzed):

      {
        "lock_time": "0.000133",
        "rows_sent": "1",
        "rows_examined": "4283201",
        "instance_id": "********",
        "db_name": "zabbix",
        "query_sql": "select userid,mediatypeid,subject,message,esc_step from alerts where alertid in (select max(alertid) from alerts where actionid=316 and mediatypeid is not null and alerttype=0 and acknowledgeid is null and eventid=265058819 group by userid,mediatypeid,esc_step) order by userid,mediatypeid,esc_step desc",
        "user_name": "zabbix",
        "user_host": "********",
        "query_time": "140.069441",
        "node_id": "********"
      } 

      Explain this query got: (note: after manually delete data to reduce query time)

      *************************** 1. row ***************************
                 id: 1
        select_type: PRIMARY
              table: alerts
         partitions: NULL
               type: ALL
      possible_keys: NULL
                key: NULL
            key_len: NULL
                ref: NULL
               rows: 1178229
           filtered: 100.00
              Extra: Using where; Using filesort
      *************************** 2. row ***************************
                 id: 2
        select_type: SUBQUERY
              table: alerts
         partitions: NULL
               type: ref
      possible_keys: alerts_1,alerts_3,alerts_5,c_alerts_6,alerts_8
                key: alerts_3
            key_len: 8
                ref: const
               rows: 8
           filtered: 1.25
              Extra: Using where; Using temporary

      Expected:
      Primary key 'alertid' should be used in query.
      Or housekeeper should clean old data to reduce query time.

      Additional information:
      It's probably introduced by ZBX-20249 to fixed escalation message issue with Oracle DB.

      But i don't know why mysql not use index to query data in PRIMARY query. If run two query independently (replace subquery use result). Everything work just fine.🤔

            zabbix.dev Zabbix Development Team
            BoringCat BoringCat
            Team B
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: