如何优化给定的db2查询,
考虑我的DB2查询,如下所示如何优化给定的db2查询,,db2,Db2,考虑我的DB2查询,如下所示 Select something from some tables, (select something from some tables where bhla=bhla Unionall select something from some tables where bhla=bhla union select something from some tables where bhla=bhla) x where bhla=bhla 看起来 select x.
Select something from some tables,
(select something from some tables where bhla=bhla
Unionall
select something from some tables where bhla=bhla
union
select something from some tables where bhla=bhla) x
where bhla=bhla
看起来
select x.something, y.somethingelse from table y,
(select something from some tables where bhla=bhla
Unionall
select something from some tables where bhla=bhla
union
select something from some tables where bhla=bhla) x
where bhla=bhla
我的问题是优化上述查询(更好地使用查询)。
请提供一些关于索引的输入以及如何使用索引。
我需要优化上述查询,因此请提出一些建议
你能建议hw重新编码下面的where子句吗
在哪里
(ID.EXCH\u RT 0.000000且ID.EXCH\u RT不为空)
和I.在(:Param_290_从日期CONCAT“00:00:00.00000”)和(:Param_300_到日期CONCAT“23:59:59.9999”之间的行为
无法使用给定的信息进行优化。
通常情况下,当人们问一个不够具体的问题时,他们只是被指代。然而,我看到了很多这种特殊情况:请求帮助优化未定义良好的SQL查询。所以我想更详细地说明这里的错误
为什么不能对此进行优化
table1
很小而table2
很大,这将是优化查询的一个好方法。但是,如果table1
很大而table2
很小,那么这将是一个非常糟糕的查询设计,浪费大量时间。在不了解任何数据的情况下,无法判断最佳设计with complicated as (
select id,
char(foo) || case when bar = 1234 then 'a' else 'c' end || 'baz'
as complicated_field
from table1
)
select * from table2
join complicated on
complicated.id = table2.id and
complicated.complicated_field = table2.some_field
我希望这是有帮助的。如果您能提供更多信息,我们将非常乐意提供进一步帮助。在这种通用的情况下无法进行优化。请描述每个表格(最好有样本数据)。每个表有多少行?这是必须知道的。另外,请用英语描述此查询应该做什么。另外,指定您使用的平台:z、i或LUW也很重要。您能建议hw重写以下where子句
(ID.EXCH_RT 0.000000和ID.EXCH_RT不为空)和i.ACT_LOC_TS之间的(:Param_290_From_Date CONCAT'00:00.00000')和(:Param_300_To_Date CONCAT'23:59:59.99999')
@javaProgrammer,我们没有足够的上下文来处理这个问题,原因与我在回答中所说的相同。我们想提供帮助,但除非你写一个好问题,否则我们无法给出一个好的答案。@WarrenT,谢谢你的建议,我已经更新了答案。
with complicated as (
select id,
char(foo) || case when bar = 1234 then 'a' else 'c' end || 'baz'
as complicated_field
from table1
)
select * from table2
join complicated on
complicated.id = table2.id and
complicated.complicated_field = table2.some_field