Module-4
Module-4
By:
Dr. Nagendra Panini Challa
Assistant Professor, Senior Grade 2
SCOPE, VIT-AP University, India
AGENDA
SQL
Steps in Query Processing
Transforming SQL queries to Relational
Algebra
Heuristic Query Optimization
02/03/2025 5
Hard Parse and Soft Parse –
If there is a fresh query and its hash code does not exist in shared pool then that query has
to pass through from the additional steps known as hard parsing otherwise if hash code
exists then query does not passes through additional steps. It just passes directly to
execution engine. This is known as soft parsing.
Hard Parse includes following steps – Optimizer and Row source generation.
Step-2:
Optimizer: During optimization stage, database must perform a hard parse atleast for one
unique DML statement and perform optimization during this parse. This database never
optimizes DDL unless it includes a DML component such as subquery that require
optimization. It is a process in which multiple query execution plan for satisfying a query are
examined and most efficient query plan is satisfied for execution.
Database catalog stores the execution plans and then optimizer passes the lowest cost plan
for execution.
Row Source Generation –
The Row Source Generation is a software that receives a optimal execution plan from the
optimizer and produces an iterative execution plan that is usable by the rest of the
database. the iterative plan is the binary program that when executes by the sql engine
produces the result set.
Step-3:
Execution Engine: Finally runs the query and display the required result.
Database Management Systems (DBMS), SCOPE, VIT-AP University, India 02/03/2025 6
RELATIONAL ALGEBRA FOR
QUERY OPTIMIZATION
When a query is placed, it is at first scanned, parsed and validated. An internal
representation of the query is then created such as a query tree or a query graph.
Then alternative execution strategies are devised for retrieving results from the
database tables. The process of choosing the most appropriate execution strategy
for query processing is called query optimization.
Query Optimization Issues in DDBMS
In DDBMS, query optimization is a crucial task. The complexity is high since number
of alternative strategies may increase exponentially due to the following factors −
The presence of a number of fragments.
Distribution of the fragments or tables across various sites.
The speed of communication links.
Disparity in local processing capabilities.
For example, in the Student table, if we want to display the details of all
students who have opted for MCA course, we will use the following relational
algebra expression −
σ BRANCH_NAME="perryride"(LOAN)
Output – Selects tuples from Tutorials where the topic is ‘Database’ and ‘author’ is
guru99.
For example, to display names of all female students of the BCA course −
Relational algebra expression using sequence of projection and selection operations
Notation: R ∪ S
A union operation must hold the following condition:
R and S must have the attribute of the same number.
Duplicate tuples are eliminated automatically.
Notation: R ∩ S
Example: Using the above DEPOSITOR table and BORROW table
Input:
∏ CUSTOMER_NAME (BORROW) ∩ ∏ CUSTOMER_NAME (DEPOSITOR)
Notation: R - S
Example: Using the above DEPOSITOR table and BORROW table
Input:
∏ CUSTOMER_NAME (BORROW) - ∏ CUSTOMER_NAME (DEPOSITOR)
Notation: E X D
This query retrieves the names of employees (from any department in the
company) who earn a salary that is greater than the highest salary in
department 5. The query includes a nested subquery and hence would be
decomposed into two blocks. The inner block is:
FROM EMPLOYEE
Relation Schemas