pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vladimir Sitnikov <sitnikov.vladimir@gmail.com>
To: Andrus <kobruleht2@hot.ee>
Cc: pgsql-performance@postgresql.org
Subject: Re: Increasing select max(datecol) from bilkaib where datecol<=date'2008-11-01' and (cr='00' or db='00') speed
Date: Wed, 12 Nov 2008 11:26:23 -0800
Message-ID: <1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.com> (raw)
In-Reply-To: <gff602$1ebo$1@news.hub.org>
References: <gff26k$2etc$1@news.hub.org>
	<1d709ecc0811120928n3c183df5kb7b7d50dee6f73ed@mail.gmail.com>
	<alpine.DEB.1.10.0811121730500.4666@aragorn.flymine.org>
	<gff602$1ebo$1@news.hub.org>

>
> This query finds initial balance date befeore given date.

If you are not interested in other balances except initial ones (the ones
that have '00') the best way is to create partial indices that I have
suggested.
That will keep size of indices small, while providing good performance
(constant response time)


> bilkaib table contains several year transactions so it is large.
>
That is not a problem for the particular case. However, when you evaluate
query performance, it really makes sense giving number of rows in each table
(is 100K rows a "large" table? what about 10M rows?)  and other properties
of the data stored in the table (like number of rows that have cr='00')


> Alternatively if you create an index on (cr, bilkaib) and one on (db,
> bilkaib) then you will be able to use other values in the query too.
>
That means if you create one index on biklaib (cr, datecol) and another
index on (db, datecol) you will be able to improve queries like
select greatest(
   (select max(date) from bilkaib where datecol<=date'2008-11-01' and
cr=XXX),
   (select max(date) from bilkaib where datecol<=date'2008-11-01' and
db=YYY)).
with arbitrary XXX and YYY. I am not sure if you really want this.


> I'm sorry I do'nt understand this.
> What does the (cr, bilkaib) syntax mean?

I believe that should be read as (cr, datecol).



> Should I create two functions indexes and re-write query as Vladimir
> suggests or is there better appoach ?

I am afraid PostgreSQL is not smart enough to rewrite query with "or" into
two separate index scans. There is no way to improve the query significantly
without rewriting it.

Note:  for this case indices on (datecol), (cr) and (db) are not very
helpful.

Regards,
Vladimir Sitnikov

view thread (9+ messages)  latest in thread

Message-ID: <1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.com>
Permalink:  ../1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.com/
Also on:    postgresql.org/message-id/1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.com

 · 

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-performance@postgresql.org
  Cc: sitnikov.vladimir@gmail.com, kobruleht2@hot.ee
  Subject: Re: Increasing select max(datecol) from bilkaib where datecol<=date'2008-11-01' and (cr='00' or db='00') speed
  In-Reply-To: <1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.com>
  References: <gff26k$2etc$1@news.hub.org> <1d709ecc0811120928n3c183df5kb7b7d50dee6f73ed@mail.gmail.com> <alpine.DEB.1.10.0811121730500.4666@aragorn.flymine.org> <gff602$1ebo$1@news.hub.org> <1d709ecc0811121126k4558db13m88c959188c3a9c0f@mail.gmail.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