Zadanie #8465

Uprościć kwerendy w metodzie getCorporaAnnotationSetStats

Added by Michał Marcińczuk over 5 years ago. Updated over 5 years ago.

Status:ZamkniętyStart date:10 Jan 2018
Priority:NiskiDue date:
Assignee:Mikołaj Szewczyk% Done:

100%

Category:-Estimated time:4.00 hours
Target version:Release 2018.02.02

Description

Obecna metoda ma postać:

    static function getCorporaAnnotationSetStats($annotation_set_id){
        global $db;

        $sql = "SELECT c.id, c.name, c.public, c.description FROM annotation_sets_corpora ansc 
                JOIN corpora c ON c.id = ansc.corpus_id
                WHERE ansc.annotation_set_id = ?
                ORDER BY c.name";
        $corpora = $db->fetch_rows($sql, array($annotation_set_id));

        foreach($corpora as $index => $corpus) {
            $sql = "SELECT count(ra.id) FROM annotation_types at 
                    LEFT JOIN reports_annotations ra ON 
                    (at.name = ra.type AND report_id IN 
                      (SELECT id FROM reports r WHERE r.corpora = ?)
                    )
                    WHERE at.group_id = ?";
            $count_uses = $db->fetch_one($sql, array($corpus['id'], $annotation_set_id));

            $corpora[$index]['count_uses'] = $count_uses;
        }
        return $corpora;
    }

Kosztowne czasowo elementy jest użycie operator IN. Czy jest on uzasadniony. Nie można go zastąpić JOIN-em?

Druga rzecz, to czy nie można całości wykonać jednym zapytaniem? Np. annotation_sets_corpora JOIN corpora ON (annotation_set_id = ?) JOIN reports JOIN annotations ...

History

#1 Updated by Michał Marcińczuk over 5 years ago

  • Estimated time set to 4.00

#2 Updated by Mikołaj Szewczyk over 5 years ago

  • % Done changed from 0 to 100

#3 Updated by Mikołaj Szewczyk over 5 years ago

  • Status changed from Przypisany to Rozwiązany

#4 Updated by Michał Marcińczuk over 5 years ago

  • Status changed from Rozwiązany to Zamknięty

Also available in: Atom PDF