-- Original query
EXPLAIN ANALYZE SELECT DISTINCT "core_record"."id", "core_record"."name", "core_record"."description", "core_record"."description_html", "core_record"."image", "core_record"."date_created", "core_record"."is_deleted", "core_record"."is_public", "core_record"."old_id", "core_record"."meta_data", "core_people"."record_ptr_id", "core_people"."firstname", "core_people"."lastname", "core_people"."affiliation", "core_people"."email", "core_people"."email_public", "core_people"."website", "core_people"."twitter", "core_people"."google_scholar", "core_people"."orcid", "core_people"."researchgate", "core_people"."linkedin", "core_people"."research_interests", "core_people"."status", "core_people"."user_id", "auth_user"."date_joined" FROM "core_people" INNER JOIN "core_record" ON ("core_people"."record_ptr_id" = "core_record"."id") INNER JOIN "core_message" ON ("core_people"."record_ptr_id" = "core_message"."posted_by_id") INNER JOIN "auth_user" ON ("core_people"."user_id" = "auth_user"."id") INNER JOIN "core_message" T5 ON ("core_people"."record_ptr_id" = T5."posted_by_id") INNER JOIN "core_record" T6 ON (T5."parent_id" = T6."id") LEFT OUTER JOIN "core_forumtopic" ON (T6."id" = "core_forumtopic"."record_ptr_id") LEFT OUTER JOIN "core_work" ON (T6."id" = "core_work"."record_ptr_id") WHERE (NOT "core_record"."is_deleted" AND "core_record"."is_public" AND "core_message"."record_ptr_id" IS NOT NULL AND "core_people"."user_id" IS NOT NULL AND ("core_forumtopic"."part_of_project_id" = 6 OR "core_work"."part_of_project_id" = 6)) ORDER BY "auth_user"."date_joined" DESC LIMIT 21;

-- Remove DISTINCT
EXPLAIN ANALYZE SELECT "core_record"."id", "core_record"."name", "core_record"."description", "core_record"."description_html", "core_record"."image", "core_record"."date_created", "core_record"."is_deleted", "core_record"."is_public", "core_record"."old_id", "core_record"."meta_data", "core_people"."record_ptr_id", "core_people"."firstname", "core_people"."lastname", "core_people"."affiliation", "core_people"."email", "core_people"."email_public", "core_people"."website", "core_people"."twitter", "core_people"."google_scholar", "core_people"."orcid", "core_people"."researchgate", "core_people"."linkedin", "core_people"."research_interests", "core_people"."status", "core_people"."user_id", "auth_user"."date_joined" FROM "core_people" INNER JOIN "core_record" ON ("core_people"."record_ptr_id" = "core_record"."id") INNER JOIN "core_message" ON ("core_people"."record_ptr_id" = "core_message"."posted_by_id") INNER JOIN "auth_user" ON ("core_people"."user_id" = "auth_user"."id") INNER JOIN "core_message" T5 ON ("core_people"."record_ptr_id" = T5."posted_by_id") INNER JOIN "core_record" T6 ON (T5."parent_id" = T6."id") LEFT OUTER JOIN "core_forumtopic" ON (T6."id" = "core_forumtopic"."record_ptr_id") LEFT OUTER JOIN "core_work" ON (T6."id" = "core_work"."record_ptr_id") WHERE (NOT "core_record"."is_deleted" AND "core_record"."is_public" AND "core_message"."record_ptr_id" IS NOT NULL AND "core_people"."user_id" IS NOT NULL AND ("core_forumtopic"."part_of_project_id" = 6 OR "core_work"."part_of_project_id" = 6)) ORDER BY "auth_user"."date_joined" DESC LIMIT 21;

-- Remove DISTINCT and ORDER BY 
EXPLAIN ANALYZE SELECT "core_record"."id", "core_record"."name", "core_record"."description", "core_record"."description_html", "core_record"."image", "core_record"."date_created", "core_record"."is_deleted", "core_record"."is_public", "core_record"."old_id", "core_record"."meta_data", "core_people"."record_ptr_id", "core_people"."firstname", "core_people"."lastname", "core_people"."affiliation", "core_people"."email", "core_people"."email_public", "core_people"."website", "core_people"."twitter", "core_people"."google_scholar", "core_people"."orcid", "core_people"."researchgate", "core_people"."linkedin", "core_people"."research_interests", "core_people"."status", "core_people"."user_id", "auth_user"."date_joined" FROM "core_people" INNER JOIN "core_record" ON ("core_people"."record_ptr_id" = "core_record"."id") INNER JOIN "core_message" ON ("core_people"."record_ptr_id" = "core_message"."posted_by_id") INNER JOIN "auth_user" ON ("core_people"."user_id" = "auth_user"."id") INNER JOIN "core_message" T5 ON ("core_people"."record_ptr_id" = T5."posted_by_id") INNER JOIN "core_record" T6 ON (T5."parent_id" = T6."id") LEFT OUTER JOIN "core_forumtopic" ON (T6."id" = "core_forumtopic"."record_ptr_id") LEFT OUTER JOIN "core_work" ON (T6."id" = "core_work"."record_ptr_id") WHERE (NOT "core_record"."is_deleted" AND "core_record"."is_public" AND "core_message"."record_ptr_id" IS NOT NULL AND "core_people"."user_id" IS NOT NULL AND ("core_forumtopic"."part_of_project_id" = 6 OR "core_work"."part_of_project_id" = 6)) LIMIT 21;

-- Remove ORDER BY
EXPLAIN ANALYZE SELECT DISTINCT "core_record"."id", "core_record"."name", "core_record"."description", "core_record"."description_html", "core_record"."image", "core_record"."date_created", "core_record"."is_deleted", "core_record"."is_public", "core_record"."old_id", "core_record"."meta_data", "core_people"."record_ptr_id", "core_people"."firstname", "core_people"."lastname", "core_people"."affiliation", "core_people"."email", "core_people"."email_public", "core_people"."website", "core_people"."twitter", "core_people"."google_scholar", "core_people"."orcid", "core_people"."researchgate", "core_people"."linkedin", "core_people"."research_interests", "core_people"."status", "core_people"."user_id", "auth_user"."date_joined" FROM "core_people" INNER JOIN "core_record" ON ("core_people"."record_ptr_id" = "core_record"."id") INNER JOIN "core_message" ON ("core_people"."record_ptr_id" = "core_message"."posted_by_id") INNER JOIN "auth_user" ON ("core_people"."user_id" = "auth_user"."id") INNER JOIN "core_message" T5 ON ("core_people"."record_ptr_id" = T5."posted_by_id") INNER JOIN "core_record" T6 ON (T5."parent_id" = T6."id") LEFT OUTER JOIN "core_forumtopic" ON (T6."id" = "core_forumtopic"."record_ptr_id") LEFT OUTER JOIN "core_work" ON (T6."id" = "core_work"."record_ptr_id") WHERE (NOT "core_record"."is_deleted" AND "core_record"."is_public" AND "core_message"."record_ptr_id" IS NOT NULL AND "core_people"."user_id" IS NOT NULL AND ("core_forumtopic"."part_of_project_id" = 6 OR "core_work"."part_of_project_id" = 6)) LIMIT 21;
