Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

psql :optimized_sql strategy now updates a single row #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jpcuevaslavin
Copy link

@jpcuevaslavin jpcuevaslavin commented Aug 7, 2020

This prevents a -single- worker from taking all jobs.

The subquery should return a row using LIMIT 1. But, it sometimes return multiple rows. Why?
Because the planner may choose to generate a plan that executes a nested loop over the LIMITing subquery, causing more UPDATEs than LIMIT.

The solution is to materialize the selection into a CTE.

fixes collectiveidea/delayed_job#915
fixes #143

see detailed explanation

credits to @koshigoe and @fsateler.

The planner may choose to generate a plan that executes a nested loop over the LIMITing subquery, causing more UPDATEs than LIMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reserving jobs hits Postgresq Update..(subquery ..limit 1) bug Single worker picks up all jobs
1 participant