I have a query where if I hard code the results of the nested SELECT DICTINCT 
to a few
static values, it completes very fast. Leaving the select causes this query to 
slow down
badly. Running an explain query plan wasn't obvious with my weak sql experience.

Is the nested query not evaluated only once?

            SELECT
               a.value,
               COUNT(*) total,
               SUM(CASE WHEN r.status IS NULL THEN 1 ELSE 0 END) unprocessed,
               SUM(CASE WHEN r.status='processed' THEN 1 ELSE 0 END) processed,
               SUM(CASE WHEN r.status='error' THEN 1 ELSE 0 END) error
              FROM diffset d
              JOIN request r
                   ON r.guid_id=d.id
              JOIN action a
                   ON a.req_id=r.id
                   AND a.key='operationType'
                   AND a.value IN (                   
                        SELECT DISTINCT(a.value)
                          FROM action a
                          JOIN request r
                               ON r.guid_id=d.id
                         WHERE a.key='operationType'                         
                   )
             WHERE d.id=?
             GROUP BY value

Thanks,
jlc
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to