pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Kretschmer <andreas@a-kretschmer.de>
To: pgsql-general@lists.postgresql.org
Subject: Re: *Regarding brin_index on required column of the table
Date: Thu, 20 Sep 2018 15:08:32 +0200
Message-ID: <897f824e-a6d5-9c2d-29b3-84e2ee9e4cbf@a-kretschmer.de> (raw)
In-Reply-To: <CAJCZkoK4yYUXjPJMbxEzkbckuEs8QAqcSvAn-JcWS-vp2_mHpQ@mail.gmail.com>
References: <CAJCZko++xfddUpwC34FwPRvoK_9mEBecYY2eKUyvHnqNanND5w@mail.gmail.com>
	<bb757960-8a9a-910b-c734-3e67171f8815@a-kretschmer.de>
	<CAJCZkoLjQJPeK4RhaJo1L0J6SS9otQ=CNf=Kck3NK4qCcJmNZQ@mail.gmail.com>
	<1962c603-099a-e947-e376-548ae4b68f19@a-kretschmer.de>
	<CAJCZkoJsWh64gaNia84b-kJgUgiBSVTD+KvYoH8Yo+1+-Cuhdg@mail.gmail.com>
	<410135d5-7791-58ed-2366-a358d7f95d79@a-kretschmer.de>
	<CAJCZkoL6zBga0VMDD-rRmXX+YUTiGduSPShQQFkwZWewwRjyNw@mail.gmail.com>
	<CAJCZkoL0Lq3MB2xkBmHD-MGh+=+yV842TEmYyKo4Y++Zp_zBLw@mail.gmail.com>
	<CAJCZkoK4yYUXjPJMbxEzkbckuEs8QAqcSvAn-JcWS-vp2_mHpQ@mail.gmail.com>



Am 20.09.2018 um 13:11 schrieb Durgamahesh Manne:
> Query was executed at less time without distinct
>
> As well as query was taking around 7 minutes to complete execution 
> with distinct
>
>  select   distinct  sub_head."vchSubmittersCode" ,rec."vchFileName" , 
> rec."vchCusipFundIDSubFundID" , rec."vchFundUnitPrice"  ,  
> sub_head."vchValuationDate" ,rec."vchAdvisorLabel" from  table1 rec 
> join table2 sub_head on 
> rec."vchSubmittersCode"=sub_head."vchSubmittersCode" where 
> rec."bFetch"=false and sub_head."bFetch"=false ;
>
> I need to execute above distinct query at less time as distinct query 
> was taking more time to execute  even i have created indexes on 
> required columns of the tables
>

 >  Unique  (cost=5871873.64..6580630.73 rows=7400074 width=89) (actual 
time=326397.551..389515.863 rows=3700000 
loops=1)                                                 |
 > |   ->  Sort  (cost=5871873.64..5973124.65 rows=40500405 width=89) 
(actual time=326397.550..372470.846 rows=40500000 
loops=1)                                                  |
 > |         Sort Key: sub_head."vchSubmittersCode", rec."vchFileName", 
rec."vchCusipFundIDSubFundID", rec."vchFundUnitPrice", 
sub_head."vchValuationDate", rec."vchAdvisorLabel" |
 > |         Sort Method: external merge  Disk: 
3923224kB                                                  |


as you can see: there are 40.500.000 rows to sort to filter out 
duplicate rows, the result contains 'only' 3.700.000 rows. But for this 
step the database needs nearly 4TB on-disk. This will, of course, need 
some time.

If you have enough ram you can try to set work_mem to 5 or 6 GB to 
change the plan to a in-memory - sort. But keep in mind, this is 
dangerous! If the machine don't have enough free ram the kernal can 
decide to Out-Of-Memory - killing processes.

What kind of disks do you have? Maybe you can use a separate fast SSD as 
temp_tablespaces?


Regards, Andreas
-- 

2ndQuadrant - The PostgreSQL Support Company.
www.2ndQuadrant.com





view thread (24+ messages)  latest in thread

Message-ID: <897f824e-a6d5-9c2d-29b3-84e2ee9e4cbf@a-kretschmer.de>
Permalink:  ../897f824e-a6d5-9c2d-29b3-84e2ee9e4cbf@a-kretschmer.de/
Also on:    postgresql.org/message-id/897f824e-a6d5-9c2d-29b3-84e2ee9e4cbf@a-kretschmer.de

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andreas@a-kretschmer.de
  Subject: Re: *Regarding brin_index on required column of the table
  In-Reply-To: <897f824e-a6d5-9c2d-29b3-84e2ee9e4cbf@a-kretschmer.de>
  References: <CAJCZko++xfddUpwC34FwPRvoK_9mEBecYY2eKUyvHnqNanND5w@mail.gmail.com> <bb757960-8a9a-910b-c734-3e67171f8815@a-kretschmer.de> <CAJCZkoLjQJPeK4RhaJo1L0J6SS9otQ=CNf=Kck3NK4qCcJmNZQ@mail.gmail.com> <1962c603-099a-e947-e376-548ae4b68f19@a-kretschmer.de> <CAJCZkoJsWh64gaNia84b-kJgUgiBSVTD+KvYoH8Yo+1+-Cuhdg@mail.gmail.com> <410135d5-7791-58ed-2366-a358d7f95d79@a-kretschmer.de> <CAJCZkoL6zBga0VMDD-rRmXX+YUTiGduSPShQQFkwZWewwRjyNw@mail.gmail.com> <CAJCZkoL0Lq3MB2xkBmHD-MGh+=+yV842TEmYyKo4Y++Zp_zBLw@mail.gmail.com> <CAJCZkoK4yYUXjPJMbxEzkbckuEs8QAqcSvAn-JcWS-vp2_mHpQ@mail.gmail.com> <897f824e-a6d5-9c2d-29b3-84e2ee9e4cbf@a-kretschmer.de>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox