我有一个像这样的巨大查询:
SELECT 'Tipification', COUNT(*) TOTAL, to_char(INITDATE,'YYYY-MM-DD')
FROM (
SELECT (TYPE || ' \ ' || SUBTYPE || ' \ ' || PROBLEM ) Triplet, INITDATE
FROM TABLE
WHERE USER IS NOT null
AND (INITDATE >= TO_DATE('2016-12-01 00:00', 'YYYY-MM-DD HH24:MI:SS'))
AND (INITDATE <= TO_DATE('2016-12-31 23:59', 'YYYY-MM-DD HH24:MI:SS'))
AND ( (TYPE || ' \ ' || SUBTYPE || ' \ ' || PROBLEM) = 'aaa \ bbb \ ccc'
OR (TYPE || ' \ ' || SUBTYPE || ' \ ' || PROBLEM) = 'aaa \ bbb \ ddd'
OR (TYPE || ' \ ' || SUBTYPE || ' \ ' || PROBLEM) = 'xxx \ yyy \ zzz'
OR (TYPE || ' \ ' || SUBTYPE || ' \ ' || PROBLEM) = 'qqq \ www \ eee'
... etc ...
)
GROUP BY to_char(INITDATE,'YYYY-MM-DD')
如果有更多300个字符串连接:(TYPE || ' \ ' || SUBTYPE || ' \ ' || PROBLEM) = '... \ ... \ ...'
。
执行此查询时,我收到了一些核心转储,因为执行DB太昂贵了。
在没有数据库内存不足的情况下,有没有其他方法可以执行这样的查询?
答案 0 :(得分:6)
Oracle有一个很好的in
函数,允许你放入多列组合。
select to_char(INITDATE,'YYYY-MM-DD'), count(*)
from table
where user is not null
AND (INITDATE >= TO_DATE('2016-12-01 00:00', 'YYYY-MM-DD HH24:MI:SS'))
AND (INITDATE <= TO_DATE('2016-12-31 23:59', 'YYYY-MM-DD HH24:MI:SS'))
and (type, subtype, problem) in (
('aaa','bbb','ccc'),
('aaa','bbb','ddd')) -- ... etc
group by to_char(INITDATE,'YYYY-MM-DD')
答案 1 :(得分:-1)
val some_set = mutable.HashSet[String]
some_rdd.filterNot(r => some_set.contains(r.some_class.id)
.map(some_row => {
try{
some_def(some_row)
}
catch{
case e:Throwable => {
some_set.add(some_row.some_class.id)
log.info("some error")
}
}
}
的替代查询:
SAP HANA DB
类似地,也可以在更新和删除查询中使用它。