Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2ldq-0007b3-JE for pgsql-performance@arkaria.postgresql.org; Fri, 22 Jan 2021 01:53:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l2ldp-0000I3-3L for pgsql-performance@arkaria.postgresql.org; Fri, 22 Jan 2021 01:53:37 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l2ldo-0000Hw-JX for pgsql-performance@lists.postgresql.org; Fri, 22 Jan 2021 01:53:36 +0000 Received: from sonic315-21.consmr.mail.ne1.yahoo.com ([66.163.190.147]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l2ldk-0002Md-Hp for pgsql-performance@lists.postgresql.org; Fri, 22 Jan 2021 01:53:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1611280409; bh=hZaifaalSL8eHpqjtalagLLthBzKRLNPK+uNoLwj+5U=; h=Date:From:To:Subject:References:From:Subject:Reply-To; b=pv6A4xvBYzD7M4cXxWQ4WhAdz5dJLrp5YPLlExY3Ll3N/32e2WEpYCFGCKcsZazGsr3cJbUzvyBZ0O/A+edc5TmxoDXZ2zA6IgWD9SG205hQDMF2phLRfaBJ8n/4ugR/kiH/LGxquNslvPZeeJL+woqVVa7T1BX9cZ879uty7D8wn+1UIf/hjjpZDH3l/BovYBgF0bujTD5BT8VDHSBVoRRmTQZEvfJVOeHJ9+xaK+0c39GWkCwcdtT2S2Ru1Gx5MPETf3VcH7ul9pRRPd25wRhvERBEKbXXXFzped2gMc8o+TypbMFU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Y5KtZqjnEtt0n3A31M7xuu5vzakLzdsdCeNyteeGZ4rNQNpX.7yOgkkyqgyAa8Cd3HhD mb_1VpkJVMzPSzEZqKrm4qS.p2a6viN6lh0zQLgIsn0cMPhDCV4ihnW6ix1G6nNBQSDQbbp9sxx3 x45JxCv.XfsZC1nTdUAQLSa99GrmQkSt58C60OQUC8rfFlypsZJzyDmQLx2WfXUiVcUFV2pB0uBa semrHikIUBd6OdX4btr2Z0l1pNJV3fAfdjapOCSZGArUHzayIz3ysvEoI_oa_2Q9ahtXJ.b4nGnq HNXNLChjqHeUO3kGLPP3j71KdVCn_sHjIVyB70PEukCCPVcb2i1JXbU3wAKfXfmkyTg14ApfyfRr pAc3sRUit5Y4nNoAUHrr6Fy.3cNiruO_CohEqLpFPHlxzcjapPSKk_WZMZ4r5kYU1UfKz7nPqM8b SxPLDjxZ2wN74xBZxC_.QtHvVApY_RTiy6qORgGXgLIipBBUERmKuMYFd3_PwaYIWjYNFJ76_HsK 4PBzKTfAGk9B11aaKD2yZ9N7K3MLEl5eFYVY8wx_M1cOrblsTcHtdIbekBAwC__YCZ81tlr7kvUW _9gG_YbriFSwP2jevuH8GA0NQCgVWeQ2ttCZg3JQgLuPVOHps_aPFQh1J7r9zfDvGg0bjX7QB8rY o3hVc7Czg5SBUQohcQ_46aUq5s6JXnBgIiDXXJ6xtjBO7bEinj85bu9rtSaR00_YxTK_8z06VXLY UKnWC7LxjJ8sD0aEaIkaVN3ibXeY5yAzgBROXinS66LxFW_7tyBpigknPbZfV5psF7CQgBmrv4lB E Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Fri, 22 Jan 2021 01:53:29 +0000 Date: Fri, 22 Jan 2021 01:53:26 +0000 (UTC) From: Nagaraj Raj To: Pgsql Performance Message-ID: <135856010.59446.1611280406074@mail.yahoo.com> Subject: Query performance issue MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_59445_2090499658.1611280406071" References: <135856010.59446.1611280406074.ref@mail.yahoo.com> X-Mailer: WebService/1.1.17630 YMailNorrin Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36 Content-Length: 18673 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_59445_2090499658.1611280406071 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi, I have a query performance issue, it takes a long time, and not even gettin= g explain analyze the output. this query joining on 3 tables which have aro= und=C2=A0a - 176223509 b - 286887780 c - 214219514 explainselect=C2=A0 Count(a."individual_entity_proxy_id")from "prospect" ai= nner join "individual_demographic" bon a."individual_entity_proxy_id" =3D b= ."individual_entity_proxy_id"inner join "household_demographic" c=C2=A0on a= ."household_entity_proxy_id" =3D c."household_entity_proxy_id"where (((a."l= ast_contacted_anychannel_dttm" is null)=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0or (a."last_contacted_anychannel_dttm" < TIMESTAMP '2020-11-23= 0:00:00.000000'))=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0and (a."shared_paddr_with_customer_ind" =3D 'N')=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0and (a."profane_wrd_ind" = =3D 'N')=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0and (= a."tmo_ofnsv_name_ind" =3D 'N')=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0and (a."has_individual_address" =3D 'Y')=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0and (a."has_last_nam= e" =3D 'Y')=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0and (a."has_first_name" =3D 'Y= '))=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0and= ((b."tax_bnkrpt_dcsd_ind" =3D 'N')=C2=A0 =C2=A0 =C2=A0and (b."govt_prison_= ind" =3D 'N')=C2=A0 =C2=A0 =C2=A0and (b."cstmr_prspct_ind" =3D 'Prospect'))= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0and ((= c."hspnc_lang_prfrnc_cval" in ('B', 'E', 'X') )=C2=A0 =C2=A0 =C2=A0or (c."= hspnc_lang_prfrnc_cval" is null));-- Explain output =C2=A0"Finalize Aggregate=C2=A0 (cost=3D32813309.28..32813309.29 rows=3D1 w= idth=3D8)""=C2=A0 ->=C2=A0 Gather=C2=A0 (cost=3D32813308.45..32813309.26 ro= ws=3D8 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 Workers Planned: 8""=C2=A0 = =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Partial Aggregate=C2=A0 (cost=3D32812308.45..= 32812308.46 rows=3D1 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 ->=C2=A0 Merge Join=C2=A0 (cost=3D23870130.00..32759932.46 rows=3D20= 950395 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 Merge Cond: (a.individual_entity_proxy_id =3D b.individual_en= tity_proxy_id)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ->=C2=A0 Sort=C2=A0 (cost=3D23870127.96..23922503.94 rows=3D2095= 0395 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Sort Key: a.individual_entity_proxy_id""= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 ->=C2=A0 Hash Join=C2=A0 (cost=3D13533600.42..21322510.26= rows=3D20950395 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Hash Con= d: (a.household_entity_proxy_id =3D c.household_entity_proxy_id)""=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Parallel Seq Scan on prospect a=C2= =A0 (cost=3D0.00..6863735.60 rows=3D22171902 width=3D16)""=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Filter: (((last_contacted_anychan= nel_dttm IS NULL) OR (last_contacted_anychannel_dttm < '2020-11-23 00:00:00= '::timestamp without time zone)) AND (shared_paddr_with_customer_ind =3D 'N= '::bpchar) AND (profane_wrd_ind =3D 'N'::bpchar) AND (tmo_ofnsv_name_ind = =3D 'N'::bpchar) AND (has_individual_address =3D 'Y'::bpchar) AND (has_last= _name =3D 'Y'::bpchar) AND (has_first_name =3D 'Y'::bpchar))""=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 ->=C2=A0 Hash=C2=A0 (cost=3D10801715.18..10801715.= 18 rows=3D166514899 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 ->=C2=A0 Seq Scan on household_demographic c=C2=A0 (cost= =3D0.00..10801715.18 rows=3D166514899 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Filter: (((hspnc_la= ng_prfrnc_cval)::text =3D ANY ('{B,E,X}'::text[])) OR (hspnc_lang_prfrnc_cv= al IS NULL))""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 ->=C2=A0 Index Only Scan using indx_individual_demographic_prxyi= d_taxind_prspctind_prsnind on individual_demographic b=C2=A0 (cost=3D0.57..= 8019347.13 rows=3D286887776 width=3D8)""=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Index Cond: ((tax_b= nkrpt_dcsd_ind =3D 'N'::bpchar) AND (cstmr_prspct_ind =3D 'Prospect'::text)= AND (govt_prison_ind =3D 'N'::bpchar))"=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Tables ddl are attached in dbfiddle --=C2=A0Postgres 11 | db<>fiddle |=20 |=20 | |=20 Postgres 11 | db<>fiddle Free online SQL environment for experimenting and sharing. | | | Server configuration is:=C2=A0Version: 10.11RAM - 320GBvCPU - 32=C2=A0"main= tenance_work_mem" 256MB"work_mem" =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= 1GB"shared_buffers" 64GB Any suggestions?=C2=A0 Thanks,Rj ------=_Part_59445_2090499658.1611280406071 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,

I have a query performance issue, i= t takes a long time, and not even getting explain analyze the output. this = query joining on 3 tables which have around 
a - 176223509
b= - 286887780
= c - 214= 219514


=

explain
select  Cou= nt(a."individual_entity_proxy_id")
from "prospect" a
in= ner join "individual_demographic" b
on a."individual_entity_proxy= _id" =3D b."individual_entity_proxy_id"
inner join "household_dem= ographic" c 
on a."household_entity_proxy_id" =3D c."househo= ld_entity_proxy_id"
where (((a."last_contacted_anychannel_dttm" i= s null) 
=09=09           or (a."last_contacted_anychannel_= dttm" < TIMESTAMP '2020-11-23 0:00:00.000000'))
    =                and (a."shared_paddr= _with_customer_ind" =3D 'N') 
=09               a= nd (a."profane_wrd_ind" =3D 'N') 
=09              &nb= sp;and (a."tmo_ofnsv_name_ind" =3D 'N')
      &nbs= p;            and (a."has_individual_address"= =3D 'Y') 
=09=                and (a."has_last_nam= e" =3D 'Y') 
=09   =09=09=09 = ;  and (a."has_first_name" =3D 'Y'))
      &n= bsp;            and ((b."tax_bnkrpt_dcsd_ind"= =3D 'N') 
=09=09=09= =09   and (b."govt_prison_ind" =3D 'N') 
=09=09=09=09   and (b= ."cstmr_prspct_ind" =3D 'Prospect'))
        =            and (( c."hspnc_lang_prfrnc_cval" = in ('B', 'E', 'X') ) 
=09=09=09=09   or (c."hspnc_lang_prfrnc_cval" is null));<= /div>
-- Explain output

 "Finalize Aggregate&nbs= p; (cost=3D32813309.28..32813309.29 rows=3D1 width=3D8)"
"  = ->  Gather  (cost=3D32813308.45..32813309.26 rows=3D8 width=3D= 8)"
"        Workers Planned: 8"
"&= nbsp;       ->  Partial Aggregate  (cost=3D3281= 2308.45..32812308.46 rows=3D1 width=3D8)"
"      &= nbsp;       ->  Merge Join  (cost=3D23870130.00= ..32759932.46 rows=3D20950395 width=3D8)"
"      &= nbsp;             Merge Cond: (a.individual_e= ntity_proxy_id =3D b.individual_entity_proxy_id)"
"    =                 ->  Sort&nb= sp; (cost=3D23870127.96..23922503.94 rows=3D20950395 width=3D8)"
= "                    &nbs= p;     Sort Key: a.individual_entity_proxy_id"
"  =                      = ;   ->  Hash Join  (cost=3D13533600.42..21322510.26 rows= =3D20950395 width=3D8)"
"           = ;                     Has= h Cond: (a.household_entity_proxy_id =3D c.household_entity_proxy_id)"
"                   = ;             ->  Parallel Seq Scan o= n prospect a  (cost=3D0.00..6863735.60 rows=3D22171902 width=3D16)"
"                  &nb= sp;                   Filter: = (((last_contacted_anychannel_dttm IS NULL) OR (last_contacted_anychannel_dt= tm < '2020-11-23 00:00:00'::timestamp without time zone)) AND (shared_pa= ddr_with_customer_ind =3D 'N'::bpchar) AND (profane_wrd_ind =3D 'N'::bpchar= ) AND (tmo_ofnsv_name_ind =3D 'N'::bpchar) AND (has_individual_address =3D = 'Y'::bpchar) AND (has_last_name =3D 'Y'::bpchar) AND (has_first_name =3D 'Y= '::bpchar))"
"              &n= bsp;                 ->  Ha= sh  (cost=3D10801715.18..10801715.18 rows=3D166514899 width=3D8)"
"                   = ;                   -> = ; Seq Scan on household_demographic c  (cost=3D0.00..10801715.18 rows= =3D166514899 width=3D8)"
"          &nbs= p;                     &n= bsp;           Filter: (((hspnc_lang_prfrnc_cval):= :text =3D ANY ('{B,E,X}'::text[])) OR (hspnc_lang_prfrnc_cval IS NULL))"
"                  &nb= sp; ->  Index Only Scan using indx_individual_demographic_prxyid_ta= xind_prspctind_prsnind on individual_demographic b  (cost=3D0.57..8019= 347.13 rows=3D286887776 width=3D8)"
"        =                   Index Cond: = ((tax_bnkrpt_dcsd_ind =3D 'N'::bpchar) AND (cstmr_prspct_ind =3D 'Prospect'= ::text) AND (govt_prison_ind =3D 'N'::bpchar))"
    &n= bsp;                    <= /div>

Tables ddl are = attached in dbfiddle -- Postgres 11 | db&= lt;>fiddle