Skip to content

Support DBs without LATERAL JOINS - #917

Merged
milessabin merged 1 commit into
typelevel:mainfrom
phdoerfler:topic/no-lateral-join-hooks
Aug 29, 2026
Merged

Support DBs without LATERAL JOINS#917
milessabin merged 1 commit into
typelevel:mainfrom
phdoerfler:topic/no-lateral-join-hooks

Conversation

@phdoerfler

@phdoerfler phdoerfler commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

This PR makes support for LATERAL JOINS optional. This has been extracted out of the SQLite branch since it can stand on its own. This way it might be easier to review. It moves the two decisions a backend without lateral joins has to make out of sql-core and behind abstract hooks.

Two abstract members on SqlMappingLike

normalizeOffsetLimit says how a select's OFFSET/LIMIT is fixed up before it is rendered, and unionBranchToFragment how one branch of a union is rendered. defaultOffsetForSubquery is gone, since the first of those covers what it did.

I decided to leave those two abstract and not provide a default implementation. I am not aware of any implementation of SqlMappingLike outside of this repo. And if there is, all it has to do is implement two small methods.

Every backend in this repo still has lateral joins, so supportsLateralJoin is true everywhere and the branches that do without one are not exercised until #864 adds SQLite and #866 adds H2.

SQL Server's generated SQL changes

SQL Server now emits OFFSET 0 ROWS after an ORDER BY at the root of a query, where before it did so only in subqueries. The rows and their order are unchanged; only the text is. Keeping the old text would have meant passing a "subquery or root?" boolean through the new hook, so I took the text change.

This was referenced Aug 28, 2026
@phdoerfler phdoerfler changed the title Move offset/limit and union-branch rendering behind backend hooks Support DBs without LATERAL JOINS Aug 28, 2026
@phdoerfler
phdoerfler requested a review from milessabin August 28, 2026 20:44
@phdoerfler
phdoerfler force-pushed the topic/no-lateral-join-hooks branch from b9d0196 to b323089 Compare August 28, 2026 22:25
SQL Server emits OFFSET 0 ROWS after a root ORDER BY now, where it only did so in subqueries before.
@phdoerfler
phdoerfler force-pushed the topic/no-lateral-join-hooks branch from b323089 to 88adfdd Compare August 29, 2026 08:32

@milessabin milessabin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@milessabin
milessabin merged commit 87f9474 into typelevel:main Aug 29, 2026
13 checks passed
@phdoerfler
phdoerfler deleted the topic/no-lateral-join-hooks branch August 29, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants