pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Gregory Stark <stark@enterprisedb.com>
Cc: mark@mark.mielke.cc, Mark Lewis <mark.lewis@mir3.com>
Cc: James Mansion <james@mansionfamily.plus.com>
Cc: Magnus Hagander <magnus@hagander.net>
Cc: Alexander Staubo <alex@purefiction.net>
Cc: Andy <frum@ar-sd.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: LIKE search and performance
Date: Fri, 25 May 2007 19:13:14 +0100
Message-ID: <4657273A.3080005@archonet.com> (raw)
In-Reply-To: <87y7jckcp6.fsf@oxford.xeocode.com>
References: <009501c79d4c$445428f0$0b00a8c0@mpsro.dom>
	<88daf38c0705230905u1a981102k691b47bd36011a80@mail.gmail.com>
	<4655DE75.4080506@mansionfamily.plus.com>
	<4655E64B.5050503@hagander.net>
	<4655FB8A.1040707@mansionfamily.plus.com>
	<1180040560.31471.262.camel@archimedes>
	<20070524215450.GA3858@mark.mielke.cc>
	<46569AA5.10205@archonet.com>
	<20070525141630.GA12162@mark.mielke.cc>
	<4657023A.20209@archonet.com>
	<20070525165633.GA13579@mark.mielke.cc>
	<46571CEC.7070202@archonet.com>
	<87y7jckcp6.fsf@oxford.xeocode.com>

Gregory Stark wrote:
> "Richard Huxton" <dev@archonet.com> writes:
> 
>> Now you and I can look at a substring and probably make a good guess how common
>> it is (assuming we know the targets are British surnames or Japanese towns). PG
>> needs one number - or rather, it picks one number for each length of
>> search-string (afaik).
> 
> I don't think that's true. Postgres calculates the lower and upper bound
> implied by the search pattern and then uses the histogram to estimate how
> selective that range is. It's sometimes surprisingly good but obviously it's
> not perfect.

Sorry - I'm obviously picking my words badly today.

I meant for the "contains" substring match. It gives different (goes 
away and checks...yes) predictions based on string length. So it guesses 
that LIKE '%aaa%' will match more than LIKE '%aaaa%'. Of course, if we 
were matching surnames you and I could say that this is very unlikely, 
but without some big statistics table I guess there's not much more PG 
can do.

For a trailing wildcard LIKE 'aaa%' it can and does as you say convert 
this into something along the lines of (>= 'aaa' AND < 'aab'). Although 
IIRC that depends if your locale allows such (not sure, I don't really 
use non-C/non-English locales enough).

-- 
   Richard Huxton
   Archonet Ltd



view thread (29+ messages)  latest in thread

Message-ID: <4657273A.3080005@archonet.com>
Permalink:  ../4657273A.3080005@archonet.com/
Also on:    postgresql.org/message-id/4657273A.3080005@archonet.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: dev@archonet.com, stark@enterprisedb.com, mark.lewis@mir3.com, james@mansionfamily.plus.com, magnus@hagander.net, alex@purefiction.net, frum@ar-sd.net
  Subject: Re: LIKE search and performance
  In-Reply-To: <4657273A.3080005@archonet.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