database - Update taking a row lock -


i have following query in postgres.

create schema s; create table s.t1 (     "id1" bigint,     "id2" bigint,     "id3" boolean default false not null,     constraint "pk1" primary key (id1) )     with(oids=false);  insert s.t1 (id1, id2, id3) values (1, 22, true); insert s.t1 (id1, id2) values (2, 22); insert s.t1 (id1, id2) values (3, 33);  select exists (select 1 s.t1 id2 = 22  , id3 = true update); /* take lock on row. */  select id3 s.t1 id2 = 22  , id3 = true update; /* takes lock on row. */  drop schema s cascade;  

i understand second query takes lock (when run under transaction) on particular row. no other query able access row till transaction commits.

does first query takes lock on row when run under transaction?

thanks

select exists (select 1 s.t1 id2 = 22  , id3 = true update); /* take lock on row. */ 

yes. rows retrieved query locked. not matter in form , whether @ returned query.

if subquery locks rows outer query may reduce number of locked rows (if reduces number of retrieved rows). in case outer query reduces number of locked rows 1 row.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -