rails / solid_queue

Database-backed Active Job backend
MIT License
1.95k stars 130 forks source link

Sequential Scans / Missing indexes? #380

Open pglombardo opened 1 month ago

pglombardo commented 1 month ago

I'm happily using Solid queue in pwpush.com and the OSS project.

While investigating sequential scans I found this:

Screenshot 2024-10-10 at 13 21 07

Postgres backend. You can gather this info with the following DB query in rails dbconsole:

SELECT relname AS table_name,
       seq_scan,
       idx_scan
FROM pg_stat_user_tables
ORDER BY seq_scan DESC;

This project was originally at v0.3 and now v1.0 - all steps/migrations run. No production issues - everything runs smoothly. Only the minor issue above.

rosa commented 3 weeks ago

Hey @pglombardo, thanks for writing this up! The reason for this is that PostgreSQL doesn't implement a technique called "loose index scan", which is what MySQL uses to allow for DISTINCT type queries on indexed columns, and which are performed on solid_queue_ready_executions if you have either paused queues or prefixes in your workers configuration (such as queues: beta*). Usually the ready_executions table should be small so these shouldn't be very problematic, but depending on your load, the number of queues and configuration, it might be noticeable. I need to document this better in the README. How do you have your queues configured?

pglombardo commented 3 weeks ago

This is a great explanation and much appreciated. Solid Queue is running smoothly for me. I just noticed this while investigating other issues. We can close this issue then. Thanks!