Оптимизация Django PostgresSQL
Имеется запрос
SELECT "shop_product"."id",
"shop_product"."title",
"shop_product"."slug",
"shop_product"."is_active",
"shop_product"."created_at",
"shop_product"."is_hit",
"shop_product"."is_new",
"shop_product"."brand_id",
"shop_product"."status",
"shop_product"."image_copy",
"shop_product"."description",
"shop_product"."sku",
"shop_product"."main_category_id",
"shop_product"."properties_json",
"shop_product"."width",
"shop_product"."height",
"shop_product"."length",
"shop_product"."weight",
"shop_product"."base_price",
"shop_product"."price",
"shop_product"."discount",
"shop_brand"."id",
"shop_brand"."slug",
"shop_brand"."is_active",
"shop_brand"."title",
"shop_brand"."image",
"shop_brand"."description",
"shop_brand"."site",
"shop_productmetadata"."id",
"shop_productmetadata"."meta_title",
"shop_productmetadata"."meta_description",
"shop_productmetadata"."meta_author",
"shop_productmetadata"."meta_robots",
"shop_productmetadata"."product_id"
FROM "shop_product"
LEFT OUTER JOIN "shop_brand"
ON ("shop_product"."brand_id" = "shop_brand"."id")
LEFT OUTER JOIN "shop_productmetadata"
ON ("shop_product"."id" = "shop_productmetadata"."product_id")
WHERE "shop_product"."is_active"
ORDER BY "shop_product"."title" ASC, "shop_product"."id" ASC
LIMIT 15
И он работает 180-190 мс, но вовзвращает дубли.
Такой же запрос с DISTINCT работает в 8 раз дольше.
Как оптимизировать? Что можно сделать?
В таблице 600 000 товаров