提高informix中sql的性能
任何人都可以帮助我提高以下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
Can any one help me in increasing the performance of below sql. Database using is 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要通过在 EXPLAIN ON 下运行此 SQL 来获取查询计划,即:
这会将优化器的计划写入文件(实际位置取决于操作系统和连接方法)。
一旦掌握了这一点,您将能够更好地确定性能问题的原因。但通常情况下,它可以归结为以下问题之一:
sqexplain 文件中有关自动索引或顺序扫描的消息(您可能期望嵌套循环(索引连接)是一个很好的指标)需要进行调整。如果没有别的事,运行查询并获取解释输出,然后执行,
如果您得到的性能结果与查询计划中报告的结果显着不同,则您知道您的问题与统计信息相关。
了解您正在运行的 Informix 版本也会很有用。
You need to obtain the query plan by running this SQL with EXPLAIN ON, ie:
This will write the optimiser's plan to a file (actual location depends on OS and connection method).
Once you have this, you'll be in a much better position to identify the cause of your performance problem. But usually, it boils down to one of these things:
Messages in the sqexplain file about AUTO-INDEXes or SEQUENTIAL SCANs where you would have expected NESTED LOOP (index joins) are a pretty good indicator some tuning is required. If nothing else, run the query and get the explain output, then execute,
If you get a dramatically different result in performance and reported in the query plan, you know your problem is statistics related.
It would be useful to know what version of Informix you're running, too.
了解如何使用表别名使 SQL 可读:
避免多余的括号也有帮助。你可以对布局进行争论——但沿着这些思路的东西通常看起来是合理的。
有一天,我们可以讨论使用用户“informix”作为表的所有者的优点或缺乏优点 - 我建议不要这样做,但有些人坚持认为这是他们的最佳选择。 (我不同意他们的推理,但客户总是对的。)
关于性能,您在评论中说索引是:
您的问题的一部分就在这里。您可能会受益于索引:
这将有助于连接 '
h.reason_code = r.reason_code
';现有的索引对此没有任何用处。您可能会从索引中受益:
然后我们开始讨论问题的实质;您加入了 customer 表,但似乎没有任何实际理由这样做 - 假设
customerkey
实际上是customers
表的主键。因此,您将从该查询中得到相同的结果:
Learn how to use table aliases to make the SQL readable:
Avoiding superfluous brackets helps too. You can debate the layout - but something along these lines usually looks reasonable.
Another day, we can debate the merits or lack of merits in using user 'informix' as the owner of the tables - I recommend against doing so, but there are those who insist that it is the best choice for them. (I disagree with their reasoning, but the customer is always right.)
Regarding performance, you say in a comment that the indexes are:
Part of your problem lies here. You would probably benefit from an index:
This would help with the join on '
h.reason_code = r.reason_code
'; the existing index is no use for that whatsoever.You might benefit from an index:
Then we get to the meat of the issue; you join with the customer table, but there doesn't seem to be any actual reason to do so - assuming that the
customerkey
is in fact the primary key of thecustomers
table.So, you would get the same result from this query: