任何人都可以帮助我提高以下sql的性能吗?使用的数据库是informix
SELECT
informix.set_reason_codes.description as reason_code,
count(*) as number_of_calls
FROM
informix.contact_history,
informix.set_reason_codes,
informix.customers
WHERE
(informix.contact_history.reason_code = informix.set_reason_codes.reason_code)
and ( ( informix.set_reason_codes.code_type = 'CONTACT_HISTORY' ) )
and ( informix.contact_history.customerkey = informix.customers.customerkey )
and ( informix.contact_history.call_type = 0 )
group
by informix.set_reason_codes.description
order by
informix.set_reason_codes.description
最佳答案
您需要通过运行此SQL并使用EXPLAIN ON来获取查询计划,即:
SET EXPLAIN ON;
SELECT ....
这会将优化器的计划写入文件(实际位置取决于操作系统和连接方法)。
一旦掌握了这一点,您将能够更好地确定性能问题的原因。但通常情况下,它可以归结为以下事情之一:
- 索引不当
- 索引统计信息已过时或缺失
sqexplain 文件中有关自动索引或顺序扫描(其中您期望嵌套循环(索引连接))的消息是一个很好的指示,需要进行一些调整。如果没有别的事,运行查询并获取解释输出,然后执行,
UPDATE STATISTICS MEDIUM FOR TABLE informix.contact_history;
UPDATE STATISTICS MEDIUM FOR TABLE informix.set_reason_codes;
UPDATE STATISTICS MEDIUM FOR TABLE informix.customers;
如果您得到的性能结果与查询计划中报告的结果显着不同,则说明您的问题与统计信息相关。
了解您正在运行的 Informix 版本也会很有用。
关于database - 提高informix中sql的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1475905/