Skip to content

Commit 6d6e05b

Browse files
committed
If it's a first page and we do not show results count and TOP is not present in the query then TOP is added to the SQL query.
It can help optimizer build a better plan
1 parent cbe2268 commit 6d6e05b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Form/JSON/SQL.cls.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,15 @@ nocount - do not output count of rows</Description>
347347
<Implementation><![CDATA[
348348
Set:$IsObject($Get(%request)) tMode = %request.Get("mode", 0)
349349
Set tRS = ##class(%ResultSet).%New()
350+
351+
If $$$webContext {
352+
Set nocount = %request.Get("nocount", $$$NO)
353+
}
354+
355+
If ((..currPage=1) && ($g(nocount, $$$NO)) && ($ZCVT($tr(..sql," "), "U") '[ "SELECTTOP")) {
356+
Set ..sql = $replace(..sql , "SELECT", "SELECT TOP " _ ..pageSize _ " ",,1,1)
357+
}
358+
350359
Set tSC = tRS.Prepare(..sql)
351360
Set tRS.RuntimeMode = $Get(tMode, 0)
352361
Set pInfo.queryText = "sql: "_..sql

0 commit comments

Comments
 (0)