Re: Strange select query

From: lbayuk(at)mindspring(dot)com (ljb)
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Strange select query
Date: 2001-09-14 22:37:20
Message-ID: 9nu0qv$1o8b$1@news.tht.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

bobson(at)alpha(dot)pl wrote:
>Hellow,
>
>I notice wired behavior of backend,
>
>for instance I've 3 tables TA, TB, TC with about 1k of records each,
>
>and I do something like that:
>
>select * from TA as a, TB as b, TC as c where
>position('some text' in a.textfield)>0 or
>(position('some text' in b.textfield)>0 and a.index=b.referencefield) or
>(position('some text' in c.textfield)>0 and a.index=b.referencefield
>and b.other_referencefield=c.index);
>
>the backend start to execute query, but it seems to be 'never ending
>story' because after 15 minutes of work I steel haven't result, and
>backend still was eating my RAM. I know that this query is ugly and
>bad, but I think backend will reject such query at parsing.

It seems to me that the query is valid, but is basically doing a
cross join or cartesian product join on 3 tables. This means all
combinations of rows from all 3 tables needs to be looked at. With
1000 rows per table, that is 1,000,000,000 rows that the database
needs to look at to see if it matches your other conditions.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Erol Öz 2001-09-14 22:41:43 Ynt: get certain # of recs
Previous Message Stephan Szabo 2001-09-14 22:29:11 Re: Postgresql data backup