Avoid fetching full entity rows in lookupEntityVersions#5038
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the JDBC persistence hot path for cache validation by making lookupEntityVersions query only the version-related columns, avoiding fetching large JSON properties / internal_properties blobs when they aren’t needed.
Changes:
- Added a
ModelEntity.VERSION_COLUMNSprojection and aQueryGeneratorhelper to generate a version-onlySELECT. - Updated
JdbcBasePersistenceImpl.lookupEntityVersionsto use the new version-only query plus a dedicatedEntityVersionConverter. - Added
QueryGeneratorTestcoverage for the new version-only query generation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| persistence/relational-jdbc/src/test/java/org/apache/polaris/persistence/relational/jdbc/QueryGeneratorTest.java | Adds unit tests asserting the new version-only select query and that property columns aren’t selected. |
| persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/QueryGenerator.java | Refactors entity-id select generation and introduces generateSelectQueryWithEntityIdsVersionOnly. |
| persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/models/ModelEntity.java | Introduces VERSION_COLUMNS as a minimal column projection for version checks. |
| persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/models/EntityVersionConverter.java | Adds a read-only ResultSet converter for the version-only projection. |
| persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcBasePersistenceImpl.java | Switches lookupEntityVersions to the new lightweight query + converter. |
Comment on lines
494
to
+501
| @Override | ||
| public List<PolarisChangeTrackingVersions> lookupEntityVersions( | ||
| @NonNull PolarisCallContext callCtx, List<PolarisEntityId> entityIds) { | ||
| Map<PolarisEntityId, ModelEntity> idToEntityMap = | ||
| lookupEntities(callCtx, entityIds).stream() | ||
| .filter(Objects::nonNull) | ||
| .collect( | ||
| Collectors.toMap( | ||
| entry -> new PolarisEntityId(entry.getCatalogId(), entry.getId()), | ||
| entry -> ModelEntity.fromEntity(entry, schemaVersion))); | ||
| return entityIds.stream() | ||
| .map( | ||
| entityId -> { | ||
| ModelEntity entity = idToEntityMap.getOrDefault(entityId, null); | ||
| return entity == null | ||
| ? null | ||
| : new PolarisChangeTrackingVersions( | ||
| entity.getEntityVersion(), entity.getGrantRecordsVersion()); | ||
| }) | ||
| .collect(Collectors.toList()); | ||
| if (entityIds == null || entityIds.isEmpty()) { | ||
| return new ArrayList<>(); | ||
| } | ||
| PreparedQuery query = | ||
| QueryGenerator.generateSelectQueryWithEntityIdsVersionOnly(realmId, entityIds); |
ayushtkn
force-pushed
the
lookupEntityVersions
branch
from
July 11, 2026 06:30
e1f5080 to
aed7825
Compare
ayushtkn
force-pushed
the
lookupEntityVersions
branch
from
July 11, 2026 06:59
aed7825 to
85d653f
Compare
nandorKollar
approved these changes
Jul 14, 2026
Contributor
|
Planning to merge on Jul 15 unless reviewers raise concerns. |
flyingImer
reviewed
Jul 16, 2026
Comment on lines
636
to
637
| ModelEntity.getAllColumnNames(schemaVersion), ModelEntity.TABLE_NAME, params)); | ||
| return b == null ? 0 : b.getGrantRecordsVersion(); |
Collaborator
There was a problem hiding this comment.
IIUC, this does the entity load just to read the grant records version. Wonder if this should or can be remediated with the same treatment?
Collaborator
There was a problem hiding this comment.
referenced my pr below
This was referenced Jul 16, 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.
lookupEntityVersionsis called byResolver.bulkValidateon every JDBC-backed request that uses the entity cache, but it previously routed throughlookupEntitiesand fetched all entity columns—including large JSONpropertiesandinternal_propertiesblobs—just to readentity_versionandgrant_records_version. This change adds a narrowVERSION_COLUMNSprojection (id,catalog_id,entity_version,grant_records_version), a sharedQueryGeneratorhelper, and anEntityVersionConvertersolookupEntityVersionsissues a single lightweightSELECTinstead.Checklist
CHANGELOG.md(if needed)site/content/in-dev/unreleased(if needed)