You are on page 1of 8

INICIAR SERVICIO MYSQL CONFIGURANDO my.

ini

Niveles de aislamiento vs Efectos de lectura
Nivel de aislamiento
READ UNCOMMITTED
READ COMMITTED
REPEATABLE READ
SERIALIZABLE

Lectura sucia
puede ocurrir
-

Lectura no repetibles
puede ocurrir
puede ocurrir
-

Lectura fantasma
puede ocurrir
puede ocurrir
puede ocurrir
-

"puede ocurrir" significa que el nivel de aislamiento sufre ese efecto, mientras que "-"
significa que no lo sufre.

Niveles de aislamiento vs Bloqueos Isolation level Bloqueo de escritura V V V Bloque de lectura V V Bloqueo de rango READ UNCOMMITTED READ COMMITTED REPEATABLE READ SERIALIZABLE V PRACTICA DE LABORATOTIO: NIVELES DE AISLAMIENTO mysql> select @@global.00 sec) mysql> select current_time(). c1.00 sec) mysql> update t set c2=c2+10 where c1=1.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select current_time().c2 from t. +----------------+ | current_time() | +----------------+ | 09:27:37 | +----------------+ 1 row in set (0. Query OK. Query OK. +-----------------------+ | @@global. 0 rows affected (0. +----------------+----+------+ | current_time() | c1 | c2 | +----------------+----+------+ | 09:28:43 | 1 | 161 | | 09:28:43 | 2 | 68 | | 09:28:43 | 3 | 83 | | 09:28:43 | 4 | 63 | +----------------+----+------+ 4 rows in set (0. 0 rows affected (0.03 sec) Se ha liberado el bloqueo compartido al registro c1=1 mysql> begin. Query OK.tx_isolation.00 sec) mysql> ********************* Se ha establecido el bloqueo compartido (BS) al registro c1=1 . +----------------+----+------+ | current_time() | c1 | c2 | +----------------+----+------+ | 09:25:22 | 1 | 151 | +----------------+----+------+ 1 row in set (0.00 sec) mysql> select current_time().tx_isolation | +-----------------------+ | READ-COMMITTED | T +-----------------------+ 1 1 row in set (0. 1 row affected (0.00 sec) mysql> commit. c1.c2 from t where c1=1 lock in share mode.

1 Query OK. c1. Query OK.19 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select current_time().87 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select current_time().03 | current_time() | sec) +----------------+ | 09:27:54 | NOTA: La T1 efectuo el BS pero practique haciendo que T2 haga primero el UPDATE.00 sec) mysql> update t set c2=c2+5 where c1=1. +----------------+----+------+ | current_time() | c1 | c2 | +----------------+----+------+ | 10:11:20 | 1 | 166 | +----------------+----+------+ 1 row in set (0.c2 from t.tx_isolation. +-----------------------+ | @@global.00 sec) mysql> select current_time(). +----------------+ Query OK. Query OK.c2 from t where c1=1 lock in share mode. 1 row affected (14. 1 row affected (48.tx_isolation | +-----------------------+ | READ-COMMITTED +-----------------------+ select | 1 row in set (0.00 sec) mysql> @@global. 0 rows affected (0. 0 rows affected (0.00 sec) . mysql> commit. LOCK IN SHARE MODE T 2 Query OK. T mysql> begin.mysql> begin.00 sec) BLOQUEO COMPARTIDO: +----------------+ 1 row in set (0.00 sec) mysql> update t set c2=c2+500 where c1=1. +----------------+----+------+ | current_time() | c1 | c2 | +----------------+----+------+ | 10:14:16 | 1 | 666 | | 10:14:16 | 2 | 68 | | 10:14:16 | 3 | 83 | | 10:14:16 | 4 | 63 | +----------------+----+------+ 4 rows in set (0. c1. 0 rows affected (0.

0 rows affected (0. +----+------+ | c1 | c2 | +----+------+ | 1 | 966 | . c1.01 sec) mysql> select * from t.BLOQUEO COMPARTIDO: mysql> commit. 1 row affected (38. Query OK.00 sec) mysql> update t set c2=c2+300 where c1=1.01 sec) mysql> select * from t.00 sec) mysql>*************************** SELECT LOCK IN SHARE MODE T mysql> begin. Query OK. 2 Query OK. +----+------+ | c1 | c2 | +----+------+ | 1 | 966 | | 2 | 68 | | 3 | 83 | | 4 | 63 | +----+------+ 4 rows in set (0. try restarting trans action mysql> select current_time(). 0 rows affected (0. +----------------+----+------+ | current_time() | c1 | c2 | +----------------+----+------+ | 10:12:18 | 1 | 166 | +----------------+----+------+ 1 row in set (0. Query OK. +----------------+----+------+ | current_time() | c1 | c2 | +----------------+----+------+ | 10:14:34 | 1 | 166 | | 10:14:34 | 2 | 68 | | 10:14:34 | 3 | 83 | | 10:14:34 | 4 | 63 | +----------------+----+------+ 4 rows in set (0. 0 rows affected (0.42 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> commit.00 sec) mysql> update t set c2=c2+300 where c1=1.c2 from t. ERROR 1213 (40001): Deadlock found when trying to get lock.c1.00 sec) mysql> select current_time().c2 from t where c1=1 lock in share mode.

1 row affected (0. try restarting transaction mysql> select * from t where c1=1.00 sec) [READ COMMITTED] mysql> update t set c2=c2-350 where c1=1. ERROR 1205 (HY000): Lock wait timeout exceeded.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> commit. +----+------+ | c1 | c2 | +----+------+ | 1 | 550 | +----+------+ 1 row in set (0. +----+------+ | c1 | c2 | +----+------+ | 1 | 900 | +----+------+ 1 row in set (0. Query OK.00 sec) T 1 mysql> begin.00 sec) mysql> commit.01 sec) mysql> mysql> update t set c2=c2-150 where c1=1.00 sec) BLOQUEO EXCLUSIVO (BX): SELECT … FOR UPDATE mysql> update t set c2=c2-150 where c1=1.| 2 | 68 | | 3 | 83 | | 4 | 63 | +----+------+ 4 rows in set (0. 0 rows affected (0. 0 rows affected (0.00 sec) mysql> select * from t where c1=1 for update. Query OK. Query OK. Query OK. 1 row affected (0. .00 sec) Rows matched: 1 Changed: 1 Warnings: 0 T 2 mysql> begin. 0 rows affected (0. Query OK.

0 rows affected (0.03 sec) mysql> NOTA: La T1 efectuo el BX pero practique haciendo que T2 haga tambien un BX despues de T1.Query OK. . 1) Dos transacciones T1 y T2 se encuentran con IL=READ COMMITTED. Cual es el valor de saldo para cada una. T1 ha rebajado el saldo de c1=11 en 150. A partir de esto T1 y T2 hacen select saldo from cuenta where c1=1 respectivamente dentro de su espacio. CONTESTE: La Base de Datos Banco con la tabla cuenta con nc=11 y saldo 500.

+-----------------------+ | @@global. c) No.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from t where c1=3.tx_isolation | +-----------------------+ | READ-COMMITTED | +-----------------------+ 1 row in set (0.00 sec) mysql> select @@global. EFECTOS DEL NIVEL DE TRANSACCION: SESSION mysql> select * from t. o sea T1.a) No es posible determinar hasta que no culminen sus transacciones. transacción.01 sec) aislamiento SESSION de COMMITTED a UNCOMMITED. Query OK. EL Bloqueo compartido (BS) asegura a la primera transacción que lo invocó (BS1).00 sec) mysql> set session transaction isolation level read committed. d) No se puede determinar. 0 rows affected (0. Query OK. +----+------+ | c1 | c2 | +----+------+ | 1 | 40 | | 2 | 68 | | 3 | 83 | | 4 | 63 | +----+------+ mysql> begin.00 sec) mysql> commit. 0 rows affected (0. a) No. pero hará efecto en la siguiente . 1 row affected (0. porque es un bloqueo compartido. 0 rows affected (0. +----+------+ | c1 | c2 | +----+------+ | 3 | 87 | +----+------+ 4 rows in set (0. Query OK. b) Si porque T1 invocó el BS primero.00 sec) mysql> update t set c2=c2 + 4 where c1=3.00 sec) Se cambia el nivel de mysql> select @@tx_isolation. +--------------------------+ | @@tx_isolation | +--------------------------+ | READ-COMMITTED | +--------------------------+ 1 row in set (0. realizar una modificación sobre el registro bloqueado. . b) 350 y 350 c) 500 y 350 d) 350 y 500 2) Sea T1 y T2 dos transacciones READ COMMITTED. aun cuando T2 haga la modificacion antes que T1. porque T2 tambien puede haberlo bloqueado con un BS2. Query OK.tx_isolation.

+----+------+ | c1 | c2 | +----+------+ | 3 | 88 | +----+------+ 4 rows in set (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from t where c1=3. . 1 row affected (0.00 sec) mysql> update t set c2=c2 + 1 where c1=3.mysql> begin.00 sec) mysql> select * from t where c1=3. 0 rows affected (0. +----+------+ | c1 | c2 | +----+------+ | 3 | 87 | +----+------+ 4 rows in set (0. Query OK. Query OK.00 sec) mysql> commit.