Query Processing and Optimization
Query Processing and Optimization
Query Processing and Optimization
&
OPTIMIZATION
Query processing
Query processing refers to the range of activities
involved in extracting data from a database.
The activities include
translation of queries in high-level database
languages into expressions that can be used at
the physical level of the file system
a variety of query-optimizing transformations ,
and
actual evaluation of queries.
Cont..
• The steps involved in processing a query appear
in Figure below . The basic steps are
Steps in query processing
Cont..
Before query processing can begin, the system
must translate the query into a usable form.
A language such as SQL is suitable for human use,
but is ill-suited to be the system’s internal
representation of a query.
A more useful internal representation
is one based on the extended relational algebra.
Thus, the first action the system must take in query
processing is to translate a given query into its internal
form.
Cont..
This translation process is similar to the work
performed by the parser of a compiler.
In generating the internal form of the query, the
parser checks the syntax of the user’s query, verifies
that the relation names appearing in the query are
names of the relations in the database, and so on.
The system constructs a parse-tree representation
of the query, which it then translates into a
relational-algebra expression.
Cont..
If the query was expressed in terms of a view, the
translation phase also replaces all uses of the view
by the relational-algebra expression that define
the view
Given a query, there are generally a variety of
methods for computing the answer.
For example, we have seen that, in SQL, a query
could be expressed in several different ways.
Each SQL query can itself be translated into a
relational-algebra expression in one of several
ways.
Cont..
Furthermore, the relational-algebra representation of a query specifies only partially
how to evaluate a query; there are usually several ways to evaluate relational-algebra
expressions.
As an illustration, consider the query
Cont..
Further, we can execute each relational-algebra
operation by one of several different algorithms.
For example, to implement the preceding selection, we
can search every tuple in account to find tuples with
balance less than 2500. If a B+-tree index is available on
the attribute balance, we can use the index instead to
locate the tuples.
To specify fully how to evaluate a query, we need not
only to provide the relational algebra expression, but
also to annotate it with instructions specifying how to
evaluate
Cont..