diff --git a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java index f449f888a0..6553ec8077 100644 --- a/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java +++ b/jOOQ/src/main/java/org/jooq/impl/AbstractTable.java @@ -52,11 +52,11 @@ import static org.jooq.JoinType.NATURAL_RIGHT_OUTER_JOIN; import static org.jooq.JoinType.OUTER_APPLY; import static org.jooq.JoinType.RIGHT_OUTER_JOIN; import static org.jooq.JoinType.STRAIGHT_JOIN; +import static org.jooq.impl.DSL.and; import static org.jooq.impl.DSL.condition; import static org.jooq.impl.DSL.exists; // ... import static org.jooq.impl.DSL.notExists; -import static org.jooq.impl.DSL.selectFrom; import static org.jooq.impl.DSL.sql; import static org.jooq.impl.DSL.table; import static org.jooq.impl.DSL.val; @@ -1110,17 +1110,17 @@ abstract class AbstractTable extends AbstractNamed implements @Override public /* non-final */ Table where(Condition condition) { - return selectFrom(this).where(condition).asTable(this); + return new InlineDerivedTable<>(this, condition); } @Override public /* non-final */ Table where(Condition... conditions) { - return selectFrom(this).where(conditions).asTable(this); + return where(and(conditions)); } @Override public /* non-final */ Table where(Collection conditions) { - return selectFrom(this).where(conditions).asTable(this); + return where(and(conditions)); } @Override diff --git a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java index c8962a7517..eabe5ef8b8 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/SelectQueryImpl.java @@ -2882,21 +2882,19 @@ final class SelectQueryImpl extends AbstractResultQuery imp } final ConditionProviderImpl getWhere() { - - // Do not apply SEEK predicates in the WHERE clause, if: - // - There is no ORDER BY clause (SEEK is non-deterministic) - // - There is no SEEK clause (obvious case) - // - There are unions (union is nested in derived table - // and SEEK predicate is applied outside). See [#7459] - if (getOrderBy().isEmpty() || getSeek().isEmpty() || unionOp.size() > 0) - return condition; - ConditionProviderImpl result = new ConditionProviderImpl(); if (condition.hasWhere()) result.addConditions(condition.getWhere()); - result.addConditions(getSeekCondition()); + // Apply SEEK predicates in the WHERE clause only if: + // - There is an ORDER BY clause (SEEK is non-deterministic) + // - There is a SEEK clause (obvious case) + // - There are no unions (union is nested in derived table + // and SEEK predicate is applied outside). See [#7459] + if (!getOrderBy().isEmpty() && !getSeek().isEmpty() && unionOp.isEmpty()) + result.addConditions(getSeekCondition()); + return result; }