Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Optimizer's inability to resolve variables for partitioning - forum topic by SANJI

$
0
0

DB VERSION 13.10.05.02

I'm attempting to understand how does the optimizer resolve (if at all) dynamic variables (subquery) for partition elimination.
Here is an example,

CREATE TABLE SSURI.CDC_BATCH(
SINGLEAMP SMALLINT,
BATCH_START DATE,
BATCH_END DATE);

INSERT INTO SSURI.CDC_BATCH VALUES (1, CURRENT_DATE - 10, CURRENT_DATE);

--collect stats ssuri.cdc_batch....

CREATE TABLE SSURI.CUSLDSFL_SI(
TRACKINGNUM INTEGER,
AUD_TIME TIMESTAMP)
PRIMARY INDEX (TRACKINGNUM)
PARTITION BY RANGE_N(CAST((AUD_TIME) AS DATE AT LOCAL) BETWEEN '2009-12-31' AND '2013-12-31' EACH INTERVAL '1' DAY);

SELECT TOP 10 PARTITION, CAST(AUD_TIME AS DATE), COUNT(*)
FROM SSURI.CUSLDSFL_SI
GROUP BY 1,2 ORDER BY 1

PARTITION AUD_TIME COUNT(*)
----------------------------------------
3 1/2/2010 596
4 1/3/2010 3072
5 1/4/2010 45956
6 1/5/2010 32130
7 1/6/2010 32571
8 1/7/2010 28969
9 1/8/2010 26795
10 1/9/2010 2275
11 1/10/2010 1734
12 1/11/2010 38274

SELECT * FROM SSURI.CUSLDSFL_SI
WHERE AUD_TIME BETWEEN CAST((CURRENT_DATE - 10) AS TIMESTAMP) AND CAST(CURRENT_DATE AS TIMESTAMP)

3) We do an all-AMPs RETRIEVE step from 12 partitions of
SSURI.CUSLDSFL_SI with a condition of (
"(SSURI.CUSLDSFL_SI.Aud_Time >= TIMESTAMP '2013-02-22
00:00:00.000000') AND (SSURI.CUSLDSFL_SI.Aud_Time <= TIMESTAMP
'2013-03-04 00:00:00.000000')") into Spool 1 (group_amps), which
is built locally on the AMPs. The size of Spool 1 is estimated
with high confidence to be 644,784 rows (620,926,992 bytes). The
estimated time for this step is 0.37 seconds.

SELECT * FROM SSURI.CUSLDSFL_SI
WHERE AUD_TIME >= (SELECT CAST(BATCH_START AS TIMESTAMP) FROM SSURI.CDC_BATCH)
AND AUD_TIME <= (SELECT CAST(BATCH_END AS TIMESTAMP) FROM SSURI.CDC_BATCH)

8) We do an all-AMPs RETRIEVE step from SSURI.CUSLDSFL_SI by way of
an all-rows scan with a condition of (
"(SSURI.CUSLDSFL_SI.Aud_Time <= :%SSQ18) AND
(SSURI.CUSLDSFL_SI.Aud_Time >= :%SSQ17)") into Spool 3
(group_amps), which is built locally on the AMPs. The size of
Spool 3 is estimated with no confidence to be 122,089,337 rows (
117,572,031,531 bytes). The estimated time for this step is 2
minutes and 54 seconds.

The subqueries (derived or otherwise) are now passed as variables and the optimizer seems to ignore partition elimination in this case.
The "no confidence" stems from this fact.

Any insight is deeply appreciated...

Thanks
Sanjeev

Forums: 

Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>