800+ records requires about 5 minutes=查询问题。
查看您的执行计划:
在SSMS中,运行:
SET SHOWPLAN_ALL ON
然后运行您的查询,它将不会产生预期的结果集,但是会针对数据库如何检索您的数据制定执行计划。大多数不良查询通常是表扫描(查看表中的每一行,速度很慢),因此请在该
StmtText列中查找单词“
SCAN” 。尝试弄清楚为什么未在该表上使用索引(名称将由单词“
SCAN”出现在该表中)。如果您加入多个表并且有多个SCAN,则首先将注意力集中在最大的表上。
没有更多信息,这是您可以获得的最佳“通用”帮助。
编辑
从阅读您的问题开始,我不确定您的意思是无论行数多少,它从SSMS总是很快,但是随着行数的增加,它从VB总是慢。
可能类似于:参数嗅探或连接参数不一致(ANSI空值,arithabort等)
对于连接设置,请尝试从SSMS和VB6运行它们(将它们添加到结果集中),看看是否存在任何差异:
SELECt SESSIonPROPERTY ('ANSI_NULLS') --Specifies whether the SQL-92 compliant behavior of equals (=) and not equal to (<>) against null values is applied. --1 = ON --0 = OFFSELECT SESSIonPROPERTY ('ANSI_PADDING') --Controls the way the column stores values shorter than the defined size of the column, and the way the column stores values that have trailing blanks in character and binary data. --1 = ON --0 = OFFSELECT SESSIonPROPERTY ('ANSI_WARNINGS') --Specifies whether the SQL-92 standard behavior of raising error messages or warnings for certain conditions, including divide-by-zero and arithmetic overflow, is applied. --1 = ON --0 = OFFSELECT SESSIonPROPERTY ('ARITHABORT') -- Determines whether a query is ended when an overflow or a divide-by-zero error occurs during query execution. --1 = ON --0 = OFFSELECT SESSIonPROPERTY ('CONCAT_NULL_YIELDS_NULL') --Controls whether concatenation results are treated as null or empty string values. --1 = ON --0 = OFFSELECT SESSIonPROPERTY ('NUMERIC_ROUNDABORT') --Specifies whether error messages and warnings are generated when rounding in an expression causes a loss of precision. --1 = ON --0 = OFFSELECT SESSIonPROPERTY ('QUOTED_IDENTIFIER') --Specifies whether SQL-92 rules about how to use quotation marks to delimit identifiers and literal strings are to be followed. --1 = ON --0 = OFF
使您的查询类似(这样您就可以在VB6中看到连接设置):
SELECT col1, col2 ,SESSIonPROPERTY ('ARITHABORT') AS ARITHABORT ,SESSIonPROPERTY ('ANSI_WARNINGS') AS ANSI_WARNINGS FROM ...
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)