pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Alexander Staubo <alex@purefiction.net>
To: Guillaume Smet <guillaume.smet@gmail.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: Estimation problem with a LIKE clause containing a /
Date: Wed, 7 Nov 2007 14:25:40 +0100
Message-ID: <88daf38c0711070525r1e7d6daft56970045de0ec8f4@mail.gmail.com> (raw)
In-Reply-To: <1d4e0c10711070453q214f089cpd144cbb5193d3c4f@mail.gmail.com>
References: <1d4e0c10711070453q214f089cpd144cbb5193d3c4f@mail.gmail.com>

On 11/7/07, Guillaume Smet <guillaume.smet@gmail.com> wrote:
> While studying a query taking forever after an ANALYZE on a never
> analyzed database (a bad estimate causes a nested loop on a lot of
> tuples), I found the following problem:
[snip]
>  Total runtime: 31.097 ms
[snip]
>  Total runtime: 31.341 ms
[snip]
>  Total runtime: 34.778 ms
>
> Which is a really good estimate.

That's a difference of less than *three milliseconds* -- a difference
probably way within the expected overhead of running "explain
analyze". Furthermore, all three queries use the same basic plan: a
sequential scan with a filter. At any rate you're microbenchmarking in
a way that is not useful to real-world queries. In what way are these
timings a problem?

Have you tried using an index which supports prefix searches? The
text_pattern_ops operator class lets yo do this with a plain B-tree
index:

  create index cms_items_ancestors_index on cms_items (ancestors
text_pattern_ops);
  analyze cms_items;

Now all "like 'prefix%'" queries should use the index.

Alexander.



view thread (21+ messages)  latest in thread

Message-ID: <88daf38c0711070525r1e7d6daft56970045de0ec8f4@mail.gmail.com>
Permalink:  ../88daf38c0711070525r1e7d6daft56970045de0ec8f4@mail.gmail.com/
Also on:    postgresql.org/message-id/88daf38c0711070525r1e7d6daft56970045de0ec8f4@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: alex@purefiction.net, guillaume.smet@gmail.com
  Subject: Re: Estimation problem with a LIKE clause containing a /
  In-Reply-To: <88daf38c0711070525r1e7d6daft56970045de0ec8f4@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