xsb Oracle Blog
ҽ
л
ҵBlog
¹鵵...
·...
Ķ...
ͳ...
վ...
Դ
===========================================================
update restart
===========================================================

Please note consistent read and current read when UPDATE statment start.


CREATE TABLE ud2_test(c1 NUMBER,c2 NUMBER,c3 NUMBER);
INSERT INTO ud2_test VALUES (1,1,1);
COMMIT;
CREATE OR REPLACE TRIGGER trg_ud2_test
BEFORE UPDATE ON ud2_test
FOR EACH ROW
BEGIN
dbms_output.put_line(:OLD.c1 || ',' || :OLD.c2 || ',' || :OLD.c3);
dbms_output.put_line(:NEW.c1 || ',' || :NEW.c2 || ',' || :NEW.c3);
END;

session1:

update ud2_test set c1=c1+1 where c2>0;
update ud2_test set c1=c1+1 where c2>0 ;
update ud2_test set c1=c1+1 where c2>0;

session2:

set serveroutput on
update ud2_test set c1=c1+10 where c2>0;
(session1 commit)
1,1,1
11,1,1
4,1,1
14,1,1
1 row updated
rollback;

etc:

update ud2_test set c3=c3+10 where c2>0;
(session1 commit)
4,1,1
4,1,11
5,1,1
5,1,11
1 row updated
rollback;

CREATE OR REPLACE TRIGGER trg_ud2_test
BEFORE UPDATE ON ud2_test
FOR EACH ROW
BEGIN
dbms_output.put_line( :OLD.c2 || ',' || :OLD.c3);
dbms_output.put_line( :NEW.c2 || ',' || :NEW.c3);
END;

update ud2_test set c3=c3+10 where c2>0;
(session1 commit)
4,1,1
4,1,11
1 row updated
rollback;

update ud2_test set c3=c3+10 where c1>0;
(session1 commit)
4,1,1
4,1,11
4,1,1
4,1,11
1 row updated
rollback;

xsb :2007.12.28 09:26 ::: ( Oracle ) ::Ķ:(141) :: (1) :: (0)
re: update restart [ظ]

OracleִupdateḶ́

1һ¶һ¶SCNΪupdate statementʼʱ䡣

2һ¶ҵļ¼(this row,when we started at update-statement SCN,was interested by us )

3ȻԵǰģʽcurrent modeȡݿµݣrow,when was interested in consistent readȻȽһ¶͵ǰݼ

4ûʹôֻȽwhereгֵ predicate in consistent read ;ҪȽtriggerõ:old СΪoracleһ¶ģʽõ:oldֵڵǰģʽ:oldпܻᱻıˡ

5) predicate 仯ʾܵӰ죬mini-rollback. ¡

ݸӣִupdate t set x = 5 where y = 6;

consistent ready=6ΪһУͨconsistent readҵü¼Ȼcurrent read ȡÿ飻Ƿָü¼Ѿsession"y=6" updateΪ "y=7"( Tx-another), ʾsessionִеupdate״̬һ£mini-rollback.

updateǰûܵTx-anotherӰ,󲿷ʶTx-anotherӰ졣ΥACIDC(onsistency):any changes to values in an instance are consistent with changes to other values in the same instance.

Mini-rollbackΣ

a) Mini-rollbackͷſϵһعblock cleanup and rollback;sessionsessionȻڵȴTX Lock.

b) Ȼл"SELECT FOR UPDATE" ģʽ Ϊ

SELECT FOR UPDATE̫ undo & redo - only the lock byte and the ITL are touched, not the other row (or indexes!) bytesᴥtriggersetc

Ϊпٴmini-rollback,select for updateܻԳɱϵͣٴmini-rollbackԡ

c)ִи¡

ˣbatch֮ǰ&mini-rollbackķselect for updateٸ¡

xsb ڣ2008.03.06 10:34



ڴ

ƺ

ַѡ

ҳѡ

authimage