pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Jeremy Finzel <finzelj@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: Aggregate not using BRIN index on timestamp
Date: Mon, 05 Aug 2019 11:53:47 -0400
Message-ID: <2667.1565020427@sss.pgh.pa.us> (raw)
In-Reply-To: <20190805154238.GA7309@alvherre.pgsql>
References: <20190805154238.GA7309@alvherre.pgsql>

Alvaro Herrera <alvherre@2ndquadrant.com> writes:
> For btrees, we have planagg.c which transforms min() and max() into
> subqueries (SELECT .. WHERE ... ORDER BY .. LIMIT 1).

> In a BRIN index, you could execute the search by scanning the index to
> determine which ranges contain the least/greatest values, and then using
> a bitmap scan to scan those.  I'm not sure that this is a transformation
> that can be applied cleanly, since that thing I describe doesn't look to
> be a "subquery".  But maybe it can -- I think you'd need a special
> executor node.

FWIW, I suspect the hard part would be dealing with cases where the
extremal ranges (according to the index) contain no live tuples
(according to the query's snapshot).  The btree case handles the
invisible-tuples problem by continuing a scan started at the index
endpoint until it finds a visible tuple --- which, in the worst case,
can take a long time.  It's not obvious to me what you'd do with
BRIN.

			regards, tom lane





view thread (7+ messages)  latest in thread

Message-ID: <2667.1565020427@sss.pgh.pa.us>
Permalink:  ../2667.1565020427@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2667.1565020427@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, alvherre@2ndquadrant.com, finzelj@gmail.com
  Subject: Re: Aggregate not using BRIN index on timestamp
  In-Reply-To: <2667.1565020427@sss.pgh.pa.us>
  References: <20190805154238.GA7309@alvherre.pgsql> <2667.1565020427@sss.pgh.pa.us>

* 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