Anda di halaman 1dari 8

The EXPLAIN

After completing this module, you will be able to:

Describe the Explain Facility.


Define Explain terminology. Describe the EXPLAIN output of a CREATE TABLE statement. Match new EXPLAIN terms (with PPI) to a definition. Use EXPLAIN to determine the number of partitions used in various access plans.

May be used on any SQL statement, except EXPLAIN itself. Translates Optimizer output (the execution plan) into English.

Provides direct feedback on what the system intends to do.


It is a good way to learn about the system and SQL. Use it consistently to analyze joins, long-running and complex queries.

Time estimates are relative, not absolute.

Assumes the query will run stand-alone; doesnt take a loaded system into
account.

Version 2 time estimates cost formulas based on H/W configuration.

The timings and spool sizes shown are ESTIMATES ONLY.

Spool sizes are based on dynamic sampling or statistics. Use them as figures of merit for comparison purposes only.
Know what the Request is supposed to do before EXPLAINing it.

In this module, we will


1st 2nd 3rd View some text examples of EXPLAINs. Discuss EXPLAIN terminology that may appear within EXPLAIN output. Discuss new V2R5 terminology with PPI and view some examples.

The Visual Explain utility will be covered in the next module.

QUERY
EXPLAIN SELECT * FROM daily_sales WHERE item_id = 5010;

EXPLANATION
-----------------------------------------------------------------------------------------------------------------------1) First, we do a single-AMP RETRIEVE step from TFACT.daily_sales by way of the primary index "TFACT.daily_sales.item_id = 5010 with no residual conditions into Spool 1, which is built locally on that AMP. The size of Spool 1 is estimated with high confidence to be 731 rows. The estimated time for this step is 0.22 seconds. -> The contents of Spool 1 are sent back to the user as the result of statement 1. The total estimated time is 0.22 seconds.

Note: Statistics were collected on the Primary Index of this table.

QUERY
EXPLAIN SELECT * FROM daily_sales ORDER BY 1;

EXPLANATION ( Full Table Scan)


--------------------------------------------------------------------------------------------------------------------------1) First, we lock a distinct TFACT."pseudo table" for read on a RowHash to prevent global deadlock for TFACT.daily_sales. 2) Next, we lock TFACT.daily_sales for read. 3) We do an all-AMPs RETRIEVE step from TFACT.daily_sales by way of an all-rows scan with no residual conditions into Spool 1, which is built locally on the AMPs. Then we do a SORT to order Spool 1 by the sort key in spool field1. The size of Spool 1 is estimated with high confidence to be 25,585 rows. The estimated time for this step is 2.41 seconds. 4) Finally, we send out an END TRANSACTION step to all AMPs involved in processing the request. -> The contents of Spool 1 are sent back to the user as the result of statement 1. The total estimated time is 2.41 seconds.

Note:

Statistics were collected on the Primary Index of this table.

Most EXPLAIN text is easy to understand. The following additional definitions may help:

... (Last Use)


A spool file is no longer needed and will be released when this step completes.

... with no residual conditions


All applicable conditions have been applied to the rows.

... END TRANSACTION


Transaction locks are released, and changes are committed.

... eliminating duplicate rows ...


Duplicate rows only exist in spool files, not set tables. Doing a DISTINCT operation.

... by way of the sort key in spool field1


Field1 is created to allow a tag sort.

... we do an ABORT test


Caused by an ABORT or ROLLBACK statement.

... by way of a traversal of index #n extracting row ids only


A spool file is built containing the Row IDs found in a secondary index (index #n)

... we do a SMS (set manipulation step)


Combining rows using a UNION, MINUS, or INTERSECT operator.

... we do a BMSMS (bit map set manipulation step)


Doing a NUSI Bit Map operation.

... which is redistributed by hash code to all AMPs.


Redistributing data in preparation for a join.

... which is duplicated on all AMPs.


Duplicating data from the smaller table (in terms of SPOOL) in preparation for a join.

... (group_AMPs)
V2R5 feature in which a subset of AMPs will be used instead of all AMPs.

... ("NOT (table_name.column_name IS NULL)")


V2R5 feature in which optimizer realizes that column being joined to is NOT NULL or has referential integrity.

Anda mungkin juga menyukai