[10.x] Updated SQL Server to consistently use OFFSET/FETCH #44458
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
SQL Server on Laravel 8 was updated to use
OFFSET/FETCH
instead of therow_number()
for offset and limit. Woo! 馃コ (#39863)However, if an
orderBy
is not included, Laravel will fallback to old code that still usesrow_number()
-- which adds an unexpected columnrow_num
to the results.This unexpected column causes the following issues:
row_num
as a column name or alias unless you include a selectrow_num
This PR updates the
row_number()
toOFFSET/FETCH
, removing the need for therow_num
column and increasing query performance. sourceChanges
row_number()
logic to match the current use ofOFFSET/FETCH
OFFSET/FETCH
logic into built in functionsExample
Currently, if you include an order by, it uses offset and fetch:
However, if order by is not included, it falls back to the old method of offsetting the results:
This PR would instead produce:
Edge cases
row_num
in their applications when order by is not used, so this could be considered a breaking change.