将条件放在 JOIN ON 或过滤条件中的好处
benefit to putting conditional in JOIN ON or Filter criteria
在带有 JOIN 的 Siddhi 查询中,将条件条件放在 ON 子句或过滤条件中更好。
JOIN ON 子句中的条件
FROM Stroke_TPA_Ingest_Ras_eMar_Output_Stream as Tpa
JOIN PreAdmitADTTable as Adt
ON str:concat(Tpa.FacilityMnemonic,"-",Tpa.AccountNumber) == str:concat(Adt.FacilityMnemonic,"-",Adt.AccountNumber)
AND (
(
(str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 40 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 90)
)
OR
(
(str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaBolusPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 0 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 9)
)
)
SELECT Tpa.meta_LinkId as meta_LinkId
INSERT INTO AlertStreamIntermediary;
过滤器中的条件
FROM Stroke_TPA_Ingest_Ras_eMar_Output_Stream[
((str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 40 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 90))
OR
((str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaBolusPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 0 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 9))
] as Tpa
JOIN PreAdmitADTTable as Adt
ON str:concat(Tpa.FacilityMnemonic,"-",Tpa.AccountNumber) == str:concat(Adt.FacilityMnemonic,"-",Adt.AccountNumber)
SELECT Tpa.meta_LinkId as meta_LinkId
INSERT INTO AlertStreamIntermediary;
这两个查询似乎是等价的,但想知道是否存在性能差异
第二个查询会执行得更好,因为当事件到达连接查询时,我们已经使用过滤器查询消除了不需要的事件。由于 Siddhi 作为管道,与过滤器不匹配的事件将在该层被丢弃。有关 Siddhi 架构的更多信息,您可以参考 this.
在带有 JOIN 的 Siddhi 查询中,将条件条件放在 ON 子句或过滤条件中更好。
JOIN ON 子句中的条件
FROM Stroke_TPA_Ingest_Ras_eMar_Output_Stream as Tpa
JOIN PreAdmitADTTable as Adt
ON str:concat(Tpa.FacilityMnemonic,"-",Tpa.AccountNumber) == str:concat(Adt.FacilityMnemonic,"-",Adt.AccountNumber)
AND (
(
(str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 40 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 90)
)
OR
(
(str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaBolusPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 0 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 9)
)
)
SELECT Tpa.meta_LinkId as meta_LinkId
INSERT INTO AlertStreamIntermediary;
过滤器中的条件
FROM Stroke_TPA_Ingest_Ras_eMar_Output_Stream[
((str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 40 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 90))
OR
((str:contains(Tpa.TpaPharmacyCodesValueSet, "https://fhir.app.medcity.net/ValueSet/StrokeTpaBolusPharmacyCodes|"))
AND
(convert(Tpa.AdministrationDosageFormId, 'int') > 0 AND convert(Tpa.AdministrationDosageFormId, 'int') <= 9))
] as Tpa
JOIN PreAdmitADTTable as Adt
ON str:concat(Tpa.FacilityMnemonic,"-",Tpa.AccountNumber) == str:concat(Adt.FacilityMnemonic,"-",Adt.AccountNumber)
SELECT Tpa.meta_LinkId as meta_LinkId
INSERT INTO AlertStreamIntermediary;
这两个查询似乎是等价的,但想知道是否存在性能差异
第二个查询会执行得更好,因为当事件到达连接查询时,我们已经使用过滤器查询消除了不需要的事件。由于 Siddhi 作为管道,与过滤器不匹配的事件将在该层被丢弃。有关 Siddhi 架构的更多信息,您可以参考 this.