Home » RDBMS Server » Performance Tuning » Question regarding performance impact on disabling foreign key (ORACLE 10.2.0.3)
Question regarding performance impact on disabling foreign key [message #506865] Wed, 11 May 2011 08:48 Go to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
Kevin Meade wrote:
"Remember, indexes with the right leading columns are good enough for any constraint these days so your indexes no longer have to exactly match your constraints."
Source: http://www.orafaq.com/forum/mv/msg/170674/505512/136107#msg_505512

Want to know index on foreign key constraint but disabled foreign key constraint can have any impact on performance.

eg, What if foreign key fk_dept (dept_id) is disabled but index exists on the column dept_id.

Is there will be any difference if foreign key enabled and index exists vs.
index exists on the column but foreign key kept disabled.

Regards
Ved
Re: Question regarding performance impact on disabling foreign key [message #506867 is a reply to message #506865] Wed, 11 May 2011 08:52 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
Want to know index on foreign key constraint but disabled foreign key constraint can have any impact on performance.

Yes, negative.

Quote:
Is there will be any difference if foreign key enabled and index exists vs.

Optimizer can't rely on the foreign key to generate the plan.

Regards
Michel
Re: Question regarding performance impact on disabling foreign key [message #506874 is a reply to message #506867] Wed, 11 May 2011 09:12 Go to previous messageGo to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
Quote:

Yes, negative.

It would help a lot if you explain in a few words. Thanks for the reply!

Regards
Ved
Re: Question regarding performance impact on disabling foreign key [message #506876 is a reply to message #506874] Wed, 11 May 2011 09:30 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Say you do:
SELECT * FROM emp e
WHERE EXISTS (SELECT 1 from dept d WHERE d.dept_id = e.dept_id)


If you have a foreign key from emp to dept on dept_id then oracle can skip the exists sub-query entirely, since the fk ensures that a matching record in dept must exist. If you disable the fk then the sub-query must be run.
Re: Question regarding performance impact on disabling foreign key [message #507088 is a reply to message #506876] Thu, 12 May 2011 07:34 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
When you enable a foreign key, inserts and updates of the key column(s) have a performance impact; they have to go check the child exists. Similarly, deletes and updates of the primary key on the parent table have a performance impact as they must ensure no matching rows exist in the child table.
Also worth noting that you cannot use direct-path load on the child table, and there are some tricky restrictions on Parallel DML.

Ross Leishman
Re: Question regarding performance impact on disabling foreign key [message #507222 is a reply to message #506876] Fri, 13 May 2011 04:39 Go to previous messageGo to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
Thanks for your reply!
Do you mean to say, the subquery does not run when fk is enabled? and thus has improvement in performance?

Regards
Ved
Re: Question regarding performance impact on disabling foreign key [message #507223 is a reply to message #507222] Fri, 13 May 2011 05:02 Go to previous messageGo to next message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Quote:
the subquery does not run when fk is enabled?

Yes.

Quote:
and thus has improvement in performance?

Yes.

Regards
Michel
Re: Question regarding performance impact on disabling foreign key [message #507336 is a reply to message #507223] Fri, 13 May 2011 14:57 Go to previous messageGo to next message
Its_me_ved
Messages: 979
Registered: October 2009
Location: India
Senior Member
Thanks for the reply.

For the above sql, the plan is same with or without fk. So, Optimizer can't rely on the foreign key to generate the plan.


-----------------------------------------------------------------------
| Id  | Operation            | Name      | Rows  | Bytes | Cost (%CPU)|
-----------------------------------------------------------------------
|   0 | SELECT STATEMENT     |           | 20000 |  1015K|    18  (12)|
|   1 |  HASH JOIN RIGHT SEMI|           | 20000 |  1015K|    18  (12)|
|   2 |   INDEX FULL SCAN    | PK_DEPTID |     5 |    65 |     1   (0)|
|   3 |   TABLE ACCESS FULL  | EMP       | 20000 |   761K|    16   (7)|
-----------------------------------------------------------------------

But how can we verify that it is not going to execute the subquery when fk is enabled? I tried to observe the performance with or without fk with 20000 rows in emp table but did not find any performance difference with or without fk.A demonstrain would help.


Regards
Ved
Re: Question regarding performance impact on disabling foreign key [message #507338 is a reply to message #507336] Fri, 13 May 2011 15:11 Go to previous message
Michel Cadot
Messages: 68641
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
20000 is very small try 20000000.
You cannot see it on explain plan above all an old one.

Regards
Michel
Previous Topic: No row resource operation information in tkprof output
Next Topic: Multiple SELECT statement help
Goto Forum:
  


Current Time: Fri Apr 19 16:37:22 CDT 2024