On Mon, 15 Jun 2020 at 10:46, Nagaraj Raj <nagaraj.sf@xxxxxxxxx> wrote: > CREATE TABLE test1 > ( ... > CONSTRAINT pk_i_entity_proxy_id PRIMARY KEY (individual_entity_proxy_id) > > ); > CREATE TABLE test2 > ( ... > CONSTRAINT pk_entity_proxy_id PRIMARY KEY (individual_entity_proxy_id) > ); > > > User query: > > explain analyze select COUNT(*) as "DII_1" > from ( select distinct table0."individual_entity_proxy_id" as "INDIVIDUAL_ENTITY_PROXY_ID" > from test1 table0 > inner join test2 table1 > on table0."individual_entity_proxy_id" = table1."individual_entity_proxy_id" Why do you use "select distinct". It seems to me that you're putting a distinct clause on the primary key of test1 and joining to another table in a way that cannot cause duplicates. I imagine dropping that distinct will speed up the query quite a bit. David