473,320 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Index and foreign key

Hello,

Excuse me for my poor english.
I would kike know if create index on the foreign key it's necessary or if
Oracle, are optimized for using foreign key whithout index.

Best regards

Olivier
Jul 19 '05 #1
5 49690
depends on the version, depends on if you're concerned with performance or
concurrency

indexes on FKs can help join performance

until some release of 9i (don't remember which -- it might even be 10g, but
i know it's been discussed in these forums before) indexes on FKs were
necessary to minimize locks when a PK value was updated (but not necessarily
when other columns in the PK records where updated)

-- mcs
"Olivier Crèvecoeur" <Ol****************@ulg.ac.be> wrote in message
news:br*********@aix4.segi.ulg.ac.be...
| Hello,
|
| Excuse me for my poor english.
| I would kike know if create index on the foreign key it's necessary or if
| Oracle, are optimized for using foreign key whithout index.
|
| Best regards
|
| Olivier
|
|
Jul 19 '05 #2
VC
Hello Olivier,

Unindexed foreign keys can cause a dead-lock during concurrent primary keys
updates/deletes under any current Oracle version including 9i.
I'd be very much impressed if this problem were fixed in 10g...

So if you anticipate updates/deletes to the primary key, the foreign keys
have to be indexed.

Also, an unindexed foreign key is a performance issue if:
-- you have an 'on delete cascade';
-- you query from the parent table to the child table;

Rgds.

VC

"Olivier Crèvecoeur" <Ol****************@ulg.ac.be> wrote in message
news:br*********@aix4.segi.ulg.ac.be...
Hello,

Excuse me for my poor english.
I would kike know if create index on the foreign key it's necessary or if
Oracle, are optimized for using foreign key whithout index.

Best regards

Olivier

Jul 19 '05 #3
Hey VC!

If you check out the Oracle press materials on Oracle 9i, it explicitly
states that dead-locks are checked for and prevented. I guess they made
fools out of themselves by point out at something they forgot to
implement :-)

Either way, I hope MySQL, DB/2 and Oracle continue to remain in business
and keep pushing each other to their limits. MySQL because its included
for free with Linux, DB/2 because it maintains some degree of
compatibility with Oracle, and Oracle because we've been spending so
much time and effort on it.

Anyway, I'd better get going.

Cheers,
NicK
VC wrote:
Hello Olivier,

Unindexed foreign keys can cause a dead-lock during concurrent primary keys
updates/deletes under any current Oracle version including 9i.
I'd be very much impressed if this problem were fixed in 10g...

So if you anticipate updates/deletes to the primary key, the foreign keys
have to be indexed.

Also, an unindexed foreign key is a performance issue if:
-- you have an 'on delete cascade';
-- you query from the parent table to the child table;

Rgds.

VC

"Olivier Crèvecoeur" <Ol****************@ulg.ac.be> wrote in message
news:br*********@aix4.segi.ulg.ac.be...
Hello,

Excuse me for my poor english.
I would kike know if create index on the foreign key it's necessary or if
Oracle, are optimized for using foreign key whithout index.

Best regards

Olivier


Jul 19 '05 #4
VC
Hello Nick,
"NicK" <no****@emirates.net.ae> wrote in message
news:bs*********@news-dxb.emirates.net.ae...
Hey VC!

If you check out the Oracle press materials on Oracle 9i, it explicitly
states that dead-locks are checked for and prevented.


Well, Oracle misled you. I can post a sample scenario where Oracle 9i
dead-locks during primary key updates with unindexed foreign keys (if you
are interested).
VC
Jul 19 '05 #5
"Olivier Crèvecoeur" <Ol****************@ulg.ac.be> wrote in message news:<br*********@aix4.segi.ulg.ac.be>...
Hello,

Excuse me for my poor english.
I would kike know if create index on the foreign key it's necessary or if
Oracle, are optimized for using foreign key whithout index.

Best regards

Olivier


if your foreign key is not the lead column(s) in an index, all DML on
the parent table locks ALL records in the child table. Oracle claims
to have 'fixed' this in 9i. That is an over-statement. That have
improved it slightly.

Foreign keys should almost always be indexed. The question is, 'in
what do I not index foreign keys'. The only case I have run across is
when you are using historical data(and in those cases, I typically
dont use keys).

When you have an 'insert heavy' table, indexes can impede performance.
So on archive tables, you generally dont want many if any indexes. So
in this case you may not want to index your foreign key. I generally
prefer to totally denormalize in these cases.

Im sure there are some other cases when you would not want to index
foreign keys, however, think to index first, then 'maybe' in some
cases not to index.
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Brian S. Smith | last post by:
Hi gang, Please help. I've been through the Access help, searched the Web, and I can't seem to get a straight answer. As the Subject line suggests, I want to run a fairly simple VB/Access Sub...
2
by: Kostas | last post by:
I ve been told from Allen and others that when enforcing referential integrity Access creates a hidden index for the foreign key, therefore, I do not need to re-index it myself. However, I...
1
by: Waldo Nell | last post by:
Hi, I have a *huge* problem. I have a table with indexes on but the moment I have an OR in my SELECT query it seems to not use the appropriate index. oasis=> \d purchases Table...
7
by: teddysnips | last post by:
Table DDL below: The tables I have contain Timesheet information. Each row in the tblTSCollected table contains an entry for an employee into the timesheet system, specifically by scanning the...
2
by: bobby_b_ | last post by:
I have a table where fields 1 and 2 make up the primary key. Because of this, I have a unique composite index on fields 1 and 2 (as required by DB2). Now my question is: Fields 1 and 2 are also...
10
by: Laurence | last post by:
Hi there, How to differentiate between unique constraint and unique index? These are very similar but I cannot differentiate them? Could someone give me a hand? Thanks in advance
1
by: ken_knee | last post by:
I have a PARENT/CHILD I'm attempting to attach another CHILD to. When I try to add a FOREIGN KEY to the 3rd table referring to CHILD1 (AGTERNS), I get error SQL0573N A column list specified in the...
5
by: Olivier Crèvecoeur | last post by:
Hello, Excuse me for my poor english. I would kike know if create index on the foreign key it's necessary or if Oracle, are optimized for using foreign key whithout index. Best regards ...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.