我正在尝试优化以下SQL,但我对SQL优化的了解相当绿色,而且我没有取得多大进展。(由于公司策略,我将列和其他标识符概括化)在当前状态下,这个SQL根据负载运行需要1到2分钟的时间。 VKTINFO表包含大约100万条记录,GNTINFO表包含大约300万条记录。通常1-2分钟不会是一个大问题,如果这是一个批处理过程,但我们有代理需要这些信息现场和尽快 - 更糟糕的是,我们的系统最终超时并返回一个抱歉的错误用户。但是,不能扩展超时窗口。我们还有其他标准可以搜索,例如名字,邮政编码,帐户类型,帐户状态等等,但是当执行如下的广泛搜索时,查询会变得相当慢。
如果有关于如何操作此SQL以加快选择的任何建议/技巧,我将非常感谢对此事的任何想法。如果需要更多信息,我很乐意尽可能提供符合我们公司政策的信息。
修改 这里要求的是VKTINFO和GNTINFO表的索引。
gnt_account_info和vkt_account_info的索引:
gntnad和vktnad表的索引:
gntpolrf和vktpolrf表的索引:
select
processing_system,
total_premium,
quote_by,
email_address,
account_number,
expiration_date,
account_state,
xrf_file,
customer_name
from
(
select
'ABCD' as processing_system,
total_premium,
quote_by,
email_address,
account_number,
expiration_date,
account_state,
xrf_file,
customer_name
from vktinfo
left outer join vkt_account_info on account_number = pi_account_number
left outer join vktpolrf on account_number = xrf_account_number
left outer join VKTNAD on account_number = nad_account_number
and history_expiration_date=nad_history_expiration_date
and nad_name_type='HA'
WHERE effective_date >= '2013-02-01'
AND effective_date <= '2013-02-28'
AND customer_name like '_SMITH%'
AND account_state = 'South Carolina'
union all
select
'EFGH' as processing_system,
total_premium,
quote_by,
email_address,
account_number,
expiration_date,
account_state,
xrf_file,
customer_name
from gntinfo
left outer join gnt_account_info on account_number = pi_account_number
left outer join vktpolrf on account_number = xrf_account_number
left outer join GNTNAD on account_number = nad_account_number
and history_expiration_date=nad_history_expiration_date
and nad_name_type='HA'
WHERE effective_date >= '2013-02-01'
AND effective_date <= '2013-02-28'
AND customer_name like '_SMITH%'
AND account_state = 'South Carolina'
)
a
order by customer_name ASC fetch first 1000 rows only WITH UR
答案 0 :(得分:1)
我没有坚如磐石的答案。但我确实有一些你可以试试的东西。我知道您无权获得执行计划。