psibr/Susanoo

Remove calculations from OFFSET/FETCH

Closed this issue · 2 comments

Instead using calculated values for OFFSET/FETCH, use direct integer values. The current format:

OFFSET (@PageNo - 1) * @PageSize ROWS
FETCH NEXT @PageSize ROWS ONLY

Proposed format:

OFFSET @Offset ROWS
FETCH NEXT @Fetch ROWS ONLY

Not all code using OffsetFetch will be based on page numbers and page size values. Because the formula is hard-coded, code that has start & length values will have to reverse calculate the page number and page size values so they can be converted back to the value as used in SQL.

Ideally the OffsetFetch<TFilter, TResult> (string, string) method would handle the new use and a new function for PageSizeNumber<TFilter, TResult> (string, string) could replace the existing calls. This would be a breaking change but it might be early enough in its use that it wouldn't cause too much pain.

Thoughts?

What about introducing an additional optional parameter on OffsetFetch(string, string, bool computePage = true), so that the computation could be turned off. This would avoid a major version increment.

This issue is resolved in commit: 7182f56.

Modifying BuildWhereFilter behavior to exclude parameters that have no value.
This change is important to assist with implified query plans in SQL Server.
Additionally, adding an override for offset fetches format that includes a SQL computed offset; 
  one overload has a bool to turn off computation, the other has a format string to overhaul the entire template.

If we agree on those changes I will queue up a release. Ignore the DefineInsert stuff, i apparently had outstanding changes i was working on and didn't notice.