Relative performance of prefix and suffix string matching - Mailing list pgsql-general

From Andrew Rose
Subject Relative performance of prefix and suffix string matching
Date
Msg-id 632BF61B4D0DEC4AAD03109304ADD5761912F6BF@ENFIRHMBX1.datcon.co.uk
Whole thread Raw
Responses Re: Relative performance of prefix and suffix string matching  (Tore Halvorsen <tore.halvorsen@gmail.com>)
Re: Relative performance of prefix and suffix string matching  (Alban Hertroys <haramrae@gmail.com>)
List pgsql-general
Basic Question: In text fields, is prefix matching significantly faster than suffix matching?

Background:

I'm designing a database schema where a common operation will be "search for substring x either at the beginning or end
ofcolumn 'str'". 

1. I could have the client issue...

SELECT * FROM tbl WHERE str LIKE 'x%' OR str LIKE '%x'

2. Alternatively, I could store column 'rev_str' as a reversed version of column 'str' and have the client produce a
reversedversion of x on each query (call it r).  Then the client would issue... 

SELECT * FROM tbl WHERE str LIKE 'x%' OR rev_str LIKE 'r%'

...which would use prefix matches only instead of requiring suffix matches.  Since I've seen this form used by others,
Iwas wondering if it's necessary - i.e. if databases really do perform prefix matching faster? 

3. Is there a solution I'm unaware of with even better performance?

Thanks,

Andrew

pgsql-general by date:

Previous
From: hamann.w@t-online.de
Date:
Subject: Re: looking for a faster way to do that
Next
From: c k
Date:
Subject: Re: Date time value error in Ms Access using pass through queries