pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: BRIN index on timestamptz
Date: Mon, 26 Apr 2021 14:29:04 +0200
Message-ID: <20210426122904.GA26434@hjp.at> (raw)
In-Reply-To: <CAOoXFP9Y=Sb=StzyiqUi4GnG1HDpBWeog7yQGnHFe4U19LJbjA@mail.gmail.com>
References: <CAOoXFP_YK8Mo80YB4-bQmKZtAkjHgGOBvGm67=P7gtoqoQNuTw@mail.gmail.com>
	<CAHOFxGosyh6snT__nHdKXDxtx9eR5BsY5+1huJKE_SYuZf4Xqw@mail.gmail.com>
	<CAOoXFP-tXjVrjV3r9cz5s_s5u2C8krbZ+D55zkfWJ6bFSZFd+w@mail.gmail.com>
	<CAHOFxGp_Fq3mWPAPf2heNRLN3yfQKATRmb7PZvY45iTAkUM0eQ@mail.gmail.com>
	<CAOoXFP8sxX1Qe7XeAkdG75mWACDR7Ko50W+eK9Zvf-0qUjHG8A@mail.gmail.com>
	<CAOoXFP9Y=Sb=StzyiqUi4GnG1HDpBWeog7yQGnHFe4U19LJbjA@mail.gmail.com>

On 2021-04-26 17:23:49 +0530, Mohan Radhakrishnan wrote:
> Isn't a btree subject to these effects ? So when I update ENUMS for each
> timestamptz, btree indexes are less susceptible
> to the effects than BRIN indexes  ?

A btree index contains one entry for each record which points to that
records. If you select a small range of values via a btree index in the
worst case you will have one random seek per row. This is not ideal, but
doesn't matter much if the number of records is low.

A BRIN index contains a minimum and maximum value per range of blocks.
In the worst case (each block range contains a totally random sample of
values) the minimum for each block range will be near the minimum of the
whole table and the maximum of each block range will be near the maximum
for the whole table. So when searching, the BRIN index will exclude very
few block ranges.

So a BRIN index will work best when each block range contains only a
small range of indexed values.

If you index on a timestamp this will work nicely if you either don't
update rows at all after inserting them or only update them for a short
time relative to the total time spanned by the table. So if your table
contains say records from the last year and records are normally only
updated after one or two days after being created that would probably
still work quite well. If there is a substantial number of records which
is still updated after a year, it probably won't work at all.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp@hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (8+ messages)

Message-ID: <20210426122904.GA26434@hjp.at>
Permalink:  ../20210426122904.GA26434@hjp.at/
Also on:    postgresql.org/message-id/20210426122904.GA26434@hjp.at

 · 

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: hjp-pgsql@hjp.at
  Subject: Re: BRIN index on timestamptz
  In-Reply-To: <20210426122904.GA26434@hjp.at>
  References: <CAOoXFP_YK8Mo80YB4-bQmKZtAkjHgGOBvGm67=P7gtoqoQNuTw@mail.gmail.com> <CAHOFxGosyh6snT__nHdKXDxtx9eR5BsY5+1huJKE_SYuZf4Xqw@mail.gmail.com> <CAOoXFP-tXjVrjV3r9cz5s_s5u2C8krbZ+D55zkfWJ6bFSZFd+w@mail.gmail.com> <CAHOFxGp_Fq3mWPAPf2heNRLN3yfQKATRmb7PZvY45iTAkUM0eQ@mail.gmail.com> <CAOoXFP8sxX1Qe7XeAkdG75mWACDR7Ko50W+eK9Zvf-0qUjHG8A@mail.gmail.com> <CAOoXFP9Y=Sb=StzyiqUi4GnG1HDpBWeog7yQGnHFe4U19LJbjA@mail.gmail.com> <20210426122904.GA26434@hjp.at>

* 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