1 Query Processing
1 Query Processing
1 Query Processing
1.1 Introduction
In this lesson, we shall utilize some publicly available databases to illustrate the concepts of
query processing.
Database 1: Northwind Database (Download structure and data for GitHub for practical
exercises on writing SQL queries
Database 2: boatclub database. An .sql file will be provided via the class email which you can
import to your local mysql instance.
The purpose of the database is to facilitate members of a boat club to reserve boats for trips lasting
several hours. The two major entities (table) are:
How are these two entities related? In this problem we need to know what boats are reserved by
what sailors. Thus, "reservation" is obviously an important relationship in this simple problem.
Thus, the following Entity-Relationship Diagram suffices.
1
Class Exercise:
Database 3: University Database (A recap on steps involved in creating a database)
Requirements Analysis
Normalization
Conceptual Model
ERD
Database Schema
Objective: Create a database based on a brief set of requirements provided during the first lesson.
While making reference to the database schema generated after completing the above class
exercise, test your basic SQL proficiency by attempting to write SQL query commands to;
2
1.3 How is a query is Executed?
1. The scanner identifies the language components (tokens) in the text of the query,
while the parser checks the correctness of the query syntax.
2. The query is validated (by accessing the system catalog) to ascertain whether the
attribute names and relation names are valid.
3. An internal representation (tree or graph) of the query is created.
4. The query is parsed and then presented to a query optimizer.
5. The optimizer generates alternative plans and chooses the plan with the least
estimated cost.
3
Primary Index Multiple Records Retrieval : A search condition uses comparison condition <,
>, etc. on a key field with primary index is known as Primary index multiple records retrieval.
– Clustering Index: If the selection condition involves an equality comparison on a non-key
attribute with a clustering index, we can use that index to retrieve all the records satisfying the
condition.
Conjunctive Condition
If the selection condition of the SELECT operation is a conjunctive condition (a condition that
is made up of several simple conditions with the AND operator), then the DBMS can use the
following additional methods to perform the selection.
Conjunctive selection: If an attribute in any single simple condition in the conjunctive condition
has an access path that permits use of binary search or an index search, use that condition to
retrieve the records and then check if that record satisfies the remaining condition.
Conjunctive selection using composite index : If two or more attributes are involved in equality
conditions in the conjunctive condition and a composite index exists on the combined fields we
can use the index.