Indexes- What?  Optional structures associated with tables  Provides a quick access path to table data  You can create indexes on one or more columns.

Slides:



Advertisements
Similar presentations
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Advertisements

9 Creating and Managing Tables. Objectives After completing this lesson, you should be able to do the following: Describe the main database objects Create.
Data Definition Language (DDL)
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Database Programming Sections 13. Marge Hohly  1. Which statements are True about the following sequence? The sequence was used to generate numbers.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
10 Copyright © 2004, Oracle. All rights reserved. Creating Other Schema Objects.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
Copyright س Oracle Corporation, All rights reserved. 13 Other Database Objects.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
Lecture 8 Index Organized Tables Clusters Index compression
Chapter 6 Additional Database Objects
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
13 Other Database Objects Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina, and Nathan.
Copyright © 2004, Oracle. All rights reserved. Lecture 3: Creating Other Schema Objects Lecture 3: Creating Other Schema Objects ORACLE.
12 Copyright © Oracle Corporation, All rights reserved. Other Database Objects.
11 Copyright © 2007, Oracle. All rights reserved. Creating Other Schema Objects.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
10 Copyright © 2009, Oracle. All rights reserved. Using DDL Statements to Create and Manage Tables.
10 Creating and Managing Tables Objectives At the end of this lesson, you will be able to: Describe the main database objects Create tables Describe.
10-1 Copyright  Oracle Corporation, All rights reserved. Database Objects ObjectDescription TableBasic unit of storage; composed of rows and columns.
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
Views In some cases, it is not desirable for all users to see the entire logical model (that is, all the actual relations stored in the database.) In some.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Copyright  Oracle Corporation, All rights reserved. 10 Creating and Managing Tables.
Session 2: SQL (A): Parts 1 and 2 Original materials supplied by the Oracle Academic Initiative (OAI). Edited for classroom use by Professor Laku Chidambaram.
11-1 Copyright  Oracle Corporation, All rights reserved. What Are Constraints? Constraints enforce rules at the table level. Constraints prevent.
Oracle 11g: SQL Chapter 4 Constraints.
Week 5 Lecture 2 Data Integrity Constraints. Learning Objectives  Learn the types and the uses of constraints  Examine the syntax and options for creating.
Database Lab Lecture 1. Database Languages Data definition language ( DDL ) Data definition language –defines data types and the relationships among them.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
9 Copyright © 2004, Oracle. All rights reserved. Using DDL Statements to Create and Manage Schema Objects.
8 Copyright © 2007, Oracle. All rights reserved. Managing Schema Objects.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
Indexes and Views Unit 7.
9 Copyright © Oracle Corporation, All rights reserved. Creating and Managing Tables.
Session 1 Module 1: Introduction to Data Integrity
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
Chapter 12 Additional Database Objects. Chapter Objectives  Define the purpose of a sequence and state how it can be used by an organization  Explain.
Altering Tables and Constraints Database Systems Objectives Add and modify columns. Add, enable, disable, or remove constraints. Drop a table. Remove.
Indexes … WHERE key = Table Index 22 Row pointer Key Indexes
Creating and Managing Tables 14. ObjectivesObjectives After completing this lesson, you should be able to do the following: After completing this lesson,
Database Programming Sections 12 – Sequences, Indexes, and Synonymns.
Chapter 12Introduction to Oracle9i: SQL1 Chapter 12 Additional Database Objects.
Copyright س Oracle Corporation, All rights reserved. 12 Creating Views.
1 Chapters 21, 22, 23, 37  Ch. 21: SQL*Loader  Ch. 22: Database Links, Oracle Net  Ch. 23: Materialized Views (aka Snapshots)  Ch. 37: Data Dictionary.
CSCI N311: Oracle Database Programming 5-1 Chapter 15: Changing Data: insert, update, delete Insert Rollback Commit Update Delete Insert Statement –Allows.
1 Indexes ► Sort data logically to improve the speed of searching and sorting operations. ► Provide rapid retrieval of specified rows from the table without.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Installation Oracle 11g Express 2 double click the "setup" button to install the Oracle.
 CONACT UC:  Magnific training   
SQL Statements SELECT INSERTUPDATEDELETECREATEALTERDROPRENAMETRUNCATECOMMITROLLBACKSAVEPOINTGRANTREVOKE Data Retrieval Language (DRL) Data Retrieval Language.
SQL Basics Review Reviewing what we’ve learned so far…….
2 Copyright © 2009, Oracle. All rights reserved. Managing Schema Objects.
Creating Indexes Database Systems Objectives Distinguish between the indexes that are created automatically and those that are created manually.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Oracle – SQL 10g.
Oracle SQL.
Choosing Access Path The basic methods.
Manipulating Data.
What Is a View? EMPNO ENAME JOB EMP Table EMPVU10 View
Chapter 4 Indexes.
CH 4 Indexes.
Chapter 2 Views.
Managing Objects with Data Dictionary Views
CH 4 Indexes.
Chapter 2 Views.
IST 318 Database Administration
Presentation transcript:

Indexes- What?  Optional structures associated with tables  Provides a quick access path to table data  You can create indexes on one or more columns of a table  Avoids the need for large-table, full-table scans and disk sorts

Indexes - Types  B-tree – default index, works well on large tables and columns with distinct values, updates relatively inexpensive.  Bitmap indexes – used on columns which contains many repeated values on a large table. create bitmap index city_ind on emp (city);  Function-based indexes – Built on expressions create index salcomm_ind on emp (sal+comm); For Queries with SAL+COMM in where SALCOMM_IND index will be used

Indexes – When to use and on what columns  Access less than 5% of the rows in the table.  Don't index tables that are frequently updated.  Tables that don't have duplicate values on the columns usually selected in WHERE clauses.  Columns frequently specified in WHERE clauses  Columns that have unique values  Columns that are commonly used to join tables

Indexes – How to use it?  Some indexes are created part of creating constraints eg: PrimaryKey and UniqueKey  Can be created using the graphical utilities of Oracle Enterprise Manager  Using CREATE INDEX command CREATE INDEX emp_hiredate_idx ON employees (hire_date); CREATE INDEX empdept_ind on emp (empno,deptno); - Composite ALTER INDEX emp_hiredate_id RENAME TO emp_hire_date_idx; DROP INDEX emp_hire_date_idx;

Indexes – How to view them?  DBA_INDEXES - indexes on all tables in the database  ALL_INDEXES - indexes on all tables accessible to the user  USER_INDEXES - restricted to indexes owned by the user  Columns of indexes on tables DBA_IND_COLUMNS,ALL_IND_COLUMNS, USER_IND_COLUMNS  Function-based indexes on tables. DBA_IND_EXPRESSIONS,ALL_IND_EXPRESSIONS,USER_IND_EXPRESSIONS

Indexes- Rebuilding  Rebuilding an index based on an existing data source removes intra-block fragmentation.  Compared to dropping the index and using the CREATE INDEX statement, re-creating an existing index offers better performance.  The following statement rebuilds the existing index emp_name: ALTER INDEX emp_name REBUILD;

Indexes - Clustering  Co-locate related tables for faster access and for less storage. create cluster emp_dept (deptno number(2)); create index on cluster emp_dept; create table dept (deptno number(2),name varchar2(20),loc varchar2(20)) cluster emp_dept (deptno); create table emp (empno number(5),name varchar2(20), sal number(10,2), deptno number(2)) cluster emp_dept (deptno)  Not good if frequent updates are expected

Indexes – refresher  Assuming index on S# created, will the index be used?  WHERE S# > YES  WHERE S# <> NO  WHERE S#= 100 – YES  Assume index on S_NMAE  WHERE S_NAME like 'S%‘ - YES  WHERE S_NAME like '%S‘- NO  WHERE S_NAME is NULL - NO:

Views – What?  SQL statement that is stored in memory for re- use  CREATE VIEW view_emp AS SELECT empid FROM emp; SELECT * FROM view_emp WHERE empid BETWEEN 500 AND 1000; Oracle will transform the query into this: SELECT * FROM (select empid from emp) WHERE empid BETWEEN 500 AND 1000;

Views - Benefits  Common set of SQL, less likely to require parsing  Security: hide tables that actually contain the data you are querying.  Restrict Rows/Columns that a given user has access to.  Logical data independence. - Same object name is interpreted differently by different users eg: Table S can be supplier table for user1 whereas it means restricted view s_view for user2 with user2.S as synonym for user1.s_view

Views - Commands  Basic Views representing entire table: CREATE OR REPLACE VIEW AS SELECT FROM ;  Restrictive Views: CREATE OR REPLACE VIEW AS SELECT FROM WHERE = ;  Multi table views – CREATE OR REPLACE VIEW explan_four AS SELECT DISTINCT s.srvr_id FROM servers s, serv_inst i WHERE s.srvr_id = i.srvr_id;

Views – Commands contd.  Drop view - DROP VIEW date_view;  Updating views - will update underlying base table. UPDATE upd_view SET person_id = person_id * 10;  Read only views - CREATE OR REPLACE VIEW person_ro_view AS SELECT first_name, last_name, ssn FROM personWITH READ ONLY;  Views with Check option - CREATE OR REPLACE VIEW checkoption_view AS SELECT person_id, first_name, last_name, dob, ssn FROM person WHERE person_id < 10 WITH CHECK OPTION;

Views – Data Dictionary  data dictionary views are divided into three groups: USER, ALL, and DBA.  USER : information about objects owned by the current SQL user  USER TABLES all tables with their name, no. of columns, storage and statistical information etc. (TABS)  USER_CATALOG tables, views, and synonyms (CAT)  USER_COL_COMMENTS comments on columns  USER_CONSTRAINTS constraint definitions for tables  USER_INDEXES_all information about indexes created for tables (IND)  USER_OBJECTS_all database objects owned by the user (OBJ)

Views – Data Dictionary contd.  USER_TAB_COLUMNS columns of the tables and views owned by the user (COLS)  USER_TAB_COMMENTS comments on tables and views  USER_TRIGGERS triggers defined by the user  USER_USERS information about the current user  USER_VIEWS views defined by the user

Views – Materialized  Database object contains results of a query.  Local copies of data located remotely  Create summary tables based on aggregations of a table's data.  Also know as snapshots.  A materialized view can query tables, views, and other materialized views. Collectively these are called master tables

Views – Materialized contd.  FAST refresh uses the materialized view logs to send the rows that have changed from master tables to the materialized view.  COMPLETE refresh re-creates the entire materialized view.  Refresh Method - FORCE Clause When you specify a FORCE clause, Oracle will perform a fast refresh if one is possible or a complete refresh otherwise. FORCE is the default.

Views – Materialized contd.  Primary Key Materialized Views CREATE MATERIALIZED VIEW mv_emp_pk REFRESH FAST START WITH SYSDATE REFRESH FAST START WITH SYSDATE NEXT SYSDATE + 1/48 WITH PRIMARY KEY AS SELECT * FROM  Rowid Materialized Views CREATE MATERIALIZED VIEW mv_emp_rowid REFRESH WITH ROWID AS SELECT * FROM AS SELECT * FROM  Subquery Materialized Views CREATE MATERIALIZED VIEW mv_empdept AS SELECT * FROM e WHERE EXISTS (SELECT * FROM d WHERE e.dept_no = d.dept_no)