[BUGS] Re: BUG #14780: PostgreSQL 9.6 selects a wrong plan duringaggregation against timestamp columns - Mailing list pgsql-bugs

From Greg Stark
Subject [BUGS] Re: BUG #14780: PostgreSQL 9.6 selects a wrong plan duringaggregation against timestamp columns
Date
Msg-id CAM-w4HOh9vxjzvpsz41SbP6qh13ANbL48iASGyTqWEG4fJZGRg@mail.gmail.com
Whole thread Raw
In response to [BUGS] BUG #14780: PostgreSQL 9.6 selects a wrong plan during aggregationagainst timestamp columns  (sogawa@yandex.ru)
List pgsql-bugs
On 16 August 2017 at 02:47,  <sogawa@yandex.ru> wrote:
>
>     select min(day) from log where user_id =
> 'ab056f5a-390b-41d7-ba56-897c14b679bf'

This is a classic database optimization problem that is difficult to
always get right. Whether to use an index on day to find the lowest
values and scan until you find the specified user_id or to scan all
the records for that user_id to find the minimum day will depend on
the number of records each user_id has and how they're distributed
across the days. If you have some users with many records then using
an index on user_id can perform terribly when those ids are
referenced.

The classic solution is to have an index on <user_id, day> and then
the database can look up the correct value in a single index probe.

These kinds of problems are better addressed to pgsql-general

-- 
greg


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs

pgsql-bugs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [BUGS] BUG #14784: www_fdw extension is vulnerable
Next
From: Виктор Пунин
Date:
Subject: [BUGS] centos 7 repository