Mercurial > hg > orthanc-databases
changeset 847:e942f6269e9f pg-next-1099
optimized single resources FindRequest
| author | Alain Mazy <am@orthanc.team> |
|---|---|
| date | Thu, 17 Sep 2026 09:12:30 +0200 |
| parents | 2cf181ce319a |
| children | 3e4d8da97292 |
| files | Framework/Plugins/ISqlLookupFormatter.cpp |
| diffstat | 1 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/Framework/Plugins/ISqlLookupFormatter.cpp Wed Sep 16 10:05:45 2026 +0200 +++ b/Framework/Plugins/ISqlLookupFormatter.cpp Thu Sep 17 09:12:30 2026 +0200 @@ -807,6 +807,11 @@ assert(upperLevel <= queryLevel && queryLevel <= lowerLevel); + const bool isOrthancIdentifiersDefined = (!request.orthanc_id_patient().empty() || + !request.orthanc_id_study().empty() || + !request.orthanc_id_series().empty() || + !request.orthanc_id_instance().empty()); + std::string orderingSql; std::string orderingJoins; @@ -878,7 +883,14 @@ } else { - orderingSql = "ROW_NUMBER() OVER (ORDER BY " + strQueryLevel + ".publicId) AS rowNumber"; // we need a default ordering in order to make default queries repeatable when using since&limit + if (isOrthancIdentifiersDefined && DetectLevel(request) == queryLevel) + { // this is a single resource, no need for ordering (ordering may prevents a lot of optimizations from the query planner) + orderingSql = "0 AS rowNumber"; + } + else + { + orderingSql = "ROW_NUMBER() OVER (ORDER BY " + strQueryLevel + ".publicId) AS rowNumber"; // we need a default ordering in order to make default queries repeatable when using since&limit + } } sql = ("SELECT " + @@ -890,11 +902,6 @@ std::string joins, comparisons; - const bool isOrthancIdentifiersDefined = (!request.orthanc_id_patient().empty() || - !request.orthanc_id_study().empty() || - !request.orthanc_id_series().empty() || - !request.orthanc_id_instance().empty()); - // handle parent constraints if (isOrthancIdentifiersDefined && Orthanc::IsResourceLevelAboveOrEqual(DetectLevel(request), queryLevel)) {
