jerryshao commented on code in PR #14967:
URL: https://github.com/apache/gravitino/pull/14967#discussion_r4582457040
##########
core/src/main/java/org/apache/gravitino/domain/DomainMembershipResolver.java:
##########
@@ -89,60 +102,192 @@ DomainMember[] listMembers(
|| filter.domains().contains(d.name()))
.collect(Collectors.toList());
- // Expand explicit tag assignments into recorded leaf objects that may
inherit the tag.
- Set<MetadataObject> candidates = new LinkedHashSet<>();
+ List<DomainMember> members =
+ filter.expand()
+ ? listExpandedMembers(metalake, queriedDomain, scopeDomains,
selectedDomains, filter)
+ : listDirectMembers(metalake, queriedDomain, scopeDomains,
selectedDomains, filter);
+
+ members.sort(
+ Comparator.comparing((DomainMember m) -> m.object().type().name())
+ .thenComparing(m -> m.object().fullName()));
+ return members.toArray(new DomainMember[0]);
+ }
+
+ /**
+ * Lists the objects that carry a backing tag themselves, including catalogs
and schemas, without
+ * expanding them or resolving effective tags.
+ */
+ private List<DomainMember> listDirectMembers(
+ String metalake,
+ DomainEntity queriedDomain,
+ List<DomainEntity> scopeDomains,
+ List<DomainEntity> selectedDomains,
+ DomainMemberFilter filter) {
+ Set<Long> selectedIds =
+
selectedDomains.stream().map(DomainEntity::id).collect(Collectors.toSet());
+ boolean needsOtherBindings =
+ scopeDomains.stream()
+ .anyMatch(d -> d.backingTagId() != null &&
!selectedIds.contains(d.id()));
+ // A selective name filter can discard most candidates after name
resolution. In that case
+ // only fetch additional paths for the remaining objects. Bound the IN
list for large scopes.
+ boolean joinPaths =
+ needsOtherBindings
+ && !selectedIds.isEmpty()
+ && selectedIds.size() <= MEMBERSHIP_LOOKUP_BATCH_SIZE
+ && !filter.nameContains().isPresent();
Review Comment:
Thanks for the reproducer. Fixed in a22d6b1332. When every first-pass name
matches, the resolver now uses the same batch comparison as an unfiltered
request. Partial matches still use object-ID lookups because the semijoin can
only restrict by selected domain. Zero matches skip the second lookup.
I reproduced your setup with 10,000 tables in cat.sales assigned to the
child and one also assigned to the parent. With the schema-wide name filter,
SELECTs dropped from 22 to 3 on both MySQL 8.0.46 and PostgreSQL 13.23,
matching the unfiltered count. Median resolver time over 14 measured runs per
configuration fell from 179.9 to 57.3 ms on MySQL and from 144.5 to 55.5 ms on
PostgreSQL. Filters matching 501, 1, and 0 tables still issued 4, 3, and 2
SELECTs respectively. I checked each result against the expected object names
and ordered relations, including both paths for the overlapping table. The
regression test also covers a partial match above the 500-ID batch boundary.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]