Back to Research Page

Soonyoung Lee




Performance Analysis on Customer_service Database Using EXPLAIN Statement
 



1. Simple Queries Without Join

        explain select * from customer_service.customer;
*** Help information returned. 13 rows.
*** Total elapsed time was 1 second.

Explanation
---------------------------------------------------------------------------
  1) First, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for
     customer_service.customer.
  2) Next, we lock customer_service.customer for read.
  3) We do an all-AMPs RETRIEVE step from customer_service.customer by
     way of an all-rows scan with no residual conditions into Spool 1,
     which is built locally on the AMPs.  The size of Spool 1 is
     estimated with low confidence to be 80 rows.  The estimated time
     for this step is 0.15 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 0.15 seconds.
 

  *** Help information returned. 7 rows.
 *** Total elapsed time was 1 second.

Explanation
------------------------------------------------------------------------
  1) First, we do a single-AMP RETRIEVE step from
     customer_service.employee by way of the unique primary index
     "customer_service.employee.employee_number = 1010" with no
     residual conditions.  The estimated time for this step is 0.03
     seconds.
  -> The row is sent directly back to the user as the result of
     statement 1.  The total estimated time is 0.03 seconds.
 


2. Queries With Join

      explain select c.customer_name
        from customer_service.customer c,customer_service.location l
        where c.customer_number = l.customer_number;



3. Queries with Set operator

explain (select employee_number
from customer_service.employee
where department_number = 401)
UNION
(select employee_number
from customer_service.employee
where department_number = 403 );
 *** Help information returned. 16 rows.
 *** Total elapsed time was 1 second.

Explanation
---------------------------------------------------------------------------
  1) First, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for
     customer_service.employee.
  2) Next, we lock customer_service.employee for read.
  3) We do an all-AMPs RETRIEVE step from customer_service.employee by
     way of an all-rows scan with a condition of (
     "(customer_service.employee.department_number = 401) OR
     (customer_service.employee.department_number = 403)") 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 no confidence to be 16 rows.  The estimated time
     for this step is 0.15 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 0.15 seconds.



4. Queries with Aggregation
 

*** Help information returned. 34 rows.
*** Total elapsed time was 1 second.

Explanation
---------------------------------------------------------------------------
  1) First, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for customer_service.e.
  2) Next, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for customer_service.d.
  3) We lock customer_service.e for read, and we lock
     customer_service.d for read.
  4) We do an all-AMPs RETRIEVE step from customer_service.e by way of
     an all-rows scan with no residual conditions into Spool 3, which
     is redistributed by hash code to all AMPs.  Then we do a SORT to
     order Spool 3 by row hash.  The size of Spool 3 is estimated with
     low confidence to be 80 rows.  The estimated time for this step is
  0.03 seconds.
  5) We do an all-AMPs JOIN step from Spool 3 (Last Use) by way of a
     RowHash match scan, which is joined to customer_service.d.  Spool
     3 and customer_service.d are joined using a merge join, with a
     join condition of ("customer_service.d.department_number =
     Spool_3.department_number").  The result goes into Spool 2, which
     is built locally on the AMPs.  The size of Spool 2 is estimated
     with index join confidence to be 80 rows.  The estimated time for
     this step is 0.20 seconds.
  6) We do a SUM step to aggregate from Spool 2 (Last Use) by way of an
     all-rows scan, and the grouping identifier in field 2.  Aggregate
     Intermediate Results are computed globally, then placed in Spool 4.
     The size of Spool 4 is estimated to be 80 rows.
  7) We do an all-AMPs RETRIEVE step from Spool 4 (Last Use) by way of
    an all-rows scan with a condition of ("((Spool_4.Field_3 )/
     (Spool_4.Field_4 ))> 3.00000000000000E 004") into Spool 1, which
     is built locally on the AMPs.  The size of Spool 1 is estimated
     with low confidence to be 80 rows.  The estimated time for this
     step is 0.17 seconds.
  8) 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.
 



5. Queries with Nested Subqueries - Comparison with Flattened query

*** Help information returned. 28 rows.
*** Total elapsed time was 1 second.

Explanation
---------------------------------------------------------------------------
  1) First, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for
     customer_service.employee.
  2) Next, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for
     customer_service.customer.
  3) We lock customer_service.employee for read, and we lock
     customer_service.customer for read.
  4) We do an all-AMPs RETRIEVE step from customer_service.customer by
     way of an all-rows scan with no residual conditions into Spool 2,
     which is redistributed by hash code to all AMPs.  Then we do a
     SORT to order Spool 2 by row hash.  The size of Spool 2 is
     estimated with low confidence to be 80 rows.  The estimated time
     for this step is 0.03 seconds.
  5) We do an all-AMPs JOIN step from Spool 2 (Last Use) by way of an
     all-rows scan, which is joined to customer_service.employee with a
     condition of ("customer_service.employee.hire_date > DATE
     '1977-03-01'").  Spool 2 and customer_service.employee are joined
     using an inclusion merge join, with a join condition of (
     "Spool_2.sales_employee_number =
     customer_service.employee.employee_number").  The result goes into
     Spool 1, which is built locally on the AMPs.  The size of Spool 1
     is estimated with no confidence to be 27 rows.  The estimated time
     for this step is 0.20 seconds.
  6) 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 0.23 seconds.
 

*** Help information returned. 26 rows.
*** Total elapsed time was 1 second.

Explanation

---------------------------------------------------------------------------

1) First, we lock a distinct customer_service."pseudo table" for read
   on a RowHash to prevent global deadlock for customer_service.e.
2) Next, we lock a distinct customer_service."pseudo table" for read
   on a RowHash to prevent global deadlock for customer_service.c.
3) We lock customer_service.e for read, and we lock
   customer_service.c for read.
4) We do an all-AMPs RETRIEVE step from customer_service.c by way of
   an all-rows scan with no residual conditions into Spool 2, which
   is redistributed by hash code to all AMPs.Then we do a SORT to
   order Spool 2 by row hash.The size of Spool 2 is estimated with
   low confidence to be 80 rows.The estimated time for this step is
  0.03 seconds.
5) We do an all-AMPs JOIN step from customer_service.e by way of a
   RowHash match scan with a condition of (
   "customer_service.e.hire_date > DATE '1977-03-01'"), which is
   joined to Spool 2 (Last Use).customer_service.e and Spool 2 are
   joined using a merge join, with a join condition of (
   "Spool_2.sales_employee_number =
   customer_service.e.employee_number").The result goes into Spool
   1, which is built locally on the AMPs.The size of Spool 1 is
   estimated with no confidence to be 27 rows.The estimated time
   for this step is 0.18 seconds.
6) 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 0.21 seconds.



6. Example of Parallel Processing - the Heart of Teradata Performance

explain select e.last_name, e.first_name, ep.area_code, ep.phone
from customer_service.employee e, customer_service.employee_phone ep,
customer_service.customer c
where e. employee_number = c. sales_employee_number
and e.employee_number = ep.employee_number
and c.customer_name = 'First American Bank';
*** Help information returned. 38 rows.
*** Total elapsed time was 1 second.

Explanation
---------------------------------------------------------------------------
  1) First, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for customer_service.ep.
  2) Next, we lock a distinct customer_service."pseudo table" for read
     on a RowHash to prevent global deadlock for customer_service.e.
  3) We lock a distinct customer_service."pseudo table" for read on a
     RowHash to prevent global deadlock for customer_service.c.
  4) We lock customer_service.ep for read, we lock customer_service.e
     for read, and we lock customer_service.c for read.
  5) We execute the following steps in parallel.
       1) We do an all-AMPs RETRIEVE step from customer_service.c by
          way of an all-rows scan with a condition of (
          "customer_service.c.customer_name = 'First American Bank'")
          into Spool 2, which is redistributed by hash code to all AMPs.
          Then we do a SORT to order Spool 2 by row hash.  The size of
          Spool 2 is estimated with no confidence to be 8 rows.  The
          estimated time for this step is 0.03 seconds.
       2) We do an all-AMPs JOIN step from customer_service.ep by way
          of a RowHash match scan with no residual conditions, which is
          joined to customer_service.e.  customer_service.ep and
          customer_service.e are joined using a merge join, with a join
          condition of ("customer_service.e.employee_number =
          customer_service.ep.employee_number").  The result goes into
          Spool 3, which is redistributed by hash code to all AMPs.
          Then we do a SORT to order Spool 3 by row hash.  The size of
          Spool 3 is estimated with low confidence to be 80 rows.  The
          estimated time for this step is 0.06 seconds.
  6) We do an all-AMPs JOIN step from Spool 2 (Last Use) by way of a
     RowHash match scan, which is joined to Spool 3 (Last Use).  Spool
     2 and Spool 3 are joined using a merge join, with a join condition
     of ("(Spool_3.employee_number = Spool_2.sales_employee_number) AND
     (Spool_2.sales_employee_number = Spool_3.employee_number)").  The
     result goes into Spool 1, which is built locally on the AMPs.  The
     size of Spool 1 is estimated with no confidence to be 8 to 640
     rows.  The estimated time for this step is 0.20 seconds.
  7) 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 0.26 seconds.
 



7. Summary and Conclusion