|
Replies:
15
-
Pages:
2
[
1
2
| Next
]
-
Last Post:
Jun 2, 2008 1:20 AM
Last Post By: Jonathan Lewis
|
|
|
Posts:
26
Registered:
01/17/06
|
|
|
|
a lot of INSERTs with incremented sequence causes performance degradation
Posted:
May 31, 2008 12:38 PM
|
|
|
|
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
|
|
|
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
|
|
|
|
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?
|
|
|
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
|
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
Posts:
2,343
Registered:
05/06/98
|
|
|
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
|
|
|
|
An index does not necessarily need to be unique to be used for PK enforcement.
-Mark
|
|
|
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
|
|
|
|
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.
|
|
|
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
|
|
|
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/
|
|
|
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
|
|
|
|
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
|
|
|
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
|
|
|
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.
|
|
|
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
|
|
|
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 . . . .
|
|
|
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
|
|
|
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/
|
|
|
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
|
|
|
..... 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
|
|
|
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
|
|
|
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>
|
|
|
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
|
|
|
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 : 2500
- 1000000
pts
|
|
Expert : 1000
- 2499
pts
|
|
Pro : 500
- 999
pts
|
|
Journeyman : 200
- 499
pts
|
|
Newbie : 0
- 199
pts
|
|
Oracle ACE Director
|
|
Oracle ACE Member
|
|
Oracle Employee ACE
|
|
Helpful Answer
(5 pts)
|
|
Correct Answer
(10 pts)
|
|