pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hans Liebenberg <hans@cambrient.com>
To: pgsql-performance@postgresql.org
Subject: Substring search using "exists" with a space in the search term
Date: Tue, 03 Mar 2009 14:12:45 +0200
Message-ID: <49AD1EBD.1050105@cambrient.com> (raw)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<span id="intelliTxt">Hi,<br>
<br>
I have come across a weird bug (i think) in postgres 8.1.11 (possibly
others)<br>
<br>
Without going into my table structure detail I will demonstrate the
problem by showing the select statements:<br>
<br>
The following statement:<br>
SELECT count(*)<br>
FROM object o, object_version v, object_type ot <br>
where v.id = o.active_versionid and ot.id = o.object_typeid and
o.is_active ='t' and (o.is_archived = 'f' or o.is_archived is null) <br>
and o.is_published = 't' and ot.object_type_typeid &lt;&gt; 1 <br>
<br>
and exists (<br>
select ova.object_versionid from attribute_value av,
object_version_attribute ova where ova.attribute_valueid=av.id and
object_versionid = v.id <br>
and (upper(av.text_val) like <b>'%KIWI%'</b>) )<br>
<br>
<br>
runs fine and executes with success.<br>
BUT now this is the strange bit, if I have a space in my search term
then postgres hangs for an indefinite period: eg:<br>
<br>
SELECT count(*)<br>
FROM object o, object_version v, object_type ot <br>
where v.id = o.active_versionid and ot.id = o.object_typeid and
o.is_active ='t' and (o.is_archived = 'f' or o.is_archived is null) <br>
and o.is_published = 't' and ot.object_type_typeid &lt;&gt; 1 <br>
<br>
and exists (<br>
select ova.object_versionid from attribute_value av,
object_version_attribute ova where ova.attribute_valueid=av.id and
object_versionid = v.id <br>
and (upper(av.text_val) like <b>'%KIWI FRUIT%'</b>) )<br>
<br>
<br>
Yet, if I modify the "exists" to an "in" all works well , as follows<br>
<br>
SELECT count(*)<br>
FROM object o, object_version v, object_type ot <br>
where v.id = o.active_versionid and ot.id = o.object_typeid and
o.is_active ='t' and (o.is_archived = 'f' or o.is_archived is null) <br>
and o.is_published = 't' and ot.object_type_typeid &lt;&gt; 1 <br>
<br>
and v.id in (<br>
select ova.object_versionid from attribute_value av,
object_version_attribute ova where ova.attribute_valueid=av.id <br>
and (upper(av.text_val) like <b>'%KIWI FRUIT%'</b>) )<br>
<br>
<br>
So my question is why would a space character cause postgres to hang
when using the exists clause????<br>
<br>
I have tested this on several different servers and mostly get the same
result (v8.08 and v8.1.11) , when I check the execution plan for either
query (space or no space) they are identical.<br>
<br>
An upgrade to 8.3 fixes this, but I am still curious as to what could
cause such bizarre behavior.<br>
<br>
Thanks<br>
Hans</span>
</body>
</html>





Message-ID: <49AD1EBD.1050105@cambrient.com>
Permalink:  ../49AD1EBD.1050105@cambrient.com/
Also on:    postgresql.org/message-id/49AD1EBD.1050105@cambrient.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: hans@cambrient.com
  Subject: Re: Substring search using "exists" with a space in the search term
  In-Reply-To: <49AD1EBD.1050105@cambrient.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