Re: Estimation problem with a LIKE clause containing a /

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11/7/07, Guillaume Smet <guillaume.smet@xxxxxxxxx> 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.

---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq

[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux