Open fdurand opened 5 years ago
ALTER TABLE radius_audit_log ADD INDEX tenant_id_id (tenant_id,id); SELECT ( ( max(id) - min(id) ) DIV ( select (select max(id) from radius_audit_log) - (select max(id) from radius_audit_log where id < (select max(id) from radius_audit_log ) ) ) ) AS count FROM radius_audit_log WHERE ( radius_audit_log.tenant_id = '1' );
When you go in radius audit log the following sql request is executed: SELECT COUNT(*) AS
count
FROMradius_audit_log
WHERE (radius_audit_log
.tenant_id
= '1' )We need to optimize this request like: SELECT max(id) - min(id) AS
count
FROMradius_audit_log
WHERE (radius_audit_log
.tenant_id
= '1' ) and divide by the step of the id.