Add covering data to res_link index for all tgt->src queries. (#4769)

Add covering data to res_link index for all tgt->src queries.
This commit is contained in:
michaelabuckley 2023-04-24 19:24:11 -04:00 committed by GitHub
parent 08c997c169
commit 20c7a32203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
type: perf
issue: 4769
title: "Chained and reverse-chained searches will be faster in some scenarios.
All required columns are now included in the IDX_RL_TGT_v2 index."

View File

@ -2,7 +2,7 @@
This release has breaking changes.
* The Resource $validate operation no longer returns Precondition Failed 412 when a resource fails validation. It now returns 200 irrespective of the validation outcome as required by the [FHIR Specification for the Resource $validate operation](https://www.hl7.org/fhir/R4/resource-operation-validate.html).
* This release changes database indexing for string and uri SearchParameters. The database migration may take several minutes. These changes will be applied automatically on first startup. To avoid this delay on first startup, run the migration manually.
* This release changes database indexing for string, uri, and reference SearchParameters. The database migration may take several minutes. These changes will be applied automatically on first startup. To avoid this delay on first startup, run the migration manually.
Bulk export behaviour is changing in this release such that Binary resources created as part of the response will now be created in the partition that the bulk export was requested rather than in the DEFAULT partition as was being done previously.

View File

@ -52,7 +52,7 @@ import java.util.stream.Collectors;
import static ca.uhn.fhir.rest.api.Constants.UUID_LENGTH;
@SuppressWarnings({"SqlNoDataSourceInspection", "SpellCheckingInspection"})
@SuppressWarnings({"SqlNoDataSourceInspection", "SpellCheckingInspection", "java:S1192"})
public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
// H2, Derby, MariaDB, and MySql automatically add indexes to foreign keys
@ -303,6 +303,24 @@ public class HapiFhirJpaMigrationTasks extends BaseMigrationTasks<VersionEnum> {
"alter table hfj_spidx_uri alter column hash_identity set statistics 1000",
"alter table hfj_spidx_uri alter column hash_uri set statistics 10000"
)));
{
// add hash_norm to res_id to speed up joins on a second string.
Builder.BuilderWithTableName linkTable = version.onTable("HFJ_RES_LINK");
linkTable
.addIndex("20230424.1", "IDX_RL_TGT_v2")
.unique(false)
.online(true)
.withColumns("TARGET_RESOURCE_ID", "SRC_PATH", "SRC_RESOURCE_ID", "TARGET_RESOURCE_TYPE","PARTITION_ID");
// drop and recreate FK_SPIDXSTR_RESOURCE since it will be useing the old IDX_SP_STRING_RESID
linkTable.dropForeignKey("20230424.2", "FK_RESLINK_TARGET", "HFJ_RESOURCE");
linkTable.dropIndexOnline("20230424.3", "IDX_RL_TPATHRES");
linkTable.dropIndexOnline("20230424.4", "IDX_RL_DEST");
linkTable.addForeignKey("20230424.5", "FK_RESLINK_TARGET")
.toColumn("TARGET_RESOURCE_ID").references("HFJ_RESOURCE", "RES_ID");
}
}
protected void init640() {

View File

@ -45,9 +45,11 @@ import java.util.Date;
@Entity
@Table(name = "HFJ_RES_LINK", indexes = {
@Index(name = "IDX_RL_TPATHRES", columnList = "SRC_PATH,TARGET_RESOURCE_ID"),
// We need to join both ways, so index from src->tgt and from tgt->src.
// From src->tgt, rows are usually written all together as part of ingestion - keep the index small, and read blocks as needed.
@Index(name = "IDX_RL_SRC", columnList = "SRC_RESOURCE_ID"),
@Index(name = "IDX_RL_DEST", columnList = "TARGET_RESOURCE_ID")
// But from tgt->src, include all the match columns. Targets will usually be randomly distributed - each row in separate block.
@Index(name = "IDX_RL_TGT_v2", columnList = "TARGET_RESOURCE_ID, SRC_PATH, SRC_RESOURCE_ID, TARGET_RESOURCE_TYPE,PARTITION_ID")
})
public class ResourceLink extends BaseResourceIndex {
@ -211,7 +213,7 @@ public class ResourceLink extends BaseResourceIndex {
// Must have set an url like http://example.org/something
// We treat 'something' as the resource type because of fix for #659. Prior to #659 fix, 'something' was
// treated as the id and 'example.org' was treated as the resource type
// TODO: log a warning?
// Maybe log a warning?
// }
myTargetResourceType = theTargetResourceUrl.getResourceType();