Skip to content

Commit

Permalink
If it's a first page and we do not show results count and TOP is not …
Browse files Browse the repository at this point in the history
…present in the query then TOP is added to the SQL query.

It can help optimizer build a better plan
  • Loading branch information
eduard93 committed May 15, 2018
1 parent cbe2268 commit 6d6e05b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Form/JSON/SQL.cls.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,15 @@ nocount - do not output count of rows</Description>
<Implementation><![CDATA[
Set:$IsObject($Get(%request)) tMode = %request.Get("mode", 0)
Set tRS = ##class(%ResultSet).%New()
If $$$webContext {
Set nocount = %request.Get("nocount", $$$NO)
}
If ((..currPage=1) && ($g(nocount, $$$NO)) && ($ZCVT($tr(..sql," "), "U") '[ "SELECTTOP")) {
Set ..sql = $replace(..sql , "SELECT", "SELECT TOP " _ ..pageSize _ " ",,1,1)
}
Set tSC = tRS.Prepare(..sql)
Set tRS.RuntimeMode = $Get(tMode, 0)
Set pInfo.queryText = "sql: "_..sql
Expand Down

0 comments on commit 6d6e05b

Please sign in to comment.