pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Allen Landsidel <alandsidel@gmail.com>
To: Postgresql Performance <pgsql-performance@postgresql.org>
Subject: Re: Strange (?) Index behavior?
Date: Fri, 5 Nov 2004 10:32:43 -0500
Message-ID: <88f1825a041105073245010974@mail.gmail.com> (raw)
In-Reply-To: <1099667258.1647.827.camel@home>
References: <88f1825a041105063955367088@mail.gmail.com>
	<1099667258.1647.827.camel@home>

On Fri, 05 Nov 2004 10:07:38 -0500, Rod Taylor <pg@rbt.ca> wrote:
> > It seems to me that a query saying "SELECT column FROM table WHERE
> > column LIKE 'AA%';" should be just as fast or very close to the first
> > case up above.  However, explain tells me that this query is not using
> > the index above, which is what's not making sense to me.
> 
> It looks for an exact expression match, and doesn't know about values
> which are equal.
> 
> You can provide both clauses.
> 
> WHERE column LIKE 'A%' and column LIKE 'AA%';

I see.  That's not really optimal either however as you can probably
see already.. adding AB, AC, AD...AZ is likely to be pretty bogus and
at the least is time consuming.

Matt Clark was right that it will use a standard index, which is in
fact what it's doing right now in the "SELECT column WHERE column LIKE
'AA%';" case.. however as I said, the table has millions of rows --
currently about 76 million, so even a full index scan is fairly slow.

The machine isn't all that hot performance wise either, a simple dual
800 P3 with a single 47GB Seagate SCSI.  The only redeeming factor is
that it has 2GB of memory, which I'm trying to make the most of with
these indexes.

So assuming this partial index situation isn't going to change (it
seems like it would be a fairly simple fix for someone that knows the
pg code however) I'm wondering if a subselect may speed things up any,
so I'm going to investigate that next.

Perhaps.. SELECT column FROM (SELECT column FROM table WHERE column
LIKE 'A%') AS sq WHERE column LIKE 'AA%';

The query planner thinks this will be pretty fast indeed, and does use
the index I am after.

OS is, of course, FreeBSD.



view thread (27+ messages)  latest in thread

Message-ID: <88f1825a041105073245010974@mail.gmail.com>
Permalink:  ../88f1825a041105073245010974@mail.gmail.com/
Also on:    postgresql.org/message-id/88f1825a041105073245010974@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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: alandsidel@gmail.com
  Subject: Re: Strange (?) Index behavior?
  In-Reply-To: <88f1825a041105073245010974@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