1 Notes on: Clusters Index and Cluster Creation in SQL Elisa Bertino CS Department and CERIAS Purdue University.

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

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
SQL Constraints and Triggers
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Introduction to Structured Query Language (SQL)
Introduction to Structured Query Language (SQL)
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
IS 4420 Database Fundamentals Chapter 6: Physical Database Design and Performance Leon Chen.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.
1 Introduction to Web Application Introduction to Data Base.
Database Systems More SQL Database Design -- More SQL1.
Introduction to Structured Query Language (SQL)
SELECT Advanced. Sorting data in a table The ORDER BY clause is used for sorting the data in either ascending or descending order depending on the condition.
SQL's Data Definition Language (DDL) – View, Sequence, Index.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
Chapter 6 Additional Database Objects
Copyright © Curt Hill Index Creation SQL.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
BACS--485 SQL 11 BACS 485 Structured Query Language.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
Chapter 6 Additional Database Objects Oracle 10g: SQL.
SQL (DDL & DML Commands)
Physical Database Design I, Ch. Eick 1 Physical Database Design I About 25% of Chapter 20 Simple queries:= no joins, no complex aggregate functions Focus.
1 ICS 184: Introduction to Data Management Lecture Note 11: Assertions, Triggers, and Index.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
IST 220 Introduction to Databases Course Wrap-up.
BACS 287 Structured Query Language 1. BACS 287 Visual Basic Table Access Visual Basic provides 2 mechanisms to access data in tables: – Record-at-a-time.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Chapter 8: SQL. Data Definition Modification of the Database Basic Query Structure Aggregate Functions.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
INTRODUCTION TO DATABASE MANAGEMENT SYSTEMS Dr. Adam Anthony Fall 2012.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Database Programming Sections 11 & 12 –Sequences, Indexes, and Synonymns.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Slide 8- 1 THE HAVING-CLAUSE Provides a condition on the summary information Sometimes we want to retrieve the values of these functions for only those.
Structured Query Language
Topics Related to Attribute Values Objectives of the Lecture : To consider sorting relations by attribute values. To consider Triggers and their use for.
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Session 1 Module 1: Introduction to Data Integrity
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
Chapter 4 Indexes. Indexes Logically represents subsets of data from one or more tables View Generates numeric valuesSequence Basic unit of storage; composed.
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
ORDER BY clause in SELECT command: Normally, the result of the query will not be in ordered format. If we want to get the result of the query in specific.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
11-1 © Prentice Hall, 2004 Chapter 11: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
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.
SQL: Interactive Queries (2) Prof. Weining Zhang Cs.utsa.edu.
SQL- Updates, Assertions and Views. Data Definition, Constraints, and Schema Changes Used to CREATE, DROP, and ALTER the descriptions of the tables (relations)
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL Query Getting to the data ……..
Chapter 3 Introduction to SQL(2)
Writing Basic SQL SELECT Statements
CS580 Advanced Database Topics
Tuning Queries from (E&N)
Database Management System
Structured Query Language (3)
Presentation transcript:

1 Notes on: Clusters Index and Cluster Creation in SQL Elisa Bertino CS Department and CERIAS Purdue University

2 Employees Emp#NameJobHiringDSalaryBonusDept# 7369RedEngineer17/12/ AndrewsTechnician20/02/ ? WhiteTechnician20/02/ PinkManager02/04/ ? MartinSecretary28/09/ ? BlackManager01/05/ ? NeriEngineer01/06/ ScottSecretary09/11/ ? DareEngineer17/11/ TurniTechnician08/09/ ? AdamsEngineer23/09/ GianniEngineer03/12/ ? FordSecretary03/12/ ? MillEngineer23/01/ GreenManager10/12/ ?10

3 Departments Dept#DeptNameOffice#DivisionManager 10 Building Construction 1100D Research2200D Road Maintenance5100D27698

4 Clustering Consider the following query: SELECT Emp#, Name, Office FROM Employees, Departments WHERE Employees.Dept# = Departments. Dept# An efficient storage strategy is based on clustering (that is, grouping) the tuples of the two tables that have the same value for the join attribute Clustering may make the execution of other queries inefficient – ex. SELECT * FROM Departments

5 Clustering 10 Building Construction 1100 D NeriEngineer01/06/ DareEngineer17/11/ MillEngineer23/01/ GreenManager10/12/ ?10 20Research2200D RedEngineer17/12/ PinkManager02/04/ ? ScottSecretary09/11/ ? Adams Engineer23/09/ FordSecretary03/12/ ?20 30 Road Maintenance 5100D Andrews Technician 20/02/ ? White Technician 20/02/ Black Manager01/05/ ? Gianni Engineer03/12/ ?30

6 Definition of clusters and indexes in SQL The most relevant commands are: the command for creating indexes, on one or more columns of a relation, and the command for creating clusters A cluster allows one to store on contiguous storage locations the tuples, of one or more relations, that have the same value for one or more columns, called cluster columns

7 Definition of clusters and indexes in SQL The command for creating an index in SQL has the following format: CREATE INDEX IndexName ON RelationName (ColumnNameList) | ClusterName [ASC | DESC]; where – IndexName is the name of the index being created – The ON clause specifies the object on which the index is allocated An index created on more than one column is called composite index

8 Definition of clusters and indexes in SQL The object on which an index is allocated can be: – a relation: one must specify the names of the columns on which the index is allocated – a cluster: the index is automatically allocated on all columns of the cluster An index can be allocated on several columns The ASC and DESC options specify if the values of the index key must be ordered according to an increasing or decreasing order – ASC is the default

9 Definition of clusters and indexes in SQL – Example The indexes are in general implemented as a B+-tree or some variations of it Suppose to allocate an index on the column salary of the Employees table CREATE INDEX idxsalary ON Employees (salary);

10 ASC and DESC Options If the index is created on a single column, the two options do not make any difference; the bidirectional-traversal capability of the index makes it possible to use the index for queries that specify sorting of results in either ascending or descending order of the sort column If the index is composite, the ASC and DESC keywords might be required For example, if we want to optimize a SELECT statement whose ORDER BY clause sorts on multiple columns and sorts each column in a different order, and we want to use an index for this query, we need to create a composite index that corresponds to the ORDER BY columns. Example: SELECT salary, dept# FROM Employees ORDER BY salary ASC, dept# DESC; To use an index for this query we need to create an index that corresponds to the order requirements of this query CREATE INDEX sal_d_idx ON Employees (salary ASC, dept# DESC);

11 Definition of clusters and indexes in SQL Definition of clustered indexes (DB2): CREATE INDEX IndexName ON RelationName (ColumnNameList) CLUSTER; Only a single clustered index can be allocated on a given table If the table is not empty when the clustered index is created, the data are not automatically re-grouped; it is necessary to use a special utility called REORG

12 Definition of clusters and indexes in SQL Command for the creation of a cluster: CREATE CLUSTER ClusterName (ColName_1 Domain_1,.., ColName_n Domain_n) [INDEX | HASH IS Expr | HASHKEYS n]; ClusterName is the name of the cluster being defined (ColName_1 Domain_1,..., ColName_n Domain_n), with n >= 1, is the specification of the cluster columns – such set of columns is called cluster key

13 Definition of clusters and indexes in SQL An auxiliary access structure is always associated with each cluster – Index: The tuples with the same value for the cluster key are clustered and indexed by a B+-tree (default) The index is convenient if there are frequent queries with range predicates on the cluster key or if the relations may frequently change size Index cluster – Hash: The tuples with the same hash value for the cluster key are clustered and indexed by a hash function The hash function is convenient if there are frequent queries with equality predicates on all cluster key columns and the relations are static Hash cluster

14 Definition of clusters and indexes in SQL – hash clusters The DBMS always provides an internal hash function used as default (very often based on the division method) the HASHKEYS option allows one to specify the number of values for the hash function If such value v is not a prime number, it is replaced by the system with the first prime number which is greater than v such value is used as input for the integer remainder function used by the system to generate the values of the hash function

15 Definition of clusters and indexes in SQL – Example Index cluster: CREATE CLUSTER Personnel(D# NUMBER); CREATE INDEX idxpersonnel ON CLUSTER Personnel; Hash cluster: CREATE CLUSTER Personnel (D# NUMBER) HASHKEYS 10; given that the HASHKEYS option is equal to 10, the number of values generated by the hash function is 11 (first prime number > 10)

16 Definition of clusters and indexes in SQL – hash clusters It is possible to modify the hash function to be used through the HASH IS option Such option can however only be used if: – The cluster key only includes columns containing integer values – The expression must return only positive values – + other conditions

17 Definition of clusters and indexes in SQL – index clusters If the cluster is of type index, before executing queries or modifications, an index on the cluster must be created through the CREATE INDEX command a cluster may include one or more relations – Single relation: the cluster is used to group the tuples of the relation that have the same value for the columns that are in the cluster key – Multiple relations: the cluster is used to group the tuples of all relations having the same value for the columns that are in the cluster key (the joins on the columns that are part of the cluster key are efficient) A relation must be inserted in the cluster when it is created

18 Definition of clusters and indexes in SQL - Example Suppose to insert in the Personnel cluster the Employees and Departments relations CREATE TABLE Employees (Emp# Decimal(4) NOT NULL, Dept# Decimal(2)) CLUSTER Personnel (Dept#); CREATE TABLE Departments (Dept# Decimal(4) NOT NULL) CLUSTER Personnel (Dept#);

19 Definition of clusters and indexes in SQL - Example The names of the columns on which the clustering of the relations is executed must not necessarily have the same names of the cluster columns; they must however have the same type