Skip to content

Instantly share code, notes, and snippets.

@Je33
Created October 30, 2019 17:41
Show Gist options
  • Save Je33/cb9e017a38dcaeffa44b18beb2f893c9 to your computer and use it in GitHub Desktop.
Save Je33/cb9e017a38dcaeffa44b18beb2f893c9 to your computer and use it in GitHub Desktop.
EXPLAIN SELECT "pairs"."id" AS t0_r0, "pairs"."pair_id" AS t0_r1, "pairs"."slug" AS t0_r2, "pairs"."is_active" AS t0_r3, "pairs"."creation_date" AS t0_r4, "pairs"."country_flag" AS t0_r5, "pairs"."partnership_type" AS t0_r6, "pairs"."main_image" AS t0_r7, "pairs"."inner_image" AS t0_r8, "pairs"."logo" AS t0_r9, "pairs"."country" AS t0_r10, "pairs"."region" AS t0_r11, "pairs"."category" AS t0_r12, "pairs"."catalog_category_id" AS t0_r13, "pairs"."city" AS t0_r14, "pairs"."subcategory" AS t0_r15, "pairs"."discount_amount" AS t0_r16, "pairs"."razmer_komissii" AS t0_r17, "pairs"."website" AS t0_r18, "pairs"."dynamics" AS t0_r19, "pairs"."is_basket" AS t0_r20, "pairs"."is_retail" AS t0_r21, "pairs"."is_rank" AS t0_r22, "pairs"."is_vip" AS t0_r23, "pairs"."created_at" AS t0_r24, "pairs"."updated_at" AS t0_r25, "pairs"."industry" AS t0_r26, "pairs"."views" AS t0_r27, "pairs"."robots_deny" AS t0_r28, "pairs"."is_unindexed" AS t0_r29, "pairs"."currency" AS t0_r30, "pairs"."referral_link" AS t0_r31, "pairs"."offline" AS t0_r32, "pairs"."online" AS t0_r33, "pairs"."only_card" AS t0_r34, "pairs"."exclusive" AS t0_r35, "pairs"."aggregator_id" AS t0_r36, "pairs"."aggregator_name" AS t0_r37, "pairs"."aggregator_rating" AS t0_r38, "pairs"."cashback_period" AS t0_r39, "pairs"."is_public" AS t0_r40, "pairs"."audit_passed" AS t0_r41, "pairs"."campaigns_count" AS t0_r42, "pairs"."active_untill" AS t0_r43, "pairs"."merchant_id" AS t0_r44, "pairs"."secret_key" AS t0_r45, "pairs"."mobile_traffic" AS t0_r46, "pairs"."only_specials" AS t0_r47, "pairs"."is_extension_allowed" AS t0_r48, "pairs"."is_cobrand_paid" AS t0_r49, "pairs"."is_qr_scan" AS t0_r50, "pairs"."is_need_to_confirm_qr" AS t0_r51, "pairs"."encrypted_password" AS t0_r52, "pairs"."is_auto_confirm_qr" AS t0_r53, "pairs"."number_of_retail_cashbox" AS t0_r54, "pairs"."check_scan_limit" AS t0_r55, "pairs"."req_legal_name" AS t0_r56, "pairs"."req_registration_date" AS t0_r57, "pairs"."req_legal_address" AS t0_r58, "pairs"."req_actual_address" AS t0_r59, "pairs"."req_post_address" AS t0_r60, "pairs"."req_contact_phone" AS t0_r61, "pairs"."req_technical_service_phone" AS t0_r62, "pairs"."req_ogrn" AS t0_r63, "pairs"."req_inn" AS t0_r64, "pairs"."req_kpp" AS t0_r65, "pairs"."req_okved" AS t0_r66, "pairs"."req_company_director" AS t0_r67, "pairs"."req_accountant_general" AS t0_r68, "pairs"."bank_checking_account" AS t0_r69, "pairs"."bank_name" AS t0_r70, "pairs"."bank_corr_account" AS t0_r71, "pairs"."bank_bik" AS t0_r72, "pairs"."contact_technical" AS t0_r73, "pairs"."contact_finances" AS t0_r74, "pairs"."contact_marketing_pr_ad" AS t0_r75, "pairs"."opportunity_gold_shop" AS t0_r76, "pairs"."email" AS t0_r77, "pairs"."is_gold" AS t0_r78, "pairs"."restrict_manual_qr" AS t0_r79, "pairs"."last_authorization_at" AS t0_r80, "pairs"."last_authorization_ip" AS t0_r81, "pairs"."mobile_apps" AS t0_r82, "pairs"."rule_fns" AS t0_r83, "pairs"."bank_external_merchant_id" AS t0_r84, "pairs"."manager_comment" AS t0_r85, "pairs"."status" AS t0_r86, "pairs"."program_status" AS t0_r87, "pairs"."gold_shop_login" AS t0_r88, "pairs"."wallet_id" AS t0_r89, "pairs"."bank_subaccount_number_rib" AS t0_r90, "pairs"."recruiter_user_id" AS t0_r91, "pairs"."is_switplanet" AS t0_r92, "countries"."id" AS t1_r0, "countries"."name" AS t1_r1, "countries"."created_at" AS t1_r2, "countries"."updated_at" AS t1_r3, "countries"."code" AS t1_r4, "countries"."currency" AS t1_r5, "countries"."name_en" AS t1_r6, "campaigns"."id" AS t2_r0, "campaigns"."aggregator_name" AS t2_r1, "campaigns"."aggregator_id" AS t2_r2, "campaigns"."start_date" AS t2_r3, "campaigns"."end_date" AS t2_r4, "campaigns"."pair_id" AS t2_r5, "campaigns"."promocode" AS t2_r6, "campaigns"."gotolink" AS t2_r7, "campaigns"."rating" AS t2_r8, "campaigns"."image" AS t2_r9, "campaigns"."active" AS t2_r10, "campaigns"."views" AS t2_r11, "campaigns"."created_at" AS t2_r12, "campaigns"."updated_at" AS t2_r13, "campaigns"."views_count" AS t2_r14, "campaigns"."foreign_id" AS t2_r15, "campaigns"."retail" AS t2_r16, "campaigns"."partner_id" AS t2_r17, "campaigns"."is_gold" AS t2_r18, "campaigns"."mode" AS t2_r19, "campaigns"."promocode_limit" AS t2_r20, "campaigns"."promocode_type" AS t2_r21, "catalog_categories"."id" AS t3_r0, "catalog_categories"."catalog_industry_id" AS t3_r1, "catalog_categories"."childrens_count" AS t3_r2, "catalog_categories"."mcc" AS t3_r3, "catalog_category_translations"."id" AS t4_r0, "catalog_category_translations"."catalog_category_id" AS t4_r1, "catalog_category_translations"."locale" AS t4_r2, "catalog_category_translations"."created_at" AS t4_r3, "catalog_category_translations"."updated_at" AS t4_r4, "catalog_category_translations"."name" AS t4_r5, "shops"."id" AS t5_r0, "shops"."name" AS t5_r1, "shops"."address" AS t5_r2, "shops"."pair_id" AS t5_r3, "shops"."lat" AS t5_r4, "shops"."lng" AS t5_r5, "shops"."is_active" AS t5_r6, "shops"."created_at" AS t5_r7, "shops"."updated_at" AS t5_r8, "shop_contacts"."id" AS t6_r0, "shop_contacts"."shop_id" AS t6_r1, "shop_contacts"."name" AS t6_r2, "shop_contacts"."contact_type" AS t6_r3, "shop_contacts"."contact" AS t6_r4, "shop_contacts"."created_at" AS t6_r5, "shop_contacts"."updated_at" AS t6_r6, "shop_working_hours"."id" AS t7_r0, "shop_working_hours"."shop_id" AS t7_r1, "shop_working_hours"."week_day" AS t7_r2, "shop_working_hours"."work_start_min" AS t7_r3, "shop_working_hours"."work_end_min" AS t7_r4, "shop_working_hours"."date" AS t7_r5, "shop_working_hours"."created_at" AS t7_r6, "shop_working_hours"."updated_at" AS t7_r7, "countries_pairs_pairs"."id" AS t8_r0, "countries_pairs_pairs"."pair_id" AS t8_r1, "countries_pairs_pairs"."country_id" AS t8_r2 FROM "pairs" INNER JOIN "pair_translations" ON "pair_translations"."pair_id" = "pairs"."id" LEFT OUTER JOIN "countries_pairs" ON "countries_pairs"."pair_id" = "pairs"."id" LEFT OUTER JOIN "countries" ON "countries"."id" = "countries_pairs"."country_id" LEFT OUTER JOIN "campaigns" ON "campaigns"."pair_id" = "pairs"."pair_id" AND (campaigns.active = TRUE AND campaigns.start_date < '2019-10-30 16:54:24.364097' AND campaigns.end_date > '2019-10-30 16:54:24.364097') LEFT OUTER JOIN "catalog_categories" ON "catalog_categories"."id" = "pairs"."catalog_category_id" LEFT OUTER JOIN "catalog_category_translations" ON "catalog_category_translations"."catalog_category_id" = "catalog_categories"."id" LEFT OUTER JOIN "shops" ON "shops"."pair_id" = "pairs"."id" LEFT OUTER JOIN "shop_contacts" ON "shop_contacts"."shop_id" = "shops"."id" LEFT OUTER JOIN "shop_working_hours" ON "shop_working_hours"."shop_id" = "shops"."id" LEFT OUTER JOIN "countries_pairs" "countries_pairs_pairs" ON "countries_pairs_pairs"."pair_id" = "pairs"."id" WHERE (pairs.is_active = TRUE AND pairs.active_untill IS NULL OR pairs.active_untill >= '2019-10-30') AND "pair_translations"."locale" = 'ru' AND "pairs"."is_public" = TRUE AND ("countries_pairs"."country_id" = 2017370 OR "countries_pairs"."country_id" IS NULL) AND "pairs"."id" IN (2911, 1737, 1539, 11269785, 2941, 1697, 1672, 2948, 1575, 2661) ORDER BY pairs.views DESC NULLS LAST
Sort (cost=393.39..393.45 rows=24 width=1990)
Sort Key: pairs.views DESC NULLS LAST
-> Hash Left Join (cost=19.09..392.84 rows=24 width=1990)
Hash Cond: (shops.id = shop_working_hours.shop_id)
-> Nested Loop Left Join (cost=9.50..382.97 rows=24 width=1950)
-> Hash Left Join (cost=9.21..231.53 rows=24 width=1938)
Hash Cond: (shops.id = shop_contacts.shop_id)
-> Nested Loop Left Join (cost=4.87..226.97 rows=24 width=1878)
-> Nested Loop Left Join (cost=4.73..219.73 rows=4 width=1833)
-> Nested Loop Left Join (cost=4.45..185.53 rows=4 width=1672)
Join Filter: (catalog_categories.id = pairs.catalog_category_id)
-> Nested Loop Left Join (cost=4.45..182.06 rows=4 width=1656)
-> Nested Loop Left Join (cost=4.03..152.47 rows=4 width=964)
-> Nested Loop (cost=3.88..151.77 rows=4 width=910)
-> Nested Loop Left Join (cost=0.56..91.46 rows=4 width=910)
Filter: ((countries_pairs.country_id = 2017370) OR (countries_pairs.country_id IS NULL))
-> Index Scan using pairs_pkey on pairs (cost=0.28..59.90 rows=5 width=906)
" Index Cond: (id = ANY ('{2911,1737,1539,11269785,2941,1697,1672,2948,1575,2661}'::integer[]))"
Filter: (is_public AND ((is_active AND (active_untill IS NULL)) OR (active_untill >= '2019-10-30'::date)))
-> Index Scan using index_countries_pairs_on_pair_id on countries_pairs (cost=0.28..6.30 rows=1 width=8)
Index Cond: (pair_id = pairs.id)
-> Bitmap Heap Scan on pair_translations (cost=3.32..15.07 rows=1 width=4)
Recheck Cond: (pair_id = pairs.id)
Filter: ((locale)::text = 'ru'::text)
-> Bitmap Index Scan on index_pair_translations_on_pair_id (cost=0.00..3.32 rows=4 width=0)
Index Cond: (pair_id = pairs.id)
-> Index Scan using countries_pkey on countries (cost=0.14..0.17 rows=1 width=58)
Index Cond: (id = countries_pairs.country_id)
-> Index Scan using index_campaigns_on_pair_id_and_actual_on on campaigns (cost=0.42..7.39 rows=1 width=692)
Index Cond: ((pair_id = pairs.pair_id) AND (active = true) AND (start_date < '2019-10-30 16:54:24.364097+00'::timestamp with time zone) AND (end_date > '2019-10-30 16:54:24.364097+00'::timestamp with time zone))
Filter: active
-> Materialize (cost=0.00..1.51 rows=34 width=16)
-> Seq Scan on catalog_categories (cost=0.00..1.34 rows=34 width=16)
-> Index Scan using index_shops_on_pair_id on shops (cost=0.28..8.53 rows=2 width=161)
Index Cond: (pair_id = pairs.id)
-> Index Scan using index_catalog_category_translations_on_catalog_category_id on catalog_category_translations (cost=0.14..1.75 rows=6 width=45)
Index Cond: (catalog_category_id = catalog_categories.id)
-> Hash (cost=3.04..3.04 rows=104 width=60)
-> Seq Scan on shop_contacts (cost=0.00..3.04 rows=104 width=60)
-> Index Scan using index_countries_pairs_on_pair_id on countries_pairs countries_pairs_pairs (cost=0.28..6.30 rows=1 width=12)
Index Cond: (pair_id = pairs.id)
-> Hash (cost=5.93..5.93 rows=293 width=40)
-> Seq Scan on shop_working_hours (cost=0.00..5.93 rows=293 width=40)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment