我被赋予此查询以运行但它返回了假脱机错误。我被告知要使用粗体where where语句并使用它来创建categoryG排除表,然后添加另一个新步骤以将该表与表的其余部分连接起来。我是Teradata的新手并且非常迷失。希望有人可以提供帮助。谢谢!
CREATE VOLATILE TABLE A
,NO FALLBACK
,NO BEFORE JOURNAL
,NO AFTER JOURNAL AS
(
SELECT 'TX' AS STATE
,ADD_MONTHS(li.column7 - EXTRACT(DAY FROM li.Column21) + 1, 1) - 1 AS column12
,ADD_MONTHS(li.Column22 - EXTRACT(DAY FROM li.Column22) + 1, 1) - 1 AS column13
,EXTRACT(YEAR FROM column13) * 12 + EXTRACT(MONTH FROM column13) - EXTRACT(YEAR FROM column12) * 12 - EXTRACT(MONTH FROM column12) AS offset
,column8
,CASE
WHEN clm.Column20 = '01strong text'
AND li.Column23 = '1'
THEN 'INP'
WHEN clm.Column20 = '01'
AND li.Column23 IN (
'2'
,'3'
)
THEN 'OUT'
WHEN clm.Column20 = '02'
AND CHARACTER_LENGTH(TRIM(Column24)) <> 5
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 1 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 2 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 3 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 4 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 5 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND Column24 BETWEEN '00000'
AND '99999'
THEN 'PRO'
WHEN clm.Column20 = '02'
THEN 'OME'
WHEN clm.Column20 = '03'
THEN 'PDP'
WHEN clm.Column20 = '04'
THEN 'DEN'
ELSE ''
END AS column9
,CASE
WHEN fcg.column15 IN (
'000166915'
,'000166916'
,'000166913'
,'000168717'
,'000168718'
)
THEN 'Y'
WHEN fcg.column15 IN (
'000168719'
,'000166920'
,'000166917'
,'000166919'
,'000166914'
,'000168716'
)
THEN 'N'
WHEN SUBSTRING(fcg.column15 FROM 6 FOR 1) = '1'
THEN 'Y'
WHEN SUBSTRING(fcg.column15 FROM 6 FOR 1) = '2'
THEN 'N'
ELSE ''
END AS column10
,CASE
WHEN fcg.Column25 IN (
'0004'
,'0005'
,'0006'
)
THEN 'Y'
ELSE 'N'
END column11
,SUM(li.Column26) AS Column26
,SUM(li.Column27) AS Column27
,SUM(li.Column28) AS paid_amt
,SUM(CASE
WHEN clm.Column20 = '01'
THEN li.Column26 - li.non_covd_amt - li.Column30
ELSE li.Column29
END) AS amount
FROM DatabaseLi li
INNER JOIN DatabaseFCG fcg
ON fcg.column30 = li.column30
AND li.disp_cd = 'A'
INNER JOIN Database11 clm
ON clm.column30 = li.column30
INNER JOIN Database11_mbr MBR
ON li.column30 = MBR.column30
LEFT JOIN / CategoryG exclusion /
(
SELECT column30
FROM Database11_src
WHERE Column50IN('MA', 'H8')
GROUP BY 1
) src
ON li.column30 = src.column30
INNER JOIN
(
SELECT column15
,CASE
WHEN product_id LIKE '%apple%'
THEN 'apple'
WHEN product_id LIKE '%orange%'
THEN 'orange'
WHEN product_id LIKE '%banana%'
THEN 'apple'
ELSE ''
END AS column8
FROM DatabaseDD
WHERE lob IN ('Categrory3')
AND product_id IS NOT NULL
AND product_id NOT LIKE '%LV%'
GROUP BY 1,2
) AS a
ON a.column15 = fcg.column15
/*This is the WHERE statement to remove*/
WHERE /* Excluding ALL CategoryG after 2014 - 01 - 01 */
li.column7 >= '2014-01-01'
AND src.column30 IS NULL
AND clm.Column20 <> '04'
AND NOT MBR.column55 IN (
SELECT DISTINCT a.column55
FROM DatabaseA a
INNER JOIN DatabaseB b ON a.column1 = b.column1
AND a.column2 = b.column2
AND a.column3 = b.column3
AND a.column4 = b.column4
AND a.column5 = '11'
AND a.column14 IN (
SELECT DISTINCT column15
FROM DatabaseDD
WHERE lob LIKE '%Categrory3%'
)
AND a.column6 <> 'IND'
)
AND NOT fcg.column15 IN (
SELECT DISTINCT a.column14
FROM DatabaseA a
INNER JOIN DatabaseB b ON a.column1 = b.column1
AND a.column2 = b.column2
AND a.column3 = b.column3
AND a.column4 = b.column4
AND a.column5 = '11'
AND a.column14 IN (
SELECT DISTINCT column15
FROM DatabaseDD
WHERE lob LIKE '%Categrory3%'
)
AND a.column6 <> 'IND'
)
AND li.column7 < '2016-01-01'
GROUP BY 1,2,3,4,5,6,7,8
)
WITH DATA UNIQUE PRIMARY INDEX (
STATE
,column8
,column9
,column10
,column11
,column12
,column13
) ON COMMIT PRESERVE ROWS;
我尝试了第一块选择的解释,但不确定它意味着什么 - 说明 SELECT DISTINCT(xxx) 1)首先,我们锁定xxx 访问,我们锁定xxx在视图中 xxx用于访问,我们锁定 xxx在视图xxx中进行访问。 2)接下来,我们从xxx进行全AMPs RETRIEVE步骤 通过带有a的全行扫描查看xxx 条件(xxx)成 假脱机1(all_amps),它是在AMP上本地构建的。尺寸 假设Spool 1的置信度低,为225,735,188行 (9,255,142,708字节)。此步骤的预计时间为11.64 秒。 3)我们并行执行以下步骤。 1)我们从xxx进行全AMPs RETRIEVE步骤 通过全行扫描查看xxx 条件为(xxx)成 假脱机1(all_amps),它是在AMP上本地构建的。该 假设1,假脱机1的大小是低的 241,718,108行(9,910,442,428字节)。估计的时间 这一步是1.21秒。 2)我们在xxx中进行全AMPs RETRIEVE步骤 xxx通过带有的全行扫描 条件(xxx)进入线轴5(all_amps)(压缩列 允许)散布到10个散列连接分区,这是 通过(xxx)的哈希码重新分配给所有AMP。后台打印5的大小是 低信心估计为44,346,884行( 2,172,997,316字节)。这一步的估计时间是 11.23秒 4)我们通过Spool 1(Last Use)进行全AMPs RETRIEVE步骤 条件为(xxx)的全行扫描进入假脱机6(all_amps)(压缩 允许的列)散布到10个散列连接分区,即 通过(xxx)的哈希码重新分配给所有AMP。线轴6的大小是 低信心估计为241,718,108行( 9,910,442,428字节)。此步骤的预计时间是8.49 秒。 5)我们通过一个来自Spool 5(Last Use)的全AMP连接步骤 全行扫描,通过一个连接到Spool 6(Last Use) 全行扫描。使用散列连接来连接假脱机5和假脱机6 10个分区,连接条件为(xxx)结果进入假脱机4(all_amps)(压缩列 允许),它是在AMP上本地构建的。线轴4的大小 估计低信心为45,125,207行( 1,037,879,761字节)。此步骤的估计时间为1.00 秒。 6)我们做一个全AMP的SUM步骤,从Spool 4(Last Use)聚合 全行扫描的方式,按field1分组( XXX)。总体中间结果是 全局计算,然后放入假脱机2。假脱机2的大小是 低信心估计为18,209,884行(528,086,636 字节)。此步骤的估计时间为1.34秒。 7)最后,我们向所有涉及的AMP发送END TRANSACTION步骤 在处理请求。 - &GT;作为结果,假脱机2的内容被发送回用户 声明1.估计总时间为33.70秒。
答案 0 :(得分:2)
除了JNevill在其答案中提供的合理建议之外,我还建议您与DBA一起评估查询的DBQL步骤信息,以便准确了解查询中错误发生的位置。您可能会发现其他统计信息可能会影响优化程序的计划并避免出现假脱机错误。
因为这是一个VOLATILE表,所以它是在用户的假脱机空间中创建的。如果查询未在查询计划的中间步骤上失败,则可能是由于假脱机空间不足而无法实现假脱机中的VOLATILE TABLE。如果这是在用户会话中执行并生成其他易失性表的其中一个语句,则可能是导致问题的部分的总和。
答案 1 :(得分:1)
假脱机空间是存储中间结果集的位置。这些通常来自子查询(但也包括在连接之前预先过滤的表和其他一百万个)。因此,为了解决您的假脱机空间问题,一个很好的第一步是将子查询删除到自己的易失性表。然后加入那些不稳定的表。
这可能类似于:
CREATE MULTISET VOLATILE TABLE volatile_1 AS
(
SELECT DISTINCT a.column55
FROM DatabaseA a
INNER JOIN DatabaseB b ON a.column1 = b.column1
AND a.column2 = b.column2
AND a.column3 = b.column3
AND a.column4 = b.column4
AND a.column5 = '11'
AND a.column14 IN (
SELECT DISTINCT column15
FROM DatabaseDD
WHERE lob LIKE '%Categrory3%'
)
AND a.column6 <> 'IND'
) WITH DATA ON COMMIT PRESERVE ROWS;
CREATE MULTISET VOLATILE TABLE volatile_2 AS
(
SELECT DISTINCT a.column14
FROM DatabaseA a
INNER JOIN DatabaseB b ON a.column1 = b.column1
AND a.column2 = b.column2
AND a.column3 = b.column3
AND a.column4 = b.column4
AND a.column5 = '11'
AND a.column14 IN (
SELECT DISTINCT column15
FROM DatabaseDD
WHERE lob LIKE '%Categrory3%'
)
AND a.column6 <> 'IND'
) WITH DATA ON COMMIT PRESERVE ROWS;
CREATE MULTISET VOLATILE TABLE volatile_src AS
(
SELECT column30
FROM Database11_src
WHERE Column50IN('MA', 'H8')
GROUP BY 1
) WITH DATA ON COMMIT PRESERVE ROWS;
CREATE MULTISET VOLATILE TABLE volatile_src AS
(
SELECT column15
,CASE
WHEN product_id LIKE '%apple%'
THEN 'apple'
WHEN product_id LIKE '%orange%'
THEN 'orange'
WHEN product_id LIKE '%banana%'
THEN 'apple'
ELSE ''
END AS column8
FROM DatabaseDD
WHERE lob IN ('Categrory3')
AND product_id IS NOT NULL
AND product_id NOT LIKE '%LV%'
GROUP BY 1,2
) WITH DATA ON COMMIT PRESERVE ROWS;
CREATE VOLATILE TABLE A
,NO FALLBACK
,NO BEFORE JOURNAL
,NO AFTER JOURNAL AS
(
SELECT 'TX' AS STATE
,ADD_MONTHS(li.column7 - EXTRACT(DAY FROM li.Column21) + 1, 1) - 1 AS column12
,ADD_MONTHS(li.Column22 - EXTRACT(DAY FROM li.Column22) + 1, 1) - 1 AS column13
,EXTRACT(YEAR FROM column13) * 12 + EXTRACT(MONTH FROM column13) - EXTRACT(YEAR FROM column12) * 12 - EXTRACT(MONTH FROM column12) AS offset
,column8
,CASE
WHEN clm.Column20 = '01strong text'
AND li.Column23 = '1'
THEN 'INP'
WHEN clm.Column20 = '01'
AND li.Column23 IN (
'2'
,'3'
)
THEN 'OUT'
WHEN clm.Column20 = '02'
AND CHARACTER_LENGTH(TRIM(Column24)) <> 5
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 1 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 2 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 3 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 4 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND SUBSTRING(TRIM(Column24) FROM 5 FOR 1) BETWEEN 'A'
AND 'Z'
THEN 'OME'
WHEN clm.Column20 = '02'
AND Column24 BETWEEN '00000'
AND '99999'
THEN 'PRO'
WHEN clm.Column20 = '02'
THEN 'OME'
WHEN clm.Column20 = '03'
THEN 'PDP'
WHEN clm.Column20 = '04'
THEN 'DEN'
ELSE ''
END AS column9
,CASE
WHEN fcg.column15 IN (
'000166915'
,'000166916'
,'000166913'
,'000168717'
,'000168718'
)
THEN 'Y'
WHEN fcg.column15 IN (
'000168719'
,'000166920'
,'000166917'
,'000166919'
,'000166914'
,'000168716'
)
THEN 'N'
WHEN SUBSTRING(fcg.column15 FROM 6 FOR 1) = '1'
THEN 'Y'
WHEN SUBSTRING(fcg.column15 FROM 6 FOR 1) = '2'
THEN 'N'
ELSE ''
END AS column10
,CASE
WHEN fcg.Column25 IN (
'0004'
,'0005'
,'0006'
)
THEN 'Y'
ELSE 'N'
END column11
,SUM(li.Column26) AS Column26
,SUM(li.Column27) AS Column27
,SUM(li.Column28) AS paid_amt
,SUM(CASE
WHEN clm.Column20 = '01'
THEN li.Column26 - li.non_covd_amt - li.Column30
ELSE li.Column29
END) AS amount
FROM DatabaseLi li
INNER JOIN DatabaseFCG fcg
ON fcg.column30 = li.column30
AND li.disp_cd = 'A'
INNER JOIN Database11 clm
ON clm.column30 = li.column30
INNER JOIN Database11_mbr MBR
ON li.column30 = MBR.column30
LEFT JOIN volatile_src src
ON li.column30 = src.column30
INNER JOIN volatile_a AS a
ON a.column15 = fcg.column15
WHERE / Excluding ALL CategoryG after 2014 - 01 - 01 /
li.column7 >= DATE '2014-01-01'
AND src.column30 IS NULL
AND clm.Column20 <> '04'
AND NOT MBR.column55 IN (SELECT * FROM volatile_1)
AND NOT fcg.column15 IN (SELECT * FROM volatile_2)
AND li.column7 < '2016-01-01'
GROUP BY 1,2,3,4,5,6,7,8
)
WITH DATA UNIQUE
PRIMARY INDEX
(
STATE
,column8
,column9
,column10
,column11
,column12
,column13
)
ON COMMIT PRESERVE ROWS;
如果您仍然遇到线轴问题,请将查询中断。在SELECT和WHERE子句中删除所有连接和对连接表的任何引用,然后运行它。它会结束吗?如果没有,请添加下一个,并重新输入相关的SELECT
和WHERE
子句。运行它。它会结束吗?如果没有,请在下一个表格中添加。继续这样做,直到你结束。您可以区分您可以通过此一个查询推送的数据量。
您可能必须使用UPDATE语句将其分解为更多语句,以便将更多数据写入连接的记录中。
您可能需要向DBA请求更多假脱机。如果这是一次性的事情,也许有更多SPOOL可用的人可以为你运行它?