2016-06-21 14 views
2

我有两个约130万行的表的简单连接的AutoQuery设置。使用内置的迷你分析器来测量SQL时序,返回前100行(无过滤)的查询需要3ms,计数需要额外的341ms。您可以禁用ServiceStack AutoQuery的计数(总计)吗?

是否可以使用自动查询而不提取计数?我实际上不需要知道完整的计数。

编辑

所以我在想,找出是否有剩余VS满计数可能会更快更行。我使用SSMS针对我们的MSSQL数据库测试了这一点。

--Generated by ServiceStack 
set statistics time on 
SELECT COUNT(*) "COUNT(*)" 
FROM "table1" INNER JOIN "table2" ON 
("table1"."PrimaryKey" = "table2"."ForeignKey") 
set statistics time off 

--Skipping 100 
set statistics time on 
SELECT CASE WHEN EXISTS(
    SELECT "table1"."PrimaryKey" 
    FROM "table1" INNER JOIN "table2" ON 
    ("table1"."PrimaryKey" = "table2"."ForeignKey") 
    ORDER BY "table1"."PrimaryKey" OFFSET 100 ROWS FETCH NEXT 1 ROWS ONLY 
) 
THEN CAST(1 AS BIT) 
ELSE CAST(0 AS BIT) END 
set statistics time off 

--Skipping 100000 
set statistics time on 
SELECT CASE WHEN EXISTS(
    SELECT "table1"."PrimaryKey" 
    FROM "table1" INNER JOIN "table2" ON 
    ("table1"."PrimaryKey" = "table2"."ForeignKey") 
    ORDER BY "table1"."PrimaryKey" OFFSET 100000 ROWS FETCH NEXT 1 ROWS ONLY 
) 
THEN CAST(1 AS BIT) 
ELSE CAST(0 AS BIT) END 
set statistics time off 

--Skipping 1000000 
set statistics time on 
SELECT CASE WHEN EXISTS(
    SELECT "table1"."PrimaryKey" 
    FROM "table1" INNER JOIN "table2" ON 
    ("table1"."PrimaryKey" = "table2"."ForeignKey") 
    ORDER BY "table1"."PrimaryKey" OFFSET 1000000 ROWS FETCH NEXT 1 ROWS ONLY 
) 
THEN CAST(1 AS BIT) 
ELSE CAST(0 AS BIT) END 
set statistics time off 

输出:

(1 row(s) affected) 

SQL Server Execution Times: 
    CPU time = 203 ms, elapsed time = 200 ms. 

(1 row(s) affected) 

SQL Server Execution Times: 
    CPU time = 0 ms, elapsed time = 0 ms. 

(1 row(s) affected) 

SQL Server Execution Times: 
    CPU time = 16 ms, elapsed time = 19 ms. 

(1 row(s) affected) 

SQL Server Execution Times: 
    CPU time = 203 ms, elapsed time = 193 ms. 

回答

3

这不是你刚才是否需要知道完整的计数或没有,但还需要总的ServiceClient API's like GetLazy()所以它能够透明地流自动查询结果后面多个分页查询。

这是以前没有一个明确的选择,但你可以通过添加ResponseFilter与一个预填充它,例如避免自动查询查询总:

Plugins.Add(new AutoQueryFeature { 
    MaxLimit = 100, 
    ResponseFilters = { 
     ctx => { ctx.Response.Meta["COUNT(*)"] = "0"; } 
    } 
}); 

我也只是增加了支持

Plugins.Add(new AutoQueryFeature { 
    MaxLimit = 100, 
    IncludeTotal = false, 
}); 

这种变化可以从v4.0.61这就是现在available on MyGet:在this commit此选项,以便在未来的版本你可以删除总。

+0

我添加了一些关于如何提高大数据集分页性能的时间细节。 –

+0

@AnonyCarl时间很有趣,但并没有报告最终用户喜欢看到的行数,只能用于MSSQL。但是如果你想在你的回复中包含它,你应该可以在[Custom ResponseFilter](https://github.com/ServiceStack/ServiceStack/wiki/AutoQuery-RDBMS#autoquery-response-filters )。 – mythz