-
Change Request
-
Resolution: Unresolved
-
Trivial
-
None
-
4.0.23
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