diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java index c4e4af16ed..2c0a61899a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java @@ -2891,7 +2891,7 @@ final class SelectQueryImpl extends AbstractResultQuery imp context.formatSeparator() .visit(K_WHERE) .sql(' ') - .qualify(false, c -> c.visit(getSeekCondition(context))); + .qualify(false, c -> c.visit(getSeekCondition(context, false))); } } @@ -3688,7 +3688,7 @@ final class SelectQueryImpl extends AbstractResultQuery imp } private final boolean applySeekOnDerivedTable() { - return !getSeek().isEmpty() && !getOrderBy().isEmpty() && !unionOp.isEmpty(); + return !getSeek(false).isEmpty() && !getOrderBy(false).isEmpty() && !unionOp.isEmpty(); } private final boolean wrapQueryExpressionBodyInDerivedTable(Context ctx, boolean hasAlternativeFields) { @@ -4594,8 +4594,8 @@ final class SelectQueryImpl extends AbstractResultQuery imp // - There are no unions (union is nested in derived table // and SEEK predicate is applied outside). See [#7459] // [#15820] We're not grouping - if (!isGrouping() && !getOrderBy().isEmpty() && !getSeek().isEmpty() && unionOp.isEmpty()) - where0.addConditions(getSeekCondition(ctx)); + if (!isGrouping() && !getOrderBy(true).isEmpty() && !getSeek(true).isEmpty()) + where0.addConditions(getSeekCondition(ctx, true)); addPathConditions(ctx, where0, tablelist); @@ -4660,10 +4660,10 @@ final class SelectQueryImpl extends AbstractResultQuery imp } @SuppressWarnings({ "rawtypes", "unchecked" }) - final Condition getSeekCondition(Context ctx) { - SortFieldList o = getOrderBy(); + final Condition getSeekCondition(Context ctx, boolean localSeek) { + SortFieldList o = getOrderBy(localSeek); Condition c = null; - QueryPartList> s = getSeek(); + QueryPartList> s = getSeek(localSeek); // If we have uniform sorting, more efficient row value expression // predicates can be applied, which can be optimised in some databases. @@ -4821,8 +4821,8 @@ final class SelectQueryImpl extends AbstractResultQuery imp // - There are no unions (union is nested in derived table // and SEEK predicate is applied outside). See [#7459] // [#15820] We're not grouping - if (isGrouping() && !getOrderBy().isEmpty() && !getSeek().isEmpty() && unionOp.isEmpty()) - result.addConditions(getSeekCondition(ctx)); + if (isGrouping() && !getOrderBy(true).isEmpty() && !getSeek(true).isEmpty()) + result.addConditions(getSeekCondition(ctx, true)); if (NO_SUPPORT_LIMIT_ZERO.contains(ctx.dialect()) && limit.limitZero() && isGrouping()) result.addConditions(falseCondition()); @@ -4835,11 +4835,19 @@ final class SelectQueryImpl extends AbstractResultQuery imp } final SortFieldList getOrderBy() { - return (unionOp.size() == 0) ? orderBy : unionOrderBy; + return getOrderBy(unionOp.size() == 0); + } + + final SortFieldList getOrderBy(boolean localOrderBy) { + return localOrderBy ? orderBy : unionOrderBy; } final QueryPartList> getSeek() { - return (unionOp.size() == 0) ? seek : unionSeek; + return getSeek(unionOp.size() == 0); + } + + final QueryPartList> getSeek(boolean localSeek) { + return localSeek ? seek : unionSeek; } final Limit getLimit() {