Re: Estimation problem with a LIKE clause containing a / - Mailing list pgsql-performance

From Alexander Staubo
Subject Re: Estimation problem with a LIKE clause containing a /
Date
Msg-id 88daf38c0711070525r1e7d6daft56970045de0ec8f4@mail.gmail.com
Whole thread Raw
In response to Estimation problem with a LIKE clause containing a /  ("Guillaume Smet" <guillaume.smet@gmail.com>)
Responses Re: Estimation problem with a LIKE clause containing a /  ("Guillaume Smet" <guillaume.smet@gmail.com>)
List pgsql-performance
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.

pgsql-performance by date:

Previous
From: "Guillaume Smet"
Date:
Subject: Estimation problem with a LIKE clause containing a /
Next
From: "Guillaume Smet"
Date:
Subject: Re: Estimation problem with a LIKE clause containing a /