Mysql row lock in select query for update

So, I am writing a simple caterpillar website for maintenance on home sites. It will go through each link, adding new links as they are found, marking the headings of headers and h1, etc.

Sometimes it duplicates the headers and H1 tags when there is only one source, when I check it manually.

The reason this happens is because the script traversal is done via cron and seems to overlap, so processing the same page is done twice.

The script will basically capture the page that has been expanded, and then if the HTTP response is 200, it marks it as a crawl and processes what it needs.

So, somewhere between SELECT and UPDATE, another script thread runs on the same line as SELECTED.

Is there a way to execute SELECT and UPDATE in the same query or block the row returned in SELECT so that it doesn't return again in another query in another thread until I finish with it?

We looked - http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html and the general SELECT FOR UPDATE stuff, but I'm still not sure.

Edit

I use something like this

START TRANSACTION;
SELECT .. FOR UPDATE;
UPDATE .... ;
COMMIT;

But he doesn’t like it. Fix using InnoDB on this table. I think that this may not be the way forward, because it just postpones processing of the string until it is committed, when I want it to be physically unable to select the string again.

, SELECT, UPDATE, , , , , , . SELECT UPDATE, SELECT, SELECT, .

+5
2

:). SELECT FOR UPDATE - , , . , .

Update:

, , :

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN TRANSACTION;
SELECT .. FOR UPDATE;
UPDATE .... ;
COMMIT TRANSACTION;
+3

( select for update), , . (, , ), , . Cron , . script, , "". cron , ""

+3

All Articles