473,795 Members | 3,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 49735
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****@emirate s.net.ae> wrote in message
news:bs******** *@news-dxb.emirates.ne t.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.ul g.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
4329
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 Function/Module that creates relationships for my tables. The problem is that I need to provide for some tables that may have > 32 relationships (which is apparently the limit on Indexes that Access can support). How can I prevent Access from...
2
2484
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 noticed that if the foreign key has the same name as the name of the field to which it corresponds in the other table, then it appears as indexed in the indexes list. For example: Table PERSON. Field: PersonID
1
1458
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 "public.purchases" Column | Type | Modifiers
7
2215
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 barcode on their badge. A whole bunch of business logic periodically attempts to "pair" these into logically matched scans. For example, some employees will scan in and out of a single place of work. For these there will be a row written to...
2
5122
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 separate foreign keys to two other tables. I have read that it is always a good idea to create indexes on foreign keys. Should I create single indexes on each of these fields? Or is that not necessary since they are already part of a composite...
10
14704
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
3778
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 references clause of constraint "RCAGTRNZ" does not identify a unique constraint of the parent table "VCSTSTNT.AGTERNS". Since CHILD1 has multiple constraints, a unique index and a foreign key, is there a gotcha that I'm not aware of? Thanks...
5
417
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 Olivier
6
4322
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 Alvin Leader
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.