-
Notifications
You must be signed in to change notification settings - Fork 299
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
Update columns' order in TokenIndexEntity multi-column index #2729
Conversation
Running query SELECT a.*
FROM ResourceEntity a
WHERE a.resourceType = 'Task'
AND a.resourceUuid IN (SELECT resourceUuid
FROM TokenIndexEntity
WHERE resourceType = 'Task'
AND index_name = 'status'
AND (
(index_value = 'ready' AND IFNULL(index_system, '') = 'http://hl7.org/fhir/task-status') OR
(index_value = 'in-progress' AND
IFNULL(index_system, '') = 'http://hl7.org/fhir/task-status'))); in a database with
took |
hey what if you change this line: android-fhir/engine/src/main/java/com/google/android/fhir/search/filter/TokenParamFilterCriterion.kt Line 93 in b59acf2
to:
wouldn't that save you from changing the index? also - i'm not sure if we should allow empty system at all? shouldn't we always look for a code system? so that even if it's empty we should be checking taht it's an empty code system. that way, even if your query doesn't include a code system we'll still be hitting the index. |
Changing that line the query, would probably look like this SELECT a.*
FROM ResourceEntity a
WHERE a.resourceType = 'Task'
AND a.resourceUuid IN (SELECT resourceUuid
FROM TokenIndexEntity
WHERE resourceType = 'Task'
AND index_name = 'status'
AND (
(IFNULL(index_system, '') = 'http://hl7.org/fhir/task-status' AND index_value = 'ready') OR
(IFNULL(index_system, '') = 'http://hl7.org/fhir/task-status' AND index_value = 'in-progress'))); whereby the query plan still doesn't change
The order of columns in the query doesn't need to match the way they've been defined in the index. I think it checks that leftmost column of an index exists within the WHERE constraints, and if there is an conflict it checks for the next column in the index...that is until, it either encounters a inequality comparison, a missing column constraint, or a column with function evaluation unless the indexed column is a function evaluation. To still have the Index(value = ["index_value", "resourceType", "index_name", "IFNULL(index_system, '')" "resourceUuid"]), For queries that wouldn't have I think it should still be okay to search without the system in the query. Assuming for the above query, it should still be okay to search SELECT a.*
FROM ResourceEntity a
WHERE a.resourceType = 'Task'
AND a.resourceUuid IN (SELECT resourceUuid
FROM TokenIndexEntity
WHERE resourceType = 'Task'
AND index_name = 'status'
AND (index_value = 'ready' OR index_value = 'in-progress')); |
engine/src/main/java/com/google/android/fhir/db/impl/entities/TokenIndexEntity.kt
Outdated
Show resolved
Hide resolved
to cover for usecases that may require searching using index_sytem without index_value
IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).
Description
Updates the order of columns in the multi-column index used in the
TokenIndexEntity
entity table to haveindex_value
as the leftmost column.Also removes the
index_system
column from the index since it would never get used because the queries generated use the IFNULL statement that forces evaluation from the actual rows.With an example query
Previous query plan, was
The updated query plan would be
Type
Feature
Checklist
./gradlew spotlessApply
and./gradlew spotlessCheck
to check my code follows the style guide of this project../gradlew check
and./gradlew connectedCheck
to test my changes locally.