Quantcast
Channel: MySQL Forums - InnoDB
Viewing all articles
Browse latest Browse all 1957

Preventing others from accessing locked row in InnoDB (3 replies)

$
0
0
I need to prevent other sessions from accessing rows that I've locked, even those not contained in a transaction.

For example, I know I can lock a record by doing something like the following -

START TRANSACTION;
BEGIN;
SELECT * FROM databasename.tablename WHERE tableid = 1 FOR UPDATE;
(at this moment in time nobody else can read the record if they are also in a transaction trying at least to get a read lock)
COMMIT;

I know also that if another session tries to obtain any kind of lock on that same row before I commit that they will have to wait until I've committed, like the following -

BEGIN;
SELECT * FROM databasename.tablename WHERE tableid = 1 LOCK IN SHARE MODE;
COMMIT;

I also know that I can force all transactions to effectively append a "LOCK IN SHARE MODE" to any regular SELECT statement with something like --

SET SESSION (or GLOBAL) TRANSACTION ISOLATION LEVEL SERIALIZABLE;

The problem is that I need to prevent ALL reads on locked records, whether the session trying to access the record is in a transaction or not.

How can I do that?

Viewing all articles
Browse latest Browse all 1957

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>