2016-06-21 15 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