+ All Categories
Home > Data & Analytics > Oracle foreign key missing index - a single index can boost performance

Oracle foreign key missing index - a single index can boost performance

Date post: 22-Nov-2014
Category:
Upload: carlos-oliveira
View: 116 times
Download: 1 times
Share this document with a friend
Description:
In Oracle databases, a foreign key does not require that the column being restricted should have an index. Update and Delete operations on referenced tables may have a heavy impact in performance, overloading the server. A single index can reduce the cost of these DML operations.
16
Foreign Key missing Index Carlos Oliveira / July 14, 2014
Transcript
Page 1: Oracle foreign key missing index - a single index can boost performance

Foreign Key missing Index

Carlos Oliveira / July 14, 2014

Page 2: Oracle foreign key missing index - a single index can boost performance

AgendaForeign Key missing index

Introduction Quote Overview of Integrity Constraints Data Model POC – Tables and Foreign Key POC Trace File Analysis Conclusion Training & Reference Apps Svcs Legacy – Oracle PL/SQL Entry Level Training & Reference Thank You

Page 3: Oracle foreign key missing index - a single index can boost performance

IntroductionI am a forward-looking Information Systems Architect with a solid Oracle DBA background comprising the daily infrastructure tasks of the DBA, several projects as a Data Modeler, and performance management projects.

I Started on the mainframe business, and soon had a deep dive in application development for Oracle databases. After acquiring an Oracle certification, I worked on performance enhancement for applications using Oracle databases, and later worked several years as an infrastructure DBA, later I worked on data modeling projects and more recently a performance management project, on both application and database layers.

Page 4: Oracle foreign key missing index - a single index can boost performance

“Grammar, which knows how to control even kings.”

Molière

Page 5: Oracle foreign key missing index - a single index can boost performance

You can define integrity constraints to enforce business rules on data in your tables. Business rules specify conditions and relationships that

must always be true, or must always be false. Because each company defines its own policies about

things like salaries, employee numbers, inventory tracking, and so on, you can specify a different set of rules for each database table.

When an integrity constraint applies to a table, all data in the table must conform to the corresponding rule. When you issue a SQL statement that modifies data in

the table, Oracle ensures that the new data satisfies the integrity constraint, without the need to do any checking within your program.

Overview of Integrity Constraints

Page 6: Oracle foreign key missing index - a single index can boost performance

Data Model 1

Page 7: Oracle foreign key missing index - a single index can boost performance

POC – Tables and Foreign KeyDROP TABLE test_fact;DROP TABLE test_extension1;

CREATE TABLE test_fact(fact0 NUMBER(10), fact1 NUMBER(10));ALTER TABLE test_fact ADD ( CONSTRAINT PKSN_test_fact PRIMARY KEY (fact0));

CREATE TABLE test_extension1(fact1 NUMBER(10), description1 VARCHAR2(2000));ALTER TABLE test_extension1 ADD ( CONSTRAINT PKSN_test_extension1 PRIMARY KEY (fact1));

ALTER TABLE test_fact ADD ( CONSTRAINT FK_test_fact_fact1 FOREIGN KEY (fact1) REFERENCES test_extension1 (fact1));

Page 8: Oracle foreign key missing index - a single index can boost performance

POC 1-- Table test_extension1 was populated with 20.000 rows.-- 10.000 in range 1..10.000 and another 10.000 in range 10.001..20.000-- Table test_fact was populated with 10.000 rows, the values in fact1 column range from 1..10.000

> DELETE FROM test_extension1 WHERE fact1 > 10000;

10000 rows deleted.

Elapsed: 00:00:20.25

> UPDATE test_extension1 2 SET fact1 = fact1 + 10000 3 WHERE fact1 > 10000 and fact1 <= 20000;

10000 rows updated.

Elapsed: 00:00:21.27

Page 9: Oracle foreign key missing index - a single index can boost performance

Data Model 2

Page 10: Oracle foreign key missing index - a single index can boost performance

POC 2-- Table test_extension1 was populated with 20.000 rows.-- 10.000 in range 1..10.000 and another 10.000 in range 10.001..20.000-- Table test_fact was populated with 10.000 rows, the values in fact1 column range from 1..10.000

> DELETE FROM test_extension1 WHERE fact1 > 10000;

10000 rows deleted.

Elapsed: 00:00:00.37

> UPDATE test_extension1 2 SET fact1 = fact1 + 10000 3 WHERE fact1 > 10000 and fact1 <= 20000;

10000 rows updated.

Elapsed: 00:00:00.36

Page 11: Oracle foreign key missing index - a single index can boost performance

11

Trace File Analysis

Without Index With Index

Page 12: Oracle foreign key missing index - a single index can boost performance

12

Trace File Analysis – Without Index

Page 13: Oracle foreign key missing index - a single index can boost performance

13

Trace File Analysis – With Index

Page 14: Oracle foreign key missing index - a single index can boost performance

14

Conclusion•There’s a huge gain on creating indexes on columns with

foreign keys.•If DML operations are frequent on these tables without

indexes, the impact on the database is huge because the tables being read so frequently are loaded by Oracle into memory to speed up the process, however this action will impact the CPU.

•If the tables are in production for a long time, the index creation may have a negative impact in other queries running on the table, specially in older Oracle versions running on Rule. An impact analysis study on the index creating must be performed beforehand.

Page 15: Oracle foreign key missing index - a single index can boost performance

Training

• Performance Tuning Guide and Reference http://docs.oracle.com/cd/B10500_01/server.920/a96533/toc.htm

• SQL Reference http://docs.oracle.com/cd/B10500_01/server.920/a96540/toc.htm

• PL/SQL User's Guide and Reference http://

docs.oracle.com/cd/B10500_01/appdev.920/a96624/toc.htm

Resources at Oracle website

Page 16: Oracle foreign key missing index - a single index can boost performance

Thank you

Carlos Oliveira / July 14, 2014


Recommended