[5.6] Add builder/grammar support for row values in where condition#22446
Conversation
|
So this implements a partially supported syntax for something that is already fully supported in the "full" syntax? |
|
Thanks for the feedback! Guess it the depends on POV and expectations. Basically, using OTOH (although I'm not trying to convince/evangelize anyone here), when I implemented this recently I wished I had a ready-made approach for, because why not; makes code more readable etc. But maybe you're right because not every database out there might support that syntax? Not sure how this is properly dealt with in the |
|
I could also imagining this as a building block for a future paginator extension which makes use of this technique instead of offset/limit |
|
According to SQL Feature Comparison, SQLServer does not support Tuple Comparison syntax. So (a, b, c) > (1, 2, 3)should be rewritten to a=1 and b=2 and c>3
or
a=1 and b>2
or
a>1If you use SQLServer, still lampager/lampager-laravel: Rapid pagination for Laravel may help implementing cursor pagination. |
|
@mpyw probably best to attempt PR's. Merged PR's are never revisited here. |
|
@driesvints Yes I know, I actually agree with the PR method. Just writing reference information for minor users. |
Support for "row values" is mostly useful when implementing pagination with keysets aka seek method.
Well known pagination with offset/limit has almost linearly bad performance characteristics with every "page" turned. They can't make use of an index to efficiently jump to the result page and thus have to always read from the beginning.
An alternative way is to define predicates to jump to the desired page which can make use of indices. Characteristics of such paginations are:
This PR implements the low-level building block. Example:
->where(…)->orderBy(…)->offset(100)->limit(10)->where(…)->whereRowValues(['last_update', 'ticket_numbner'], '<', ['2017-12-15 23:00:00', 123])->orderBy(…)->limit(10)(iff the business logic of your application allows it)
The benefits/performance characteristics as well as in-depth examples how and why this works are well described at:
Note
->whereRaw()but after reading http://use-the-index-luke.com/no-offset I figured a direct support for this could be welcomeRowValuesmay not be obvious to related to this "keyset pagination" or "seek method". But OTOH this seems to be the term describing this particular syntax (I'm not an expert on this topic), that's why I choose it instead of->whereSeekor->whereKeysetPagination…This may be left open for the future to directly support this via something like
->paginateKeyset()(just thinking out loud)