Skip to content

Add query response field selection/filtering - #7039

Open
clockard wants to merge 2 commits into
masterfrom
query-response-fields
Open

clockard wants to merge 2 commits into
masterfrom
query-response-fields

Conversation

@clockard

Copy link
Copy Markdown
Contributor

What does this PR do?

This PR is a possible way to reduce query times especially for large queries with thumbnails.

Adds optional Solr field-list restriction to catalog queries so callers can
request only the attributes they need, greatly reducing Solr fetch time and
response size for large result sets (e.g. excluding thumbnails).

  • New query request properties includedFields / excludedFields (lists of attribute names, * wildcards supported; only one may be given). They are read from the top-level request properties or from the nested unchecked-properties map used by endpoints such as ddf-jsonrpc.
  • Disabled by default; enable with solr.query.fieldList.enabled=true.
  • id, title and the metacard type key are always returned. Additional always-returned attributes are set with solr.query.fieldList.requiredFields (e.g. security.*,validation-errors,validation-warnings,metacard-tags, metacard.owner) so post-query security/validity plugins keep working.
  • Exclusions are sent to Solr as an explicit inclusion list (Solr fl has no exclusion syntax), limited to base attribute fields; derived index-only fields (_tokenized, _phonetics, _sort, ...) are never requested.
  • The serialized metacard type object (~11.5 KB/doc) is no longer fetched for field-restricted queries. Types missing from the resolver cache are fetched once per type key via getById and cached (DynamicSchemaResolver.cacheMetacardType / isMetacardTypeCached).
  • Metacards from field-restricted queries are marked metacard.partial=true (the attribute is added to a cached extension of the metacard type so transformers serialize it).
  • New PartialMetacardIngestPlugin registers metacard.partial in the AttributeRegistry and rejects creates/updates of partial metacards, which would otherwise silently drop every attribute that was not returned.

Query performance improvements

Removes two per-result costs from the post-query phase and fixes ambiguous
query metric keys.

  • QueryOperations.injectAttributes: snapshot the attribute injector list once per response instead of iterating the live blueprint reference-list for every result. Aries DynamicCollection.iterator() walks a list of weak references to every iterator created since the last GC, so per-result iteration made attribute injection slow and GC-timing dependent.
  • SecurityManagerImpl: hand Shiro a CopyOnWriteArrayList of realms, kept in sync through blueprint bind/unbind (addRealm/removeRealm), instead of the live reference-list. Shiro iterates realms on every permission check, so FilterPlugin paid the same per-result cost.
  • Query metrics: pre-query access plugins are now recorded as qm.prequeryaccess.<Plugin>.elapsed (previously mislabeled qm.postquery.*), and the post-query pass of pre-authorization plugins as qm.postauthorization.<Plugin>.elapsed (previously overwrote the pre-query

Results: 1000-result queries via JSON-RPC (median ms)

Stage Request Client total Server request Solr query Post-query Response size
Baseline (no field filtering, no fixes) all fields 487.3 349.5 141.4 183.7 20.3 MB
Field filtering: exclude thumbnail (type object still fetched) excludedFields: [thumbnail] 358.4 300.5 82.5 – 3.2 MB
+ metacard type object no longer fetched excludedFields: [thumbnail] 281.6 232.0 19.1 200.0 3.2 MB
+ Fix 1: injector list snapshot excludedFields: [thumbnail] 208.9 154.5 19.0 120.0 3.2 MB
+ Fix 2: copy-on-write realm list excludedFields: [thumbnail] 136.9 83.0 18.5 50.2 3.2 MB
Total improvement, filtered (baseline → all changes) −72% −76% −87% −73% −84%
Unfiltered query with fixes 1 + 2 only all fields 433.5 269.5 143.0 103.2 20.3 MB
Improvement, unfiltered (perf commit alone) −11% −23% +1% −44% –

How these numbers were produced:

  • Setup: the DDF Docker container with single-node SolrCloud, 1000 seeded metacards (85% with a 15.7 KB thumbnail).
  • Most rows: 6 interleaved rounds × 15 runs per condition.
  • The "type object still fetched" row: a single 10-run back-to-back run from before the JSON-RPC metrics patch, which is why it has no post-query figure.
  • Variance: after both fixes, the filtered server time is also much more predictable. Its interquartile range went from 177–279 ms to 83–84 ms.

Who is reviewing it?

@jaymcnallie
@vinamartin
@derekwilhelm

Select relevant component teams:

Ask 2 committers to review/merge the PR and tag them here.

How should this be tested?

Any background context you want to provide?

What are the relevant tickets?

Fixes: #____

Screenshots

Checklist:

  • Documentation Updated
  • Update / Add Threat Dragon models
  • Update / Add Unit Tests
  • Update / Add Integration Tests

Notes on Review Process

Please see Notes on Review Process for further guidance on requirements for merging and abbreviated reviews.

Review Comment Legend:

  • ✏️ (Pencil) This comment is a nitpick or style suggestion, no action required for approval. This comment should provide a suggestion either as an in line code snippet or a gist.
  • ❓ (Question Mark) This comment is to gain a clearer understanding of design or code choices, clarification is required but action may not be necessary for approval.
  • ❗ (Exclamation Mark) This comment is critical and requires clarification or action before approval.

@clockard
clockard requested a review from stustison as a code owner November 24, 2026 03:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant