Open salmonsteak1 opened 2 weeks ago
Hmm... interesting that you get that query. That code results in the following query for us:
DELETE FROM `solid_queue_jobs`
WHERE `solid_queue_jobs`.`finished_at` IS NOT NULL
AND `solid_queue_jobs`.`finished_at` < '2024-11-04 19:42:00.055618'
LIMIT 1000;
that simply uses the index index_solid_queue_jobs_on_finished_at
. Is this PostgreSQL?
@rosa yes, we're using PostgreSQL
Ahh, I realised why this is the case. PostgreSQL doesn't support LIMIT
on DELETE
queries 😅
I don't have a good alternative for this one at the moment, I'm afraid. I'm not sure from reading the output from your EXPLAIN QUERY
, but doesn this mean that the index on finished_at
is not being used for the inner query?
Seq Scan on solid_queue_jobs solid_queue_jobs_1 (cost=0.00..621188.83 rows=3996682 width=8) (actual time=0.004..0.201 rows=500 loops=1)
Filter: ((finished_at IS NOT NULL) AND (finished_at < now()))
Ahh, I realised why this is the case. PostgreSQL doesn't support
LIMIT
onDELETE
queries 😅 I don't have a good alternative for this one at the moment, I'm afraid. I'm not sure from reading the output from yourEXPLAIN QUERY
, but doesn this mean that the index onfinished_at
is not being used for the inner query?Seq Scan on solid_queue_jobs solid_queue_jobs_1 (cost=0.00..621188.83 rows=3996682 width=8) (actual time=0.004..0.201 rows=500 loops=1) Filter: ((finished_at IS NOT NULL) AND (finished_at < now()))
Yes, I believe that's the case - I can't see much of a hit to the performance of our database now, but its a shame that PostgresSQL does it this way
Hey there, I was analyzing some queries that is being done on my solid queue DB and I came across this:
I believe it relates to the
SolidQueue::Job.clear_finished_in_batches
code, where I have been using it like so in a recurring job:I also did an
EXPLAIN QUERY
on this query, and I seems like it's doing a sequential scan on all rows insolid_queue_jobs
which are older than the time specified infinished_before
:More information from query analysis on CloudSQL:
Is it possible to simplify this query, or would there be a timeline for when
clear_finished_jobs_after
will happen automatically?