DBMS M3 Ktunotes - in 1
DBMS M3 Ktunotes - in 1
PREPARED BY SHARIKA T R,
SNGCE
The first SELECT query retrieves the projects that involve a ‘Smith’ as manager of
the department that controls the project, and the second retrieves the projects that
involve a ‘Smith’ as a worker on the project. Notice that if several employees have the
last name ‘Smith’, the project names involving any of them will be retrieved.
Applying the UNION operation to the two SELECT queries gives the desired result.
suppose that we want to see the effect of giving all employees who work on the
‘ProductX’ project a 10 percent raise; we can issue Query 13 to see what their
salaries would become. This example also shows how we can rename an attribute in
the query result using AS in the SELECT clause.
Student Table
The keyword ALL can be combined with each of >, >=, <, <=, and <>,
these operators. For example, the comparison condition (v > ALL V)
returns TRUE if the value v is greater than all the values in the set (or
multiset) V.
Here the nested query has a different result for each tuple
in the outer query.
A query written with nested SELECT... FROM... WHERE...
blocks and using the = or IN comparison operators can
alwaysbe expressed as a single block query.
Downloaded from Ktunotes.in
A Simple Retrieval Query in SQL
• A simple retrieval query in SQL can consist of up to four
clauses,
▫ but only the first two SELECT and FROM are
mandatory
▫ the clauses between square brackets [ ... ] being
optional:
SELECT COUNT(*)
FROM EMPLOYEE;
V1
V2
Algebra Operations
Algorithm:
• Using rule 1, break up any select operations with conjunctive conditions into a
cascade of select operations.
• Using rules 2, 4, 6, and 10 concerning the commutativity of select with other
operations, move each select operation as far down the query tree as is permitted
by the attributes involved in the select condition.
• Using rule 9 concerning associativity of binary operations, rearrange the leaf nodes
of the tree so that the leaf node relations with the most restrictive select operations
are executed first in the query tree representation.
• Using Rule 12, combine a Cartesian product operation with a subsequent select
operation in the tree into a join operation.
• Using rules 3, 4, 7, and 11 concerning the cascading of project and the commuting
of project with other operations, break down and move lists of projection attributes
down the tree as far as possible by creating new project operations as needed.
• Identify subtrees that represent groups of operations that can be executed by a
single algorithm.
Downloaded from Ktunotes.in
Summary of Heuristics for
Algebraic Optimization
• The main heuristic is to apply first the operations that reduce the
size of intermediate results.
• Perform select operations as early as possible to reduce the
number of tuples and perform project operations as early
as possible to reduce the number of attributes.
▫ This is done by moving select and project operations as far down
the
tree as possible.
• The select and join operations that are most restrictive should be
executed before other similar operations.
▫ This is done by reordering the leaf nodes of the tree
Downloaded from Ktunotes.in
Query Execution Plans
• An execution plan for a relational algebra query consists of
a combination of the relational algebra query tree and
information about the access methods to be used for each
relation as well as the methods to be used in computing the
relational operators stored in the tree.
• Materialized evaluation: the result of an operation is stored
as a temporary relation.
• Pipelined evaluation:
▫ as the result of an operator is produced, it is forwarded to
the next operator in sequence.
Downloaded from Ktunotes.in
END