ydb-platform / ydb-platform/ydb-java-dialects

[jooq] Add DELETE LIMIT emulation via subquery

Open
#217 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
78
Forks
24
Avg merge
8h 19m
Merged PRs (30d)
15

Description

Problem

When using jOOQ's delete(...).limit(n) with the YDB dialect, the generated SQL is:

DELETE FROM `test` LIMIT $jp1

YQL does not support the LIMIT clause on DELETE statements, so this fails with:

Status{code = GENERIC_ERROR(code=400080), issues = [19:3 - 19:3: extraneous input 'limit' expecting {<EOF>, ';'} (S_ERROR)]}

Reproducer

dsl.delete(TEST).limit(10).execute();
// → DELETE FROM `test` LIMIT $jp1  (GENERIC_ERROR)

Expected behavior

The dialect should emulate DELETE LIMIT n by rewriting it as a subquery using the table's primary key:

DELETE FROM `test` WHERE `key` IN (SELECT `key` FROM `test` LIMIT $jp1)

For composite PKs:

DELETE FROM `episodes`
WHERE (`series_id`, `season_id`, `episode_id`) IN (
  SELECT `series_id`, `season_id`, `episode_id`
  FROM `episodes`
  LIMIT $jp1
)

Implementation notes

jOOQ already has a similar emulation tracked in jOOQ/jOOQ#7839 for other databases that lack native DELETE LIMIT support.

For this dialect the natural place is a custom DeleteQuery implementation in org.jooq.impl (mirroring the existing UpsertReplaceQueryImpl pattern), wired in via YdbDSLContextImpl.deleteQuery(). The PK fields are available through table.getPrimaryKey().getFields() when the table is code-generated. When PK is unavailable the implementation should throw a descriptive error.

Environment

  • jooq-ydb-dialect version: 1.2.1
  • jOOQ: 3.19.x
  • YQL does not support DELETE ... LIMIT (confirmed)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with YdbDSLContextImpl.deleteQuery() and the existing UpsertReplaceQueryImpl pattern in org.jooq.impl, then run the provided delete(...).limit(n) reproducer. Use table.getPrimaryKey().getFields() to cover single and composite keys, and verify the generated YQL uses a key subquery; missing primary keys should produce a descriptive error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.