pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <dave@fastcrypt.com>
To: Jan de Visser <jdevisser@digitalfairway.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Prepared statement not using an index
Date: Fri, 2 Sep 2005 09:12:22 -0400
Message-ID: <663FA0A4-DA16-4C7A-96F5-373E5AA55F2E@fastcrypt.com> (raw)
In-Reply-To: <200509020841.51212.jdevisser@digitalfairway.com>
References: <1D63F6F8-331A-46E4-BF58-1D502A12AC53@pharmaline.de>
	<4317863E.8090001@opencloud.com>
	<0C0329E7-1A4B-478C-A003-5C605496FC19@pharmaline.de>
	<200509020841.51212.jdevisser@digitalfairway.com>

You can actually get postgres to use an index in like %bar

postgres has functional indexes so you need to create an index on  
reverse(col) and then use that function in the select statement.

It's been a while, the details of actual implementation are sketchy,  
perhaps the performance list would be more appropriate.

Dave
On 2-Sep-05, at 8:41 AM, Jan de Visser wrote:

> On Friday 02 September 2005 01:49, Guido Neitzer wrote:
>
>> On 02.09.2005, at 0:52 Uhr, Oliver Jowett wrote:
>>
>>>> I use PostgreSQL 8.0.3 on Mac OS X and the JDBC driver 8.0-312
>>>> JDBC 3.
>>>>
>>>> After a lot of other things, I tried using a 7.4 driver and with
>>>> this,
>>>> the index is used in both cases.
>>>>
>>>
>>> The 8.0 drivers pass parameters individually to the backend  
>>> (analogous
>>> to using PREPARE/EXECUTE), while the 7.4 drivers do textual
>>> substitution
>>> into the query text. This can result in different query plans as
>>> you've
>>> discovered.
>>>
>>
>> This sounds like a bug to me. If a simple substitution of the
>> placeholders with actual values ends with different query plan, my
>> understanding is, that there is something broken in the query
>> planner ...
>>
>
> Well, no. The OP has a 'foo LIKE ?' in there. If his 'actual' query is
> something like 'foo LIKE bar%', the planner is able to determine  
> that using
> an index on foo would help, whereas in the parameterized form he  
> cannot do
> that, since 'foo LIKE %bar' would not be helped by that index.
>
> In general, things like 'LIKE ?' will be killing performance  
> anyway, for
> exactly that reason.
>
>
>>
>> cug
>>
>
> JdV!!
>
> -- 
> --------------------------------------------------------------
> Jan de Visser                     jdevisser@digitalfairway.com
>
>                 Baruk Khazad! Khazad ai-menu!
> --------------------------------------------------------------
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 6: explain analyze is your friend
>
>




view thread (5+ messages)

Message-ID: <663FA0A4-DA16-4C7A-96F5-373E5AA55F2E@fastcrypt.com>
Permalink:  ../663FA0A4-DA16-4C7A-96F5-373E5AA55F2E@fastcrypt.com/
Also on:    postgresql.org/message-id/663FA0A4-DA16-4C7A-96F5-373E5AA55F2E@fastcrypt.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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: dave@fastcrypt.com, jdevisser@digitalfairway.com
  Subject: Re: Prepared statement not using an index
  In-Reply-To: <663FA0A4-DA16-4C7A-96F5-373E5AA55F2E@fastcrypt.com>
  References: <1D63F6F8-331A-46E4-BF58-1D502A12AC53@pharmaline.de> <4317863E.8090001@opencloud.com> <0C0329E7-1A4B-478C-A003-5C605496FC19@pharmaline.de> <200509020841.51212.jdevisser@digitalfairway.com> <663FA0A4-DA16-4C7A-96F5-373E5AA55F2E@fastcrypt.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