如何优化Sybase Sql查询?

问题描述 投票:0回答:1

我有一个从 Sybase 数据库获取数据的 SQL 查询。在 where 子句中,我们根据要求使用文本列

(BU IN ('CMBS','MBS') AND RU='GBR')
。这些条款正在扼杀性能。使用的表有大量行。

有什么提高性能的建议吗?

下面是SQL-

SELECT [COLUMN LIST]
from dealer_Key dk, 
INNER JOIN d_posting dp ON dk.deal_key_id = dp.deal_key_id, 
INNER JOIN d_p_v dpv ON dp.posting_id = dpv.posting_id,
INNER JOIN snapInfo s ON dpv.snapshot_start_id = s.snapshot_id, 
INNER JOIN psgl_ratemeter r ON (dp.gl_currency = r.from_currency),
INNER JOIN psgl_ratemeter_value rv (ON r.psgl_rate_id = rv.psgl_rate_id AND rv.refdate = dpv.gl_transaction_effective_date)
where 
r.snapshot_end_id is null
and r.to_currency = 'AUD'
and (dp.snapshot_end_id is null or dp.snapshot_end_id > dpv.snapshot_start_id)
and dpv.gl_transaction_effective_date > '20140930'
and dpv.gl_transaction_effective_date < '20150901'
and gl_business_unit IN ('CTCMB')
and gl_currency='CAD'
and gl_counterparty='IMCLIMTR'
and gl_location='SYD'
and gl_department='LTFSY'
and gl_product='FEES'
sql query-optimization sybase
1个回答
0
投票

这是违反直觉的,但我们通过将逻辑移至 SELECT 中,发现了 Sybase ASA 的 WHERE 子句优化技巧。这是一种迫使不同执行策略的黑客行为。使用您的示例,您可以尝试在选择中放入“匹配”列,例如 -

SELECT (if (BU IN ('CMBS','MBS') AND RU='GBR') then 1 else 0 endif) 作为匹配

然后在你的where子句中-

哪里匹配=1

© www.soinside.com 2019 - 2024. All rights reserved.