Skip to content

feat(search): add skipCount parameter to skip expensive COUNT queries#8325

Merged
carlesarnal merged 3 commits into
mainfrom
issue-4723
Jun 23, 2026
Merged

feat(search): add skipCount parameter to skip expensive COUNT queries#8325
carlesarnal merged 3 commits into
mainfrom
issue-4723

Conversation

@carlesarnal

Copy link
Copy Markdown
Member

Summary

Adds an optional skipCount boolean query parameter to v3 search endpoints, allowing callers to skip the expensive COUNT(*) query when they don't need total pagination count. When skipCount=true, the response returns count=0 instead of executing the count query. Fixes #4723

Root Cause

The COUNT(*) query in searchArtifacts() and searchVersions() accounts for ~10% of all queries but takes ~95% of database time on large datasets. Callers who only need search results (not the total count for pagination) pay this cost unnecessarily with no way to opt out.

Changes

  • OpenAPI spec (common/src/main/resources/META-INF/openapi.json): Added skipCount boolean query parameter (default false) to 6 endpoints: searchArtifacts, searchArtifactsByContent, searchVersions, searchVersionsByContent, listArtifactsInGroup, listArtifactVersions
  • Storage interface (RegistryStorage.java): Added boolean skipCount parameter to searchArtifacts() and searchVersions()
  • SQL implementation (SqlSearchRepository.java): Conditionally skips COUNT query construction and execution when skipCount=true
  • Elasticsearch (ElasticsearchSearchService.java): Disables trackTotalHits when skipCount=true
  • Decorators/delegates: Updated ReadOnlyDelegatingStorage, ElasticsearchSearchDecorator, AbstractPollingRegistryStorage, AbstractSqlRegistryStorage to thread the parameter through
  • v3 REST layer (SearchResourceImpl.java, GroupsResourceImpl.java): Updated method signatures to accept and pass the new parameter
  • v2/ccompat/internal callers: Updated to pass false (preserving existing behavior) in SearchResourceImpl (v2), GroupsResourceImpl (v2), WellKnownResourceImpl, IcebergApiResourceImpl, SubjectsResourceImpl, SchemasResourceImpl
  • Tests: Updated AbstractRegistryStorageTest, RegistryStoragePerformanceTest, ReadOnlyRegistryStorageTest, TestInMemoryRegistryStorage

Test plan

  • Build compiles successfully (./mvnw clean install -DskipTests -pl common,app -am)
  • Checkstyle passes (./mvnw checkstyle:check -pl app)
  • Existing unit tests updated to pass skipCount=false
  • Integration tests with skipCount=true verifying count=0 in response
  • Integration tests with skipCount=false verifying correct count in response
  • Manual test: GET /search/artifacts?skipCount=true returns results with count=0
  • Storage variant testing (SQL, KafkaSQL)
  • SDK updates (java-sdk, go-sdk, python-sdk, typescript-sdk) — follow-up PR

…ueries

Add an optional `skipCount` boolean query parameter to 6 v3 search
endpoints. When set to true, the storage layer skips the COUNT(*)
query and returns count=0 in the response. This can significantly
improve performance for large datasets when callers don't need total
pagination count.

Affected endpoints:
- GET/POST /search/artifacts
- GET/POST /search/versions
- GET /groups/{groupId}/artifacts
- GET /groups/{groupId}/artifacts/{artifactId}/versions

Fixes #4723
@github-actions github-actions Bot added lifecycle/ready-for-review Ready for review, full tests running lifecycle/waiting-on-maintainer Blocked on maintainer action labels Jun 22, 2026
@github-actions

Copy link
Copy Markdown

PR auto-accepted (trusted author). Full test suite will run.

A maintainer can use /skip-review to skip the review requirement for small changes, or /auto-merge to merge automatically once approved and tested.

@github-actions

Copy link
Copy Markdown

The test suite was cancelled for commit 8fdb5e1. See the workflow run. Use /retry to re-run.

Regenerate Go SDK to include the new skipCount query parameter
added to search endpoints.

Relates to #4723
@github-actions github-actions Bot added the lifecycle/tested Full test suite passed for current HEAD label Jun 22, 2026
@github-actions

github-actions Bot commented Jun 22, 2026

Copy link
Copy Markdown

Verify — ✅ passed (run)

Phase Status
Lint and Validate 🟢
Build 🟢
Unit Tests 🟢
Integration Tests 🟢
Extra Tests 🟢
SDK Verification 🟢
CLI Verification
Operator Tests
Change detection

java: true, ui: false, integration: true, sdk: true, cli: false, go-sdk-gen: true, operator: false, ci: false

@github-actions github-actions Bot added lifecycle/tested Full test suite passed for current HEAD and removed lifecycle/tested Full test suite passed for current HEAD labels Jun 23, 2026
@carlesarnal carlesarnal merged commit 0381bed into main Jun 23, 2026
50 checks passed
@carlesarnal carlesarnal deleted the issue-4723 branch June 23, 2026 08:21
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

lifecycle/ready-for-review Ready for review, full tests running lifecycle/tested Full test suite passed for current HEAD lifecycle/waiting-on-maintainer Blocked on maintainer action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search API count query takes a lot of db time

1 participant