From: Tomas Vondra <tomas.vondra@enterprisedb.com>
To: Mohan Radhakrishnan <radhakrishnan.mohan@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: BRIN index on timestamptz
Date: Sat, 24 Apr 2021 02:06:17 +0200
Message-ID: <abf9aacc-cd77-b08d-311e-7bc932f4ddd8@enterprisedb.com> (raw)
In-Reply-To: <CAOoXFP_YK8Mo80YB4-bQmKZtAkjHgGOBvGm67=P7gtoqoQNuTw@mail.gmail.com>
References: <CAOoXFP_YK8Mo80YB4-bQmKZtAkjHgGOBvGm67=P7gtoqoQNuTw@mail.gmail.com>
On 4/23/21 10:31 AM, Mohan Radhakrishnan wrote:
> Hi,
> I am planning to use as I search based on timestamptz fields.
> There are millions of records.I refer
> https://www.percona.com/blog/2019/07/16/brin-index-for-postgresql-dont-forget-the-benefits
> <https://www.percona.com/blog/2019/07/16/brin-index-for-postgresql-dont-forget-the-benefits;
>
> I execute this on the AWS RDS instance. Is there something in the plan I
> should pay attention to ? I notice the Execution Time.
>
> Thanks,
> Mohan
>
> INSERT INTO testtab (id, date, level, msg) SELECT g, CURRENT_TIMESTAMP +
> ( g || 'minute' ) :: interval, random() * 6, md5(g::text) FROM
> generate_series(1,8000000) as g;
Two things:
a) You need to do ANALYZE, otherwise there are no statistics the
optimizer could use (which is why the row estimates in the plans are
entirely bogus).
b) BRIN indexes don't work on random data, because the whole idea is
about eliminating large blocks of data (e.g. 1MB). But with random data
that's not going to happen, because each such range will match anything.
Which is why seqscan is a bit faster than when using BRIN index.
regards
--
Tomas Vondra
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
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: tomas.vondra@enterprisedb.com, radhakrishnan.mohan@gmail.com
Subject: Re: BRIN index on timestamptz
In-Reply-To: <abf9aacc-cd77-b08d-311e-7bc932f4ddd8@enterprisedb.com>
References: <CAOoXFP_YK8Mo80YB4-bQmKZtAkjHgGOBvGm67=P7gtoqoQNuTw@mail.gmail.com> <abf9aacc-cd77-b08d-311e-7bc932f4ddd8@enterprisedb.com>
* 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