Uploaded image for project: 'ZABBIX FEATURE REQUESTS'
  1. ZABBIX FEATURE REQUESTS
  2. ZBXNEXT-6131

Performance improvement of "delete sql" of problem table in PostgreSQL.

XMLWordPrintable

    • Icon: Change Request Change Request
    • Resolution: Unresolved
    • Icon: Trivial Trivial
    • None
    • 4.0.23
    • Server (S)

      rc = DBexecute("delete from problem where r_clock<>0 and r_clock<%d", now - SEC_PER_DAY);
      

      "r_clock<>0" does not use the index.
      I think it's better to use "between".

      I changed "delete" to "select" and got "sql explain".

      zabbix=> explain analyze select * from problem where r_clock<>0 and r_clock < 1595774180;
                                                  QUERY PLAN                                             
      ---------------------------------------------------------------------------------------------------
       Seq Scan on problem  (cost=0.00..29.63 rows=5 width=78) (actual time=0.871..0.871 rows=0 loops=1)
         Filter: ((r_clock <> 0) AND (r_clock < 1595774180))
         Rows Removed by Filter: 1042
       Total runtime: 0.947 ms
      (4 行)
      
      zabbix=> explain analyze select * from problem where r_clock between 1 and (1595774180 - 1);
                                                           QUERY PLAN                                                     
      --------------------------------------------------------------------------------------------------------------------
       Index Scan using problem_2 on problem  (cost=0.00..9.17 rows=5 width=78) (actual time=0.031..0.031 rows=0 loops=1)
         Index Cond: ((r_clock >= 1) AND (r_clock <= 1595774179))
       Total runtime: 0.058 ms
      (3 行)
      

      actual time 0.871 -> 0.031

            wiper Andris Zeila
            kazuo.ito Kazuo Ito
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: