Thread: a lot of INSERTs with incremented sequence causes performance degradation


Permlink Replies: 15 - Pages: 2 [ 1 2 | Next ] - Last Post: Jun 2, 2008 1:20 AM Last Post By: Jonathan Lewis
user480682

Posts: 26
Registered: 01/17/06
a lot of INSERTs with incremented sequence causes performance degradation
Posted: May 31, 2008 12:38 PM
Click to report abuse...   Click to reply to this thread Reply
Hi,
can someone explain me how PK is verified (a lot of IOs)?
I've observed performance degradation when many inserts is done to 200mln rows table with huge PK index. Looks like whole index is read for pk veryfication , or maybe I'm wrong.
Database is 10.2.0.3 EE.
Regards
Grzegorz
damorgan

Posts: 9,443
Registered: 10/20/03
Re: a lot of INSERTs with incremented sequence causes performance degradati
Posted: May 31, 2008 2:02 PM   in response to: user480682 in response to: user480682
Click to report abuse...   Click to reply to this thread Reply
You should be wrong about the entire index being read.

Other than the amount of time the insert is taking what leads you to think this and how are you measuring "a lot of IOs?"

With 200M rows you, and in EE, you should have purchased the Partitioning Option: Did you? Is the table partitioned?
user480682

Posts: 26
Registered: 01/17/06
Re: a lot of INSERTs with incremented sequence causes performance degradati
Posted: May 31, 2008 2:10 PM   in response to: user480682 in response to: user480682
Click to report abuse...   Click to reply to this thread Reply
I've read that, whole pk index is read into db cache when a row is inserted.
You re right about partitioning, that's first think which I've proposed but Im curious about theory behind pk validating.\Regards
Grzegorz
Justin Cave

Posts: 24,284
Registered: 10/11/99
Re: a lot of INSERTs with incremented sequence causes performance degradati
Posted: May 31, 2008 3:14 PM   in response to: user480682 in response to: user480682
Click to report abuse...   Click to reply to this thread Reply
I've read that, whole pk index is read into db cache when a row is inserted.

Where did you read that? Either the source was incorrect or you misread the information. Oracle does have to read a few blocks from the index to validate the primary key-- enough to ensure that the primary key isn't duplicated, but it certainly doesn't have to read the whole thing into memory every time there is an insert.

Justin
burleson

Posts: 2,343
Registered: 05/06/98
Re: a lot of INSERTs with incremented sequence causes performance degradation
Posted: May 31, 2008 4:41 PM   in response to: user480682 in response to: user480682
Click to report abuse...   Click to reply to this thread Reply
Hi Grzegorz,

Oracle uses a unique index to enforce a PK, and the overhead is about the same whether or not the unique index is used to enforce a primary key.

You mentioned a sequence. Coud that be your issue? Are you using sequece caching?

http://www.dba-oracle.com/t_sequence_caching.htm

If this is a maintenance batch load, you might look at droppin indexes, loading, and rebuilding indexes/constraints after:

http://www.dba-oracle.com/t_optimize_insert_sql_performance.htm



Hope this helps. . .

Donald K. Burleson
Oracle Press author
Author of "Oracle Tuning: The Definitive Reference":
http://www.dba-oracle.com/bp/s_oracle_tuning_book.htm
mbobak

Posts: 625
Registered: 11/27/07
Re: a lot of INSERTs with incremented sequence causes performance degradation
Posted: May 31, 2008 5:17 PM   in response to: burleson in response to: burleson
Click to report abuse...   Click to reply to this thread Reply
An index does not necessarily need to be unique to be used for PK enforcement.

-Mark
damorgan

Posts: 9,443
Registered: 10/20/03
Re: a lot of INSERTs with incremented sequence causes performance degradati
Posted: May 31, 2008 8:34 PM   in response to: burleson in response to: burleson
Click to report abuse...   Click to reply to this thread Reply
Minor correction: Oracle uses unique indexes to enforce primary keys ONLY if they are non-deferrable. Deferrable primary keys always use a non-unique index.
Richard Foote

Posts: 485
Registered: 12/13/99
Re: a lot of INSERTs with incremented sequence causes performance degradati
Posted: May 31, 2008 11:35 PM   in response to: damorgan in response to: damorgan
Click to report abuse...   Click to reply to this thread Reply
Hi Daniel

Of course Don is incorrect but a minor correction to your minor correction. Oracle can use a unique index or a non-unique index to enforce a PK if they're non-deferrable. Deferrable and non-validated PKs use a non-unique index.

Cheers

Richard Foote
http://richardfoote.wordpress.com/
Nick Naughty

Posts: 404
Registered: 05/03/07
Re: a lot of INSERTs with incremented sequence causes performance degradation
Posted: May 31, 2008 11:45 PM   in response to: user480682 in response to: user480682
Click to report abuse...   Click to reply to this thread Reply
you need to check on the following grounds

Did you cache your sequences. I usually cache 20
did you have any row migration problem.
are you indexing on the key which is genernated by sequence (yes i guess)
then are you delete a lots of records before an insert ( if yes then)
then you may need to rebuild your indexes after each delete.

regards
Nick
burleson

Posts: 2,343
Registered: 05/06/98
Re: a lot of INSERTs with incremented sequence causes performance degradation
Posted: Jun 1, 2008 6:05 AM   in response to: mbobak in response to: mbobak
Click to report abuse...   Click to reply to this thread Reply
Hi Mark,

The OP asked: "Can someone explain me how PK is verified?"

You responded "An index does not necessarily need to be unique to be used for PK enforcement."

Um, I've never seen a case where a "alter table . . . add constraint . . . primary key" does not create a unique index.

ORA-02437: cannot validate <name> - primary key violated

Cause: attempted to validate a primary key with duplicate values or null values.

Action: remove the duplicates and null values before enabling a primary key.
burleson

Posts: 2,343
Registered: 05/06/98
Re: a lot of INSERTs with incremented sequence causes performance degradati
Posted: Jun 1, 2008 6:07 AM   in response to: damorgan in response to: damorgan
Click to report abuse...   Click to reply to this thread Reply
Minor correction: Oracle uses unique indexes to enforce primary keys ONLY if they are non-deferrable.

Fair enough. The OP sounded like a beginner, and I did not want to confuse them with TMI . . . .
Richard Foote

Posts: 485
Registered: 12/13/99
Re: a lot of INSERTs with incremented sequence causes performance degradation
Posted: Jun 1, 2008 6:42 AM   in response to: burleson in response to: burleson
Click to report abuse...   Click to reply to this thread Reply
Um, I've never seen a case where a "alter table . . .
add constraint . . . primary key" does not create a
unique index.

Hi Don

SQL> create table bowie as select rownum id, 'BOWIE' text from dual connect by level <=1000;

Table created.

SQL> create index bowie_idx on bowie(id);

Index created.

SQL> select index_name, uniqueness from user_indexes where index_name = 'BOWIE_IDX';

INDEX_NAME UNIQUENES


---------
BOWIE_IDX NONUNIQUE

SQL> alter table bowie add constraint bowie_pk primary key (id);

Table altered.

SQL> select ic.index_name, ic.column_name, i.uniqueness, c.constraint_name, c.co
nstraint_type from user_ind_columns ic, user_indexes i, user_constraints c where
ic.index_name = i.index_name and i.index_name = c.index_name and i.index_name =
'BOWIE_IDX';

INDEX_NAME COLUMN_NAME UNIQUENES CONSTRAINT_NAME C


------------
------------------------------ -
BOWIE_IDX ID NONUNIQUE BOWIE_PK P

You have now :)

Cheers

Richard Foote
http://richardfoote.wordpress.com/
hkchital

Posts: 4,974
Registered: 11/06/98
Re: a lot of INSERTs with incremented sequence causes performance degradation
Posted: Jun 1, 2008 7:54 AM   in response to: user480682 in response to: user480682
Click to report abuse...   Click to reply to this thread Reply
..... the rest of this thread seems to have gone on many different tracks
(about uniqueness and PK definitions, constraints and deferred constraints etc).

However, to answer your question , the issue would be the index, not the
sequence.

See http://www.jlcomp.demon.co.uk/faq/slowdown.html
damorgan

Posts: 9,443
Registered: 10/20/03
Re: a lot of INSERTs with incremented sequence causes performance degradati
Posted: Jun 1, 2008 6:38 PM   in response to: burleson in response to: burleson
Click to report abuse...   Click to reply to this thread Reply
Let me show you another one:
SQL> CREATE TABLE t (col NUMBER);

Table created.

SQL> ALTER TABLE t
2 ADD CONSTRAINT pk_t
3 PRIMARY KEY (col)
4 INITIALLY DEFERRED DEFERRABLE;

Table altered.

SQL> SELECT index_name, index_type, uniqueness
2 FROM user_indexes
3 WHERE table_name = 'T';

INDEX_NAME INDEX_TYPE UNIQUENES

---------------------------
PK_T NORMAL NONUNIQUE

SQL>
Jonathan Lewis

Posts: 1,911
Registered: 01/23/07
Re: a lot of INSERTs with incremented sequence causes performance degradation
Posted: Jun 2, 2008 1:10 AM   in response to: burleson in response to: burleson
Click to report abuse...   Click to reply to this thread Reply

You responded "An index does not necessarily need to
be unique to be used for PK enforcement."

Um, I've never seen a case where a "alter table . . .
add constraint . . . primary key" does not create a
unique index.

ORA-02437: cannot validate <name> - primary key
violated

Cause: attempted to validate a primary key with
duplicate values or null values.

Action: remove the duplicates and null values before
enabling a primary key.


Non-unique indexes supporting primary key (or just unique) constraints has been a possibility since at least 8i, and quoting an irrelevant error message doesn't change that fact.

Remember, there's an important difference between "I've never seen it", and "It doesn't happen".

Please try to bear that in mind the next time you get the urge to spout your silly comments about "empirical" DBAs.

Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums