From 4443fa6eedcac6cf2e3268963025ff16fed2551a Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 10 Mar 2021 09:46:43 +0100 Subject: [PATCH] [jOOQ/jOOQ#11582] Avoid auxiliary derived table in SQLite GENERATE_SERIES emulation --- .../java/org/jooq/impl/SelectQueryImpl.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java index 1d439fba11..2321632594 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java @@ -1650,10 +1650,10 @@ final class SelectQueryImpl extends AbstractResultQuery imp // ---------------------------------------------- // DISTINCT seems irrelevant here (to be proven) - c.visit(getLimit().withTies() - ? DSL.rank().over(orderBy(getNonEmptyOrderBy(c.configuration()))) - : distinct + c.visit(distinct ? DSL.denseRank().over(orderBy(getNonEmptyOrderByForDistinct(c.configuration()))) + : getLimit().withTies() + ? DSL.rank().over(orderBy(getNonEmptyOrderBy(c.configuration()))) : DSL.rowNumber().over(orderBy(getNonEmptyOrderBy(c.configuration()))) ); @@ -2914,12 +2914,14 @@ final class SelectQueryImpl extends AbstractResultQuery imp derivedTableRequired |= derivedTableRequired - // [#3579] [#6431] [#7222] Some databases don't support nested set operations at all - // because they do not allow wrapping set op subqueries in parentheses - || NO_SUPPORT_UNION_PARENTHESES.contains(ctx.dialect()) + // [#3579] [#6431] [#7222] [#11582] + // Some databases don't support nested set operations at all because + // they do not allow wrapping set op subqueries in parentheses + || parensRequired && NO_SUPPORT_UNION_PARENTHESES.contains(ctx.dialect()) - // [#3579] [#6431] [#7222] Nested set operations aren't supported, but parenthesised - // set op subqueries are. + // [#3579] [#6431] [#7222] + // Nested set operations aren't supported, but parenthesised set op + // subqueries are. || (TRUE.equals(ctx.data(DATA_NESTED_SET_OPERATIONS)) && UNION_PARENTHESIS.contains(ctx.dialect())) // [#2995] Ambiguity may need to be resolved when parentheses could mean both: