Skip to content

Instantly share code, notes, and snippets.

@dirkcuys
Created January 7, 2013 07:50
Show Gist options
  • Select an option

  • Save dirkcuys/4473181 to your computer and use it in GitHub Desktop.

Select an option

Save dirkcuys/4473181 to your computer and use it in GitHub Desktop.

Revisions

  1. dirkcuys created this gist Jan 7, 2013.
    26 changes: 26 additions & 0 deletions Faster query
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    SELECT
    `relationships_relationship`.`id`,
    `relationships_relationship`.`source_id`,
    `relationships_relationship`.`target_user_id`,
    `relationships_relationship`.`target_project_id`,
    `relationships_relationship`.`created_on`,
    `relationships_relationship`.`deleted`
    FROM
    `relationships_relationship`
    INNER JOIN
    `users_userprofile` ON (`relationships_relationship`.`source_id` = `users_userprofile`.`id`)
    INNER JOIN
    `projects_perusertaskcompletion` ON (`relationships_relationship`.`source_id` = `projects_perusertaskcompletion`.`user_id`)
    INNER JOIN
    `content_page` U1 ON (`projects_perusertaskcompletion`.`page_id` = U1.`id`)
    WHERE
    `projects_perusertaskcompletion`.`unchecked_on` IS NULL
    AND U1.`project_id` = 355
    AND U1.`deleted` = False
    AND `users_userprofile`.`deleted` = False
    AND `relationships_relationship`.`target_project_id` = 355
    GROUP BY
    `projects_perusertaskcompletion`.`user_id`, `projects_perusertaskcompletion`.`user_id`
    HAVING
    COUNT(`projects_perusertaskcompletion`.`page_id`) = 4
    LIMIT 56;