Skip to content

Implement query.exists() via select exists(...)#3824

Merged
rbygrave merged 2 commits into
masterfrom
feature/3584-exists
Jul 2, 2026
Merged

Implement query.exists() via select exists(...)#3824
rbygrave merged 2 commits into
masterfrom
feature/3584-exists

Conversation

@rbygrave

@rbygrave rbygrave commented Jul 2, 2026

Copy link
Copy Markdown
Member

Previously query.exists() was implemented by running a findIds() limited to 1 row and checking whether the list was empty. This PR replaces that with a dedicated select exists(select 1 ...) execution path.

Changes:

• CQueryExists — new query executor, analogous to CQueryCount, that runs select exists(...) and returns the boolean result directly from the JDBC ResultSet • CQueryBuilder.buildExistsQuery() — builds select exists(select 1 ...) SQL, reusing the query plan cache on repeat calls • CQueryEngine.findExists() / DefaultOrmQueryEngine / OrmQueryEngine interface — wire the new executor through the standard query engine stack, including SQL logging, summary logging, and query cache put • DefaultServer.exists() — delegate to request.findExists() instead of findIds()

Tests added to TestQueryExists:

• testExistsBoolean_returnsFalse — verifies false is returned when no rows match • testExistsBoolean_withJoin — exercises the join SQL path in buildExistsQuery; also checks false when the join yields no match • testExistsBoolean_queryPlanReuse — runs the same query twice and asserts the generated SQL is identical, confirming the plan cache is hit on the second call

Previously query.exists() was implemented by running a findIds() limited to 1 row and checking whether the list was empty. This PR replaces that with a dedicated select exists(select 1 ...) execution path.

## Changes:

• CQueryExists — new query executor, analogous to CQueryCount, that runs select exists(...) and returns the boolean result directly from the JDBC ResultSet
• CQueryBuilder.buildExistsQuery() — builds select exists(select 1 ...) SQL, reusing the query plan cache on repeat calls
• CQueryEngine.findExists() / DefaultOrmQueryEngine / OrmQueryEngine interface — wire the new executor through the standard query engine stack, including SQL logging, summary logging, and query cache put
• DefaultServer.exists() — delegate to request.findExists() instead of findIds()

## Tests added to TestQueryExists:

• testExistsBoolean_returnsFalse — verifies false is returned when no rows match
• testExistsBoolean_withJoin — exercises the join SQL path in buildExistsQuery; also checks false when the join yields no match
• testExistsBoolean_queryPlanReuse — runs the same query twice and asserts the generated SQL is identical, confirming the plan cache is hit on the second call
@rbygrave rbygrave self-assigned this Jul 2, 2026
@rbygrave rbygrave linked an issue Jul 2, 2026 that may be closed by this pull request
@rbygrave rbygrave added this to the 18.2.0 milestone Jul 2, 2026
@rbygrave rbygrave merged commit 864aff6 into master Jul 2, 2026
1 check passed
@rbygrave rbygrave deleted the feature/3584-exists branch July 2, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH] Use "exists" PostgreSQL keyword for "exists()" expression method

2 participants