Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Date/DateTime and Token indexes to speed up Search #2063

Merged
merged 5 commits into from
Jul 4, 2023
Merged

Fix Date/DateTime and Token indexes to speed up Search #2063

merged 5 commits into from
Jul 4, 2023

Conversation

omarismail94
Copy link
Contributor

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #2040

Description
Clear and concise code change description.

In the Search API, we perform a LEFT JOIN when sorting:

LEFT JOIN ${sortTableName.tableName} $tableAlias
      ON a.resourceType = $tableAlias.resourceType AND a.resourceUuid = $tableAlias.resourceUuid AND $tableAlias.index_name = ?

this join uses the resourceType, resourceUuid and index_name columns. To speed this up, we should create a composite index made up of these 3 columns. We also do the same for the TokenIndexTable

TESTED:
Downloaded 7000 households. Opened App Inspector and ran query generated. Returned results almost instantaneously as opposed to many seconds

Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?

Type
Choose one: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)

Checklist

  • I have read and acknowledged the Code of conduct.
  • I have read the Contributing page.
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA.
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach.
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project.
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally.
  • I have built and run the demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

@omarismail94 omarismail94 marked this pull request as ready for review July 4, 2023 14:30
@omarismail94 omarismail94 requested review from a team and santosh-pingle as code owners July 4, 2023 14:30
@omarismail94 omarismail94 requested a review from aditya-07 July 4, 2023 14:30
@omarismail94 omarismail94 enabled auto-merge (squash) July 4, 2023 15:23
@omarismail94 omarismail94 disabled auto-merge July 4, 2023 15:37
@omarismail94 omarismail94 enabled auto-merge (squash) July 4, 2023 16:22
@omarismail94 omarismail94 merged commit 9dbae14 into google:master Jul 4, 2023
@omarismail94 omarismail94 deleted the indexy branch July 4, 2023 17:18
joiskash pushed a commit to DigitalHealthIntegration/android-fhir that referenced this pull request Jul 17, 2023
* add indexes to speed up left joins

* add index_from to get convering indexes

* add resourceuuid to tokenindex to make entire query convering

* add commas, and comments explaining what a covering index is

* add reference to GH Issue
# Conflicts:
#	engine/src/main/java/com/google/android/fhir/db/impl/DatabaseImpl.kt
#	engine/src/main/java/com/google/android/fhir/db/impl/ResourceDatabase.kt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Search method takes more time when load 7k household list
2 participants