Calculates the undo generated by a statement

Source: Internet
Author: User

The following table is a nologging state in archive mode and is more efficient when using/*+ append*/inserts.
Why, because it will reduce the redo and undo generation.

How do I calculate how much undo an insert produces? Before and after the insert is performed by comparing the current session

The number of undo can be known.


Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.4.0

Sql> select Sid from V$mystat where Rownum=1;
Sid
----------
312

Sql> Select value "Undo Change vector Size"
2 from V$statname A, V$sesstat b
3 Where a.statistic# = b.statistic#
4 and A.name = ' undo change vector Size '
5 and B.sid = ' 312 ';

Undo Change Vector Size
-----------------------
0

Sql> CREATE table T as select RowNum from User_objects where rownum<100;

CREATE TABLE t as select RowNum from User_objects where rownum<100

Ora-00998:must name This expression with a column alias

---show rownum to specify individual names

Sql> CREATE table T as select RowNum a from user_objects where rownum<100;
Table created

Sql> Select value "Undo Change vector Size"
2 from V$statname A, V$sesstat b
3 Where a.statistic# = b.statistic#
4 and A.name = ' undo change vector Size '
5 and B.sid = ' 312 ';

Undo Change Vector Size
-----------------------
3128

sql> Insert/*+ append/into T select RowNum A from user_objects where rownum<100;

Inserted rows

Sql>
Sql> Select value "Undo Change vector Size"
2 from V$statname A, V$sesstat b
3 Where a.statistic# = b.statistic#
4 and A.name = ' undo change vector Size '
5 and B.sid = ' 312 ';

Undo Change Vector Size
-----------------------
3204

--Calculating the number of/*+ append * * * mode insert 100 records to produce undo

Sql> Select 3204-3128 d from dual;

D
----------
76

sql> INSERT INTO T-select RowNum a from user_objects where rownum<100;

Inserted rows

Sql> commit;

Commit Complete

Sql> Select value "Undo Change vector Size"
2 from V$statname A, V$sesstat b
3 Where a.statistic# = b.statistic#
4 and A.name = ' undo change vector Size '
5 and B.sid = ' 312 ';

Undo Change Vector Size
-----------------------
3920

--Calculates the number of undo produced by inserting 100 records in normal mode

Sql> Select 3920-3204 d from dual;

D
----------
716

The results show that the same record is inserted, and the undo produced by the/*+ append*/method is less.

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.