Soonyoung Lee |
Performance Analysis on Customer_service Database Using EXPLAIN
Statement
1. Simple Queries Without Join
*** 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.
explain select
employee_number
from customer_service.employee
where department_number =
401
order by employee_number;
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") 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 8
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.
explain select * from customer_service.employee where employee_number = 1010;
*** 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.
Explanation
---------------------------------------------------------------------------
1) First, we
lock a distinct customer_service."pseudo table" for read
on a RowHash to prevent global deadlock
for customer_service.l.
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.l for read, and we lock
customer_service.c for read.
4) We do an all-AMPs
JOIN step from customer_service.l by way of a
RowHash match
scan with no residual conditions, which is joined to
customer_service.c.
customer_service.l and customer_service.c are
joined
using a merge join, with a join condition of (
"customer_service.c.customer_number =
customer_service.l.customer_number"). The result goes 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.18
seconds.
5) 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.18 seconds.
explain select
employee_number
from customer_service.department d, customer_service.employee
e
where d.department_number=e.department_number and
d.budget_amount > 500000;
*** Help information
returned. 25 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 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.d by
way of a
RowHash match scan with a condition of
(
"customer_service.d.budget_amount >
500000.00"), which is joined
to
Spool 2 (Last Use). customer_service.d and Spool 2 are
joined
using a merge join, with a join
condition of (
"customer_service.d.department_number =
Spool_2.department_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. 21 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.b.
2) Next, we lock
customer_service.b for read.
3) We do a two-AMP
RETRIEVE step from customer_service.a by way of
unique index # 4
"customer_service.a.department_name = 'research
and
development'" with no residual conditions into Spool 2, which
is duplicated on all AMPs. The
size of Spool 2 is estimated with
high
confidence to be 80 to 6,400 rows. The estimated time for
this step is 0.21
seconds.
4) 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.b. Spool 2 and
customer_service.b are joined using a product join, with a
join
condition of ("Spool_2.budget_amount
>
customer_service.b.budget_amount"). 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 80 rows. The estimated
time
for this step is 0.20
seconds.
5) 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.40 seconds.
Explanation
---------------------------------------------------------------------------
1) First, we
lock a distinct customer_service."pseudo table" for read
on a RowHash to prevent global deadlock
for customer_service.e1.
2) Next, we lock
customer_service.e1 for read.
3) We do a single-AMP
RETRIEVE step from customer_service.e2 by way
of the
unique primary index "customer_service.e2.employee_number
=
1010" with no residual conditions into
Spool 2, which is
duplicated on all AMPs. The size
of Spool 2 is estimated with
high
confidence to be 80 to 6,400 rows. The estimated time for
this step is 0.17
seconds.
4) 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.e1. Spool 2
and
customer_service.e1 are joined using a product join, with
a
join condition of
("customer_service.e1.salary_amount >
Spool_2.salary_amount"). The result goes into Spool 1, which
is
redistributed by hash code to all
AMPs. Then we do a SORT to
order
Spool 1 by the sort key in spool field1 eliminating
duplicate rows. The size of Spool 1 is estimated with no
confidence to be 80 rows. The
estimated time for this step is
0.20
seconds.
5) 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.36 seconds.
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 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.
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 80 to 6,400
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.
*** Help information returned.
30 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.lp.
2) Next, we lock a distinct
customer_service."pseudo table" for read
on a RowHash to prevent
global deadlock for customer_service.l.
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.lp for read, we
lock customer_service.l
for read, and we lock
customer_service.c for read.
5) We do an all-AMPs JOIN step from
customer_service.l by way of a
RowHash match scan with no
residual conditions, which is joined to
customer_service.c.
customer_service.l and customer_service.c are
joined using a merge join,
with a join condition of (
"customer_service.c.customer_number =
customer_service.l.customer_number"). The result goes 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.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 customer_service.lp. Spool
2 and customer_service.lp
are joined using a merge join, with a
join condition of
("Spool_2.location_number =
customer_service.lp.location_number"). The result goes into Spool
1, which is
built locally on the AMPs. The size of Spool 1 is
estimated with index join
confidence to be 6,400 rows. The
estimated time for this
step is 0.19 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.25 seconds.
explain (select employee_number
from customer_service.employee
where department_number = 401)
UNION
(select employee_number
from customer_service.employee
where department_number = 403 );
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") into Spool
1,
which is built locally on the
AMPs. The size of Spool 1 is
estimated with no confidence to be 8 rows. The estimated time
for
this step is 0.15
seconds.
4) 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 = 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 eliminating duplicate rows.
The size of Spool 1 is estimated with
no confidence to be 8 rows.
The
estimated time for this step is 0.15 seconds.
5) 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.31
seconds.
explain select
employee_number
from customer_service.employee
where
department_number = 401 or department_number = 403
order by
employee_number;
*** 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.
*** 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.department.
2) Next, we lock
customer_service.department for read.
3) We do a SUM step
to aggregate from customer_service.department by
way of
an all-rows scan with no residual conditions. Aggregate
Intermediate Results are computed
globally, then placed in Spool 2.
The
size of Spool 2 is estimated to be 1 row.
4) We do an all-AMPs
RETRIEVE step from Spool 2 (Last Use) by way of
an
all-rows scan into Spool 1, which is built locally on the AMPs.
The size of Spool 1 is estimated with
high confidence to be 1 row.
The
estimated time for this step is 0.17 seconds.
5) 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.
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 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.
explain select
d.department_name, avg(salary_amount) a
from customer_service.department
d, customer_service.employee e
where d.department_number =
e.department_number
group by
d.department_name
having a>30000;
*** 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
explain select
customer_name
from customer_service.customer
where sales_employee_number in
(select employee_number
from customer_service.employee
where hire_date > '77/03/01');
*** 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.
explain select
customer_name
from customer_service.customer c, customer_service.employee
e
where c.sales_employee_number =
e.employee_number
and hire_date > '77/03/01';
*** 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.