JOINS、EXISTS 或 IN 哪个更好?关于SQL的几个问题 [英] JOINS, EXISTS or IN which is better? Few questions on SQL
问题描述
我有几个关于 SQL 的问题..
I have few questions on SQL..
如何分析一个系统的性能询问?任何软件,内置MSSQL Server 2005/2008 的特点?
How to analyze the performance of a query? Any software, inbuilt features of MSSQL server 2005/2008?
在查询中应该用什么代替in
才能使性能更好?例如:
What should be used in place of in
in queries so that the performance is better?
Eg:
选择 *FROM enquiry_courses在哪里enquiry_id IN( SELECT enquiry_id FROM 查询 WHERE session_id = '4cd3420a16dbd61c6af58f6199ac00f1' )
SELECT * FROM enquiry_courses WHERE enquiry_id IN ( SELECT enquiry_id FROM enquiries WHERE session_id = '4cd3420a16dbd61c6af58f6199ac00f1' )
在性能方面,JOINS
、EXISTS
或 IN
哪个更好?
Which is better: JOINS
, EXISTS
or IN
in terms of performance?
感谢评论/帮助...
推荐答案
使用 SQL Server Management Studio,并包括
Actual Execution Plan
和SET STATISTICS TIME
和SET STATISTICS IO
.
这对应于 JOIN
,但重写可能无关紧要.猜测可能是您需要 enquiry_courses.enquiry_id
和 enquiries.session_id
上的索引来提高查询性能.
This in corresponds to a JOIN
, but rewriting probably won't matter. A guess could be that you need indexes on enquiry_courses.enquiry_id
and on enquiries.session_id
to improve query performance.
这篇关于JOINS、EXISTS 或 IN 哪个更好?关于SQL的几个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!