Fix JDBC hasChildren fetching all rows and columns#5066
Open
ayushtkn wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes JdbcBasePersistenceImpl.hasChildren in the relational JDBC persistence layer to avoid selecting wide entity rows (including large JSON blob columns) when only row existence is needed.
Changes:
- Add
QueryGenerator.generateExistsQuery(...)to emitSELECT 1 ... LIMIT 1existence checks. - Update
JdbcBasePersistenceImpl.hasChildrento use the new existence query instead of a full entity-columnSELECT. - Add/extend tests to verify
LIMIT 1usage and thatproperties/internal_propertiesare not fetched.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/QueryGenerator.java | Adds an existence-query generator (SELECT 1 ... LIMIT 1). |
| persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java | Switches hasChildren to the existence-query path to avoid fetching wide rows. |
| persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/QueryGeneratorTest.java | Adds assertions ensuring the existence query uses SELECT 1 + LIMIT 1 and avoids blob columns. |
| persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImplTest.java | Adds an integration-style test validating hasChildren issues a limited existence query (no blob columns). |
Comment on lines
+383
to
+388
| public static PreparedQuery generateExistsQuery( | ||
| @NonNull String tableName, @NonNull Map<String, Object> whereClause) { | ||
| QueryFragment where = generateWhereClause(whereClause.keySet(), whereClause, Map.of()); | ||
| String sql = | ||
| "SELECT 1 FROM " + getFullyQualifiedTableName(tableName) + where.sql() + " LIMIT 1"; | ||
| return new PreparedQuery(sql, where.parameters()); |
Member
Author
There was a problem hiding this comment.
hmm, as of now it had one caller only, but fair enough, I have changed it & added a test as well around it
ayushtkn
force-pushed
the
hasChildren
branch
2 times, most recently
from
July 15, 2026 18:56
b1c7a3f to
606a6d7
Compare
adutra
previously approved these changes
Jul 17, 2026
Contributor
|
@ayushtkn could you please fix the merge conflict? Thanks! |
adutra
approved these changes
Jul 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JdbcBasePersistenceImpl.hasChildrenwas issuing aSELECTof all15+entity columns—including large JSONpropertiesandinternal_propertiesblobs—with noLIMIT, just to answer whether any children exist.Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)