MySQL Forums
Forum List  »  Newbie

Re: Are queries queued?
Posted by: Rick James
Date: June 05, 2009 08:47PM

Indexes need to be added for what would be useful. This is not necessarily the "most commonly used" fields".

Your suggestion of
LOCK TABLES products WRITE
SELECT id FROM products WHERE status = 'available' LIMIT 3;
UPDATE products SET status = 'pending', timestamp = now()
WHERE id IN (the 3 rows in the previous query)
UNLOCK TABLES;
would need
INDEX (status) -- probably useless unless very few are 'available'
INDEX (id) -- certainly

There are multiple ways to get the list of 3 rows...
* Do it in your application layer (PHP?)
* CREATE TEMPORARY TABLE to put then in
* Combine the SELECT and UPDATE, something like this:
UPDATE products SET
         status = 'pending',
         timestamp = now(),
         user_id = ...
    WHERE status = 'available' LIMIT 3;
Note that I had to say who has them reserved. After that, you have to find what you grabbed:
INDEX(user_id) -- needed for this
SELECT id FROM products
    WHERE user_id = ...;
That should return the (up to) 3 ids, if you need them.

If the user can move onto another 3 items, the above does not lay the groundwork for that.

Options: ReplyQuote


Subject
Written By
Posted
May 15, 2009 05:32AM
May 15, 2009 01:27PM
May 15, 2009 02:50PM
May 16, 2009 07:19PM
May 16, 2009 07:26PM
May 18, 2009 03:38PM
May 18, 2009 03:35PM
May 18, 2009 11:16PM
June 03, 2009 02:37PM
June 03, 2009 07:40PM
June 05, 2009 01:35PM
Re: Are queries queued?
June 05, 2009 08:47PM
June 06, 2009 11:20AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.