0

我真的需要以下建议,尝试使用数据库函数 getpreviousorders..

SELECT o1.* FROM "sample"."order" o1 JOIN "sample".patient p1 ON o1.patient_id = p1.id
        WHERE o1.sample_id != _sampleId AND p1.mrn = _mrn
          AND ((o1.collection_date is not null AND o1.collection_date >= _createdDate)
            OR (o1.collection_date is null AND o1.receipt_date is not null
                AND o1.receipt_date >= _createdDate))
        UNION
        (SELECT o2.* FROM "sample"."order" o2 JOIN "sample".patient p2 ON o2.patient_id = p2.id
         WHERE (o2.status = 1 or o2.status = 2 OR o2.status = 3) AND o2.sample_id != _sampleId
         AND p2.mrn = _mrn
           AND ((o2.collection_date is not null AND o2.collection_date < _createdDate)
             OR (o2.collection_date is null AND o2.receipt_date is not null
                 AND o2.receipt_date < _createdDate)) ORDER by created_date DESC LIMIT 1)
        ORDER by collection_date DESC, receipt_date DESC, created_date DESC;

获得 199 个先前订单的总时间为 2628 毫秒,而 findPreviousOrders 函数花费的所有时间最多:2535 毫秒

分析查询和代码片段!!!

查询分析器

大部分时间用于代码

代码片段

4

0 回答 0