Re: [GENERAL] Perfomance of IN-clause with many elements and possiblesolutions - Mailing list pgsql-general

From Dmitry Lazurkin
Subject Re: [GENERAL] Perfomance of IN-clause with many elements and possiblesolutions
Date
Msg-id a2931f79-2c5b-f35b-a790-4ae15e2139db@gmail.com
Whole thread Raw
In response to Re: [GENERAL] Perfomance of IN-clause with many elements andpossible solutions  (PT <wmoran@potentialtech.com>)
Responses Re: [GENERAL] Perfomance of IN-clause with many elements andpossible solutions  (PT <wmoran@potentialtech.com>)
List pgsql-general
On 07/24/2017 01:40 AM, PT wrote:
> In this example you count approximately 40,000,000 values, which is
> about 40% of the table.
4 000 000 (:

> If you really need these queries to be faster, I would suggest
> materializing the data, i.e. create a table like:
>
> CREATE TABLE id_counts (
>  id BIGINT PRIMARY KEY,
>  num BIGINT
> )
>
> Then use a trigger or similar technique to keep id_counts in sync
> with the id table. You can then run queries of the form:
>
> SELECT sum(num) FROM id_counts WHERE id IN :values:
>
> which I would wager houseboats will be significantly faster.
I use count only for example because it uses seqscan. I want optimize
IN-clause ;-).

Thanks.



pgsql-general by date:

Previous
From: Achilleas Mantzios
Date:
Subject: Re: [GENERAL] Dealing with ordered hierarchies
Next
From: Dmitry Lazurkin
Date:
Subject: Re: [GENERAL] Perfomance of IN-clause with many elements and possiblesolutions