需要提高sql查询的性能
我有 3 个表 a、b、c。
select * from a
select * from b where aid in (select id from a)
select * from c where bid in (select Id from b where aid in (select id from a))
这些查询在 sp 中工作正常,但作为性能,我需要优化它们。 您能否建议我如何提高性能,或任何可用的工具 优化sql查询。
谢谢 。
I have 3 table a,b,c.
select * from a
select * from b where aid in (select id from a)
select * from c where bid in (select Id from b where aid in (select id from a))
These queries in sp and working fine but as performance I need to optimise these.
Could you please suggest how do I improve perfomance, or any tools available to
optimise sql queries.
Thanks .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我认为你可以使用
INNER JOIN
重写查询:如果你有id、bid和aid索引,一切都应该没问题
I think you could rewrite the queries using
INNER JOIN
:if you have indexes on id, bid and aid all should be fine
查询速度缓慢的原因可能有很多。从您所描述的几个出发点可能是:
您可能需要使用 Tuning Advisor 和/或 SQL Server Profiler - 两者都可以在启动时的 SQL Server 文件夹下的性能工具菜单中找到。
此外,了解 Management Studios 报告的可能性并熟悉执行计划也是很好的起点。
对于更高级的学习者,开始包括查询 I/O 的统计信息(在 Management Studios 查询窗口中),使用 Windows 性能监视器来关注相关的 SQL Server 计数器等。可以在此处找到其中一些的很好的解释:http://www.sql-server-performance.com/2005/sql-server-performance-monitor-coutners/
There can be many reasons why your queries are slow. From what you describe a few starting points could be:
You might want to use the Tuning Advisor and/or SQL Server Profiler - both avaialble in the Performance Tools menu under your SQL Server folder in startup.
Also, learning the Management Studios reporting possibilities, and getting acquainted with execution plans are good starting points.
For the more advanced learners, start including statistics for query I/O (in Management Studios Query Window), using the Windows Performance Monitor to keep an eye on relevant SQL Server counters, etc. A good explanation to some of them can be found here: http://www.sql-server-performance.com/2005/sql-server-performance-monitor-coutners/
您能否表达您的疑问:
Can you express your queries like:
您还可以尝试使用exists 代替IN:s。如果有分配的数据可以提供帮助:
You can also try using exists instead of IN:s. If there is allot of data that can help: