03-04-2015, 11:57
Buenas, hay algo que no me cerro en la resolucion. Pusieron que la respuesta al 3) a. es:
" Devolvia a=c=n y b=n+1 siendo n la cantidad de registros."
Pero la transaccion 2 al ser serializable, establece con el select un exclusive lock sobre toda la tabla, que no se va a liberar hasta que commitee. La transaccion 1 por mas que sea read uncommited, intenta establecer un shared lock por el select solo durante la duracion del select (despues lo libera), pero el shared lock es incompatible con el exclusive lock. Por ende deberian devolver las 3 variables el mismo resultado...
Leyendo en la pagina de microsoft sobre locks, dice que el select con read uncommited si establece un shared lock y lo libera:
"Shared (S) locks allow concurrent transactions to read (SELECT) a resource under pessimistic concurrency control. For more information, see Types of Concurrency Control. No other transactions can modify the data while shared (S) locks exist on the resource. Shared (S) locks on a resource are released as soon as the read operation completes, unless the transaction isolation level is set to repeatable read or higher, or a locking hint is used to retain the shared (S) locks for the duration of the transaction."
Pero tambien dice sobre los exclusive locks que bloquean todos los select salvo en read uncommited:
"Exclusive (X) locks prevent access to a resource by concurrent transactions. With an exclusive (X) lock, no other transactions can modify data; read operations can take place only with the use of the NOLOCK hint or read uncommitted isolation level."
Entonces, alguien que la tenga clara con base de datos me puede responder cual de las 2 opciones es?
Porque si se intentara establecer un shared lock por el select, no se podria, puesto que ya tiene un exclusive lock por el insert. Entonces, como joraca pueden hacerse selects si ya hay un exclusive lock?
" Devolvia a=c=n y b=n+1 siendo n la cantidad de registros."
Pero la transaccion 2 al ser serializable, establece con el select un exclusive lock sobre toda la tabla, que no se va a liberar hasta que commitee. La transaccion 1 por mas que sea read uncommited, intenta establecer un shared lock por el select solo durante la duracion del select (despues lo libera), pero el shared lock es incompatible con el exclusive lock. Por ende deberian devolver las 3 variables el mismo resultado...
Leyendo en la pagina de microsoft sobre locks, dice que el select con read uncommited si establece un shared lock y lo libera:
"Shared (S) locks allow concurrent transactions to read (SELECT) a resource under pessimistic concurrency control. For more information, see Types of Concurrency Control. No other transactions can modify the data while shared (S) locks exist on the resource. Shared (S) locks on a resource are released as soon as the read operation completes, unless the transaction isolation level is set to repeatable read or higher, or a locking hint is used to retain the shared (S) locks for the duration of the transaction."
Pero tambien dice sobre los exclusive locks que bloquean todos los select salvo en read uncommited:
"Exclusive (X) locks prevent access to a resource by concurrent transactions. With an exclusive (X) lock, no other transactions can modify data; read operations can take place only with the use of the NOLOCK hint or read uncommitted isolation level."
Entonces, alguien que la tenga clara con base de datos me puede responder cual de las 2 opciones es?
Porque si se intentara establecer un shared lock por el select, no se podria, puesto que ya tiene un exclusive lock por el insert. Entonces, como joraca pueden hacerse selects si ya hay un exclusive lock?