Subject Re: [firebird-support] Locking and disk activity
Author Ann W. Harrison
benedicte_asselin wrote:
>
>
> i use statements like this to lock the rows I need:
> SELECT mycolumns FROM thetable WHERE thekey=? FOR LOCK
>
> do such locks involve WRITE disk activity (if I do not actually
> modify the raw)?

Yes, but only if the page is in contention, which in turn depends on
whether you're using SuperServer or Classic. The lock is a change to a
data page. If another connection wants to read or change that data page
while the lock is in place, then it needs to see the most recent
version. In Classic, the connection that made the change has to write
the page to disk so the other connection can read it. In SuperServer,
both connections share a cache, so the newest version is available to
both without a write.

> if I have several rows to lock at a time, may I win time by making
> a 'in (key1, key2...)' and prepare a new statement and execute it
> rather than executing several one-by-one statement?

No, that doesn't make any difference. Well, it makes difference in the
number of round-trips between your application and the database, but it
won't affect the number of writes.


Regards,

Ann