This morning I had a confusion regarding the update and insert statement. If we have a table with one million rows (The rows can be any). Table structure
Session 1:
if I run update
before this update in session 1 finishes run insert from second session
1,000,000
or
1,000,001
The correct answer is 1,000,000
15:09:37 SQL> select count(*) from myt;
COUNT(*)
----------------
1,000,001
Elapsed: 00:00:01.33
15:09:45 SQL>
SQL> desc myt
Name Null? Type
--------- -------- ------------------------
NO NUMBER(8)
NAME VARCHAR2(10CHAR)
this table is populated with
beginMeans each row have no = 1 and name = harvey.
for i in 1..1000000 loop
insert into myt values(1,'harvey');
end loop;
commit;
end;
/
14:49:07 SQL> select count(*) from myt;
COUNT(*)
----------------
1,000,000
Elapsed: 00:00:00.01
Session 1:
if I run update
14:49:56 SQL> update myt set no=2 where no=1;Session 2:
before this update in session 1 finishes run insert from second session
14:48:53 SQL> insert into myt values(1,'harvey');Question: what will be the number of rows updated by session 1.
1 row created.
Elapsed: 00:00:00.01
14:50:06 SQL> commit;
Commit complete.
Elapsed: 00:00:00.14
14:50:07 SQL>
1,000,000
or
1,000,001
The correct answer is 1,000,000
14:49:56 SQL> update myt set no=2 where no=1;and total number of rows in myt will be 1,000,001 because I have commited one row from session 2.
1000000 rows updated.
Elapsed: 00:00:17.7114:50:22 SQL>
15:09:37 SQL> select count(*) from myt;
COUNT(*)
----------------
1,000,001
Elapsed: 00:00:01.33
15:09:45 SQL>
1 comment:
One more wonderful consistency check would be to run a database backup/export while this export runs.
That will either substantiate that oracle backups/export are consistent. or will prove oracle has some serious bug(highly unlikely, with strict concurrency checks oracle employs.)
thanks Harv. for the effort
Post a Comment