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

MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' #32

Closed
ejunker opened this issue Feb 11, 2013 · 10 comments
Closed

MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery' #32

ejunker opened this issue Feb 11, 2013 · 10 comments

Comments

@ejunker
Copy link

ejunker commented Feb 11, 2013

I'm using MySQL 5.5.29 and after upgrading to 0.4.0 I get this error:

Mysql2::Error: This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery': UPDATE delayed_jobs SET locked_at = '2013-02-10 23:59:21', locked_by = 'delayed_job host:twitzip pid:4918' WHERE delayed_jobs.id IN (SELECT id FROM delayed_jobs WHERE ((run_at <= '2013-02-10 23:59:21' AND (locked_at IS NULL OR locked_at < '2013-02-10 23:54:21') OR locked_by = 'delayed_job host:twitzip pid:4918') AND failed_at IS NULL) ORDER BY priority ASC, run_at ASC LIMIT 1 FOR UPDATE) AND ((run_at <= '2013-02-10 23:59:21' AND (locked_at IS NULL OR locked_at < '2013-02-10 23:54:21') OR locked_by = 'delayed_job host:twitzip pid:4918') AND failed_at IS NULL)

@kellydunn
Copy link

👍 I am also getting this on MySQL 5.0.x and MySQL 5.1.x

After some brief investigation, it appears as though that there are a couple of MySQL support issues.

The first of which comes from using LIMIT inside of a subquery that gets constructed here.

The second issue is attempting to update a table of the same name it uses in a subquery here.

Both of which MySQL versions 5.1.x and 5.0.x do not support.
http://dev.mysql.com/doc/refman/5.0/en/subquery-restrictions.html

It would be nice if a core-contributor could chime in as to the purpose of these uses of limiting and updating. From an un-informed perspective, they seem uneeded as the code appears to only be concerned with a single eligible job at any point in time.

@sferik
Copy link
Collaborator

sferik commented Feb 11, 2013

Those change were introduced in #29.

@scosman, can you work on a patch that works on MySQL as well as Postgres? Otherwise, I will need to revert your changes.

I'm going to work on making the tests run on MySQL, Postgres, and SQLite. Currently, the only run on SQLite. 😦

@scosman
Copy link
Contributor

scosman commented Feb 11, 2013

Sorry about that. Revert for now and I'll submit an update later (I don't have a MySQL install handy to test changes on).

What compatibility are you targeting for the project? Postgres, MySQL and SQLite?

@kellydunn
Copy link

In the meantime, using an earlier version of the gem (0.3.3 @f276ec2cb2) seems to be working with my local test suite.

I eagerly await the new changeset 😸

@sferik
Copy link
Collaborator

sferik commented Feb 11, 2013

What compatibility are you targeting for the project? Postgres, MySQL and SQLite?

Yes, for now. Those are the three most popular open-source databases. This project can’t afford to test against commercial databases (Oracle, Microsoft SQL Server, etc.)

I should have tests running (and failing) under MySQL on Travis CI later today.

@scosman I can help you get MySQL up and running on your local machine. Even though you wrote this code, I don’t hold you responsible for the failure. I reviewed and merged your pull request and should have tested again MySQL. Let’s work on fixing this together. Let me know what time is convenient for you.

@scosman
Copy link
Contributor

scosman commented Feb 12, 2013

Unfortunately I don't have time to install MySQL this week, but this "should" fix the issue:
scosman@c9703fa

MySQL supports UPDATE...LIMIT which makes this easy using basic active_record updates. I couldn't test this fix as I don't have MySQL set up, but from reading AR/MySQL documentation it should work.

Anyone have a local environment to test on?

@sferik
Copy link
Collaborator

sferik commented Feb 12, 2013

If someone can verify this fix, I'll merge it upstream. To do so, make the following change to your Gemfile:

-gem 'delayed_job_active_record'
+gem 'delayed_job_active_record', :git => 'git@github.com:scosman/delayed_job_active_record.git'

The run the command

bundle install

@jensblond
Copy link

Fixed worked for me. Thanks.

@sferik
Copy link
Collaborator

sferik commented Feb 12, 2013

I got the tests running on Postgres, MySQL and SQLite on Travis. Then I applied @scosman's patch and everything passes. This ought to prevent database-specific failures in the future.

@scosman Thank you for pushing this patch so quickly!

@jensblond Thank you for testing this patch!

I'll release gem version 0.4.1 shortly.

@sferik sferik closed this as completed Feb 12, 2013
@duritong
Copy link

Unfortunately, these changes do not work on PostgreSQL 8.4 which is for example what ships with RHEL6.

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

No branches or pull requests

6 participants