我正在尝试优化以下 SQL,但我对 SQL 优化的了解相当浅,而且我没有取得太大进展。(由于公司政策,我概括了列和其他标识符)在当前状态下,此 SQL 介于根据负载运行 1 到 2 分钟。VKTINFO 表包含大约 100 万条记录,GNTINFO 表包含大约 300 万条记录。如果这是一个批处理过程,通常 1-2 分钟不会有什么大不了的,但我们有代理需要这些信息,并且尽快 - 更糟糕的是,我们的系统最终会超时并返回一个抱歉的错误用户。但是,延长超时窗口不是一种选择。我们还有其他条件可供搜索,例如名字、邮政编码、帐户类型、帐户状态、
如果对如何操纵此 SQL 以加快选择速度有任何建议/技术,我将非常感谢您对此事的任何想法。如果需要更多信息,我很乐意提供尽可能多的仍然符合我们公司政策的信息。
编辑: 这里要求的是 VKTINFO 和 GNTINFO 表的索引。
- 帐号
- 截止日期
- 生效日期
gnt_account_info 和 vkt_account_info 的索引:
- pi_account_num
- pi_policy_num_gid
gntnad 和 vktnad 表的索引:
- nad_account_number
- nad_name_type
gntpolrf 和 vktpolrf 表的索引:
- xrf_account_number
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