积极答复者
同样的查询在不同环境下执行,为什么效果大不相同?

问题
-
SELECT MAX(cpscjd.scrq) AS scrq, cpscjd.bmbh, cpscjd.bmmc, cpscjd.jhh, cpscjd.pch, cpscjd.bh, cpscjd.gxrid, ISNULL(scgx.flbh,
'') AS flbh, scgx.bh AS gxbh, scgx.mc AS gxmc, scgx.gg AS gxgg, cpscjh.jhsl, SUM(cpscjd.cpsl) AS cpsl, SUM(cpscjd.fpsl)
AS fpsl, MAX(cpscjd.fuhe) AS fuhe, MAX(cpscjd.quxiao) AS quxiao
FROM cpscjd INNER JOIN
cpscjh ON cpscjh.bmbh = @bmbh AND cpscjd.bmbh = @bmbh AND cpscjd.pch = cpscjh.pch INNER JOIN
scgx ON cpscjd.gxrid = scgx.rid
WHERE EXISTS
(SELECT rid
FROM cpscjd AS cpscjd_1
WHERE (scrq BETWEEN @scrq1 AND @scrq2) AND (bmbh = @bmbh) AND (pch = cpscjd.pch) AND
(gxrid = cpscjd.gxrid))
GROUP BY cpscjd.bmbh, cpscjd.bmmc, cpscjd.jhh, cpscjd.pch, cpscjd.bh, scgx.flbh, scgx.bh, scgx.mc, scgx.gg, cpscjh.jhsl,
cpscjd.gxrid
HAVING (SUM(cpscjd.cpsl) > cpscjh.jhsl)这是我在数据集设计器中做的一个查询。
在查询生成器中,执行该查询,瞬间(不到1秒钟)便得到结果,在SQL Server中执行,也不到1秒钟。
但是,在数据集设计器中,在预览数据对话框中,却长时间得不到结果,最终出现超时错误;同样,在程序中调用该查询,也是长时间无结果。
请问,问题在哪里?为什么在不同的环境中,执行效果会大不相同?
韩立学
- 已编辑 大海怪 2014年11月28日 3:17
答案
-
谢谢回复!
跟踪发现,同样的语句和参数:
1.在数据集查询生成器、SQL SERVER查询中,执行正常;
2.在数据集预览数据对话框、程序调用中,执行超时,且CPU、Reads、Writes数据要比第1种情况大得多。
这是为什么呢?
韩立学
你试试只查询部分结果呢 比如 select top 10?remember make the reply as answer and vote the reply as helpful if it helps.
- 已标记为答案 Youjun TangModerator 2014年12月5日 8:19
全部回复
-
SELECT MAX(cpscjd.scrq) AS scrq, cpscjd.bmbh, cpscjd.bmmc, cpscjd.jhh, cpscjd.pch, cpscjd.bh, cpscjd.gxrid, ISNULL(scgx.flbh,
'') AS flbh, scgx.bh AS gxbh, scgx.mc AS gxmc, scgx.gg AS gxgg, cpscjh.jhsl, SUM(cpscjd.cpsl) AS cpsl, SUM(cpscjd.fpsl)
AS fpsl, MAX(cpscjd.fuhe) AS fuhe, MAX(cpscjd.quxiao) AS quxiao
FROM cpscjd INNER JOIN
cpscjh ON cpscjh.bmbh = @bmbh AND cpscjd.bmbh = @bmbh AND cpscjd.pch = cpscjh.pch INNER JOIN
scgx ON cpscjd.gxrid = scgx.rid
WHERE EXISTS
(SELECT rid
FROM cpscjd AS cpscjd_1
WHERE (scrq BETWEEN @scrq1 AND @scrq2) AND (bmbh = @bmbh) AND (pch = cpscjd.pch) AND
(gxrid = cpscjd.gxrid))
GROUP BY cpscjd.bmbh, cpscjd.bmmc, cpscjd.jhh, cpscjd.pch, cpscjd.bh, scgx.flbh, scgx.bh, scgx.mc, scgx.gg, cpscjh.jhsl,
cpscjd.gxrid
HAVING (SUM(cpscjd.cpsl) > cpscjh.jhsl)这是我在数据集设计器中做的一个查询。
在查询生成器中,执行该查询,瞬间(不到1秒钟)便得到结果,在SQL Server中执行,也不到1秒钟。
但是,在数据集设计器中,在预览数据对话框中,却长时间得不到结果,最终出现超时错误;同样,在程序中调用该查询,也是长时间无结果。
请问,问题在哪里?为什么在不同的环境中,执行效果会大不相同?
韩立学
你使用 SQL Profile 跟踪一下执行过来的 SQL语句试试。
remember make the reply as answer and vote the reply as helpful if it helps.
-
谢谢回复!
跟踪发现,同样的语句和参数:
1.在数据集查询生成器、SQL SERVER查询中,执行正常;
2.在数据集预览数据对话框、程序调用中,执行超时,且CPU、Reads、Writes数据要比第1种情况大得多。
这是为什么呢?
韩立学
你试试只查询部分结果呢 比如 select top 10?remember make the reply as answer and vote the reply as helpful if it helps.
- 已标记为答案 Youjun TangModerator 2014年12月5日 8:19