Google
 

Tuesday, April 1, 2008

Types of SQL Statements

Oracle optimizes the following types of SQL statements:


Simple statement

An INSERT, UPDATE, DELETE, or SELECT statement that involves only a single table.

Simple query

Another name for a SELECT statement.

Join

A query that selects data from more than one table. A join is characterized by multiple tables in the FROM clause. Oracle pairs the rows from these tables using the condition specified in the WHERE clause and returns the resulting rows. This condition is called the join condition and usually compares columns of all the joined tables.

Equijoin

A join condition containing an equality operator.

Non-equijoin

A join condition containing something other than an equality operator.

Outer join

A join condition using the outer join operator (+) with one or more columns of one of the tables. Oracle returns all rows that meet the join condition. Oracle also returns all rows from the table without the outer join operator for which there are no matching rows in the table with the outer join operator.

Cartesian product

A join with no join condition results in a Cartesian product, or a cross product. A Cartesian product is the set of all possible combinations of rows drawn one from each table. In other words, for a join of two tables, each row in one table is matched in turn with every row in the other. A Cartesian product for more than two tables is the result of pairing each row of one table with every row of the Cartesian product of the remaining tables.

All other kinds of joins are subsets of Cartesian products effectively created by deriving the Cartesian product and then excluding rows that fail the join condition.

Complex statement

An INSERT, UPDATE, DELETE, or SELECT statement that contains a subquery, which is a form of the SELECT statement within another statement that produces a set of values for further processing within the statement. The outer portion of the complex statement that contains a subquery is called the parent statement.

Compound query

A query that uses set operators (UNION, UNION ALL, INTERSECT, or MINUS) to combine two or more simple or complex statements. Each simple or complex statement in a compound query is called a component query.

Statement accessing views

Simple, join, complex, or compound statement that accesses one or more views as well as tables.

Distributed statement

A statement that accesses data on two or more distinct nodes of a distributed database. A remote statement accesses data on one remote node of a distributed database.

Optimizer Operations

For any SQL statement processed by Oracle, the optimizer does the following:


Evaluation of expressions and conditions

The optimizer first evaluates expressions and conditions containing constants as fully as possible.

Statement transformation

For complex statements involving, for example, correlated subqueries, the optimizer may transform the original statement into an equivalent join statement.

View merging

For SQL statements that access a view, the optimizer often merges the query in the statement with that in the view, and then optimizes the result.

Choice of optimizer approaches

The optimizer chooses either a cost-based or rule-based approach and determines the goal of optimization.

Choice of access paths

For each table accessed by the statement, the optimizer chooses one or more of the available access paths to obtain the table's data.

Choice of join orders

For a join statement that joins more than two tables, the optimizer chooses which pair of tables is joined first, and then which table is joined to the result, and so on.

Choice of join operations

For any join statement, the optimizer chooses an operation to use to perform the join.


No comments: