blaze-persistence icon indicating copy to clipboard operation
blaze-persistence copied to clipboard

Simple query with an EXISTS clause and pagination adds an unnecessary inner ID query

Open shopera007 opened this issue 1 year ago • 1 comments

A simple query with an EXISTS clause and pagination adds an unnecessary inner ID query:

final CriteriaBuilder<ProductQuestion> criteriaBuilder = this.criteriaBuilderFactory.create(this.entityManager, ProductQuestion.class);
final CriteriaBuilder<ProductQuestion> criteriaBuilder = criteriaBuilder.from(ProductQuestion.class, PRODUCT_QUESTION_ALIAS);

criteriaBuilder
    .whereExists()
    .from(ProductAnswer.class, PRODUCT_ANSWER_ALIAS)
    .select(joinExpressions(PRODUCT_ANSWER_ALIAS, "id"))
    .where(joinExpressions(PRODUCT_ANSWER_ALIAS, ProductAnswer_.QUESTION, ProductQuestion_.ID))
    .eqExpression(joinExpressions(PRODUCT_QUESTION_ALIAS, ProductQuestion_.ID))
    .end();

Is there any way to force Blaze-Persistence not to use an inner ID query? I'm joining with no collection and just using a simple EXISTS query, which has no impact on pagination.

Could you please help me, thanks

shopera007 avatar Jun 25 '24 12:06 shopera007

Can you please post the generated SQL?

beikov avatar Jul 05 '24 09:07 beikov