Oracle foreign key missing index - a single index can boost performance
-
Upload
carlos-oliveira -
Category
Data & Analytics
-
view
115 -
download
1
description
Transcript of Oracle foreign key missing index - a single index can boost performance
![Page 1: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/1.jpg)
Foreign Key missing Index
Carlos Oliveira / July 14, 2014
![Page 2: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/2.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/3.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/4.jpg)
“Grammar, which knows how to control even kings.”
Molière
![Page 5: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/5.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/6.jpg)
Data Model 1
![Page 7: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/7.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/8.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/9.jpg)
Data Model 2
![Page 10: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/10.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/11.jpg)
11
Trace File Analysis
Without Index With Index
![Page 12: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/12.jpg)
12
Trace File Analysis – Without Index
![Page 13: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/13.jpg)
13
Trace File Analysis – With Index
![Page 14: Oracle foreign key missing index - a single index can boost performance](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/14.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/15.jpg)
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](https://reader033.fdocuments.us/reader033/viewer/2022061122/546f9ddcb4af9f210b8b45f7/html5/thumbnails/16.jpg)
Thank you
Carlos Oliveira / July 14, 2014