Oracle 11g new NOT null field is faster than 10g-new feature

Source: Internet
Author: User

It is slow to add a NOT null field before 11g. It was soon after 11g. Let's do a test first and then explore the principles.

Sql> select * from V$version;

BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0-64bi
PL/SQL Release 10.2.0.1.0-production
CORE 10.2.0.1.0 Production
TNS for 64-bit windows:version 10.2.0.1.0-production
Nlsrtl Version 10.2.0.1.0-production

sql> drop table test purge;
Sql> CREATE TABLE Test as SELECT * from Dba_objects;
Sql> Select COUNT (*) from test;
COUNT (*)
----------
151203
Sql> Set Timing on
Sql> ALTER TABLE test add col1 char () DEFAULT ' LARGE COLUMN ' not null;
time used: 00:00:09.48

Sql> SELECT SUM (BYTES)/1024/1024 | | ' M ' from user_segments WHERE segment_name = ' TEST ';
SUM (BYTES)/1024/1024| | ' M
-----------------------------------------
200M

Under 11g:

Sql> select * from V$version;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0-64bit Production
PL/SQL Release 11.2.0.1.0-production
CORE 11.2.0.1.0 Production
TNS for Linux:version 11.2.0.1.0-production
Nlsrtl Version 11.2.0.1.0-production
sql> drop table test purge;
Sql> CREATE TABLE Test as SELECT * from Dba_objects;
sql> INSERT INTO Test select * from Dba_objects;
Sql> commit;
Sql> Select COUNT (*) from test;
COUNT (*)
----------
149012
Sql> Set Timing on
Sql> ALTER TABLE test add col1 char () DEFAULT ' LARGE COLUMN ' not null;

Time used: 00:00:00.07


sql> SELECT SUM (BYTES)/1024/1024 | | ' M ' from user_segments WHERE segment_name = ' TEST ';
SUM (BYTES)/1024/1024| | ' M
-----------------------------------------

18M


Explore principle: Dump block can find that there are very many lines of migration and row links under 10g.

And in the 11g is a value, in the official document that Oracle by recording the default value in the data dictionary, avoids the heavy update operation.

in theDump block to see:
Alter session Set Tracefile_identifier = ' gg_test ';
Select rowID,
Dbms_rowid.rowid_object (ROWID) object_id,
DBMS_ROWID.ROWID_RELATIVE_FNO (ROWID) file_id,
Dbms_rowid.rowid_block_number (ROWID) block_id,
Dbms_rowid.rowid_row_number (ROWID) num
From Test where rownum <5;
Alter system dump DATAFILE 5 block 1465683;

10g under:
Tl:9 FB:--h-----lb:0x2 cc:0
Nrid:0x0181e36b.1
tab 0, row 2, @0x1b3a
tl:1076 FB:--h-fl--lb:0x2 cc:14
Col 0: [3] 53 59 53
Col 1: [4] 4f 4e 24
Col 2: *null*
Col 3: [2] C1 1d
Col 4: [2] C1 1d
Col 5: [5] 4c 45
Col 6: [7] 1e 0e 33 19
Col 7: [7] 1e 0f 31 37
Col 8: [+] + 2d 2d (3a) 3a 32 34
Col 9: [5] 4c 49 44
Col: [1] 4e
Col: [1] 4e
Col: [1] 4e
col: [+]
4c 4f 4c 4d 4e 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20
tab 0, row 3, @0x1b31
Tl:9 FB:--h-----lb:0x2 cc:0
nrid:0x0181e36b.2--nrid Row Migration
tab 0, row 4, @0x1b28
Tl:9 FB:--h-----lb:0x2 cc:0
Nrid:0x0181e36b.3

11g under:
tab 0, row 0, @0x3f33
tl:77 FB:--h-fl--lb:0x0 cc:14
Col 0: [3] 53 59 53
Col 1: [5] 4f 4c 24
Col 2: *null*
Col 3: [2] C1 15
Col 4: [2] C1 03
Col 5: [5] 4c 45
Col 6: [7] 0c 1a 2f
Col 7: [7] 0c 26 33
Col 8: [+] 2d, 2d, 3a, 3a, 3a 34 36
Col 9: [5] 4c 49 44
Col: [1] 4e
Col: [1] 4e
Col: [1] 4e
col: [2] C1
tab 0, row 1, @0x3ee4
tl:79 FB:--h-fl--lb:0x0 cc:14
Col 0: [3] 53 59 53
Col 1: [7] 5f 55 53 45 52 31
Col 2: *null*
Col 3: [2] C1 2f
Col 4: [2] C1 2f
Col 5: [5] 4e 44 45 58
Col 6: [7] 0c 1a 2f
Col 7: [7] 0c 1a 2f
Col 8: [+] 2d, 2d, 3a, 3a, 3a 34 36
Col 9: [5] 4c 49 44
Col: [1] 4e
Col: [1] 4e
Col: [1] 4e
Col: [2] C1 05

Oracle 11g new NOT null field is faster than 10g-new feature

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.