Skip site navigation (1) Skip section navigation (2)

Slow performance with no apparent reason

From: Yonatan Goraly <ygoraly(at)sbcglobal(dot)net>
To: pgsql-general(at)postgresql(dot)org, pgsql-performance(at)postgresql(dot)org
Subject: Slow performance with no apparent reason
Date: 2003-10-25 21:25:37
Message-ID: 3F9AEA51.2070701@sbcglobal.net (view raw or flat)
Thread:
Lists: pgsql-generalpgsql-performance
I am in the process of  adding PostgreSQL support for an application, in 
addition to Oracle and MS SQL.
I am using PostgreSQL version 7.3.2, Red Hat 9.0 on Intel Pentium III board.

I have a query that generally looks like this:

SELECT t1.col1, t2.col1 FROM t1, t2 WHERE t1.x=t2.y AND t2.p='string' 
AND t2.q=1

This query is strikingly slow (about 100 sec when both t1 and t2 has 
about 1,200 records, compare with less than 4 sec with MS SQL and Oracle)

The strange thing is that if I remove one of the last 2 conditions 
(doesn't matter which one), I get the same performance like with the 
other databases.
Since in this particular case both conditions ( t2.p='string', t2.q=1) 
are not required, I can't understand why having both turns the query so 
slow.
A query on table t2 alone is fast with or without the 2 conditions.

I tired several alternatives, this one works pretty well:

SELECT t1.col1, t2.col1 FROM t1, t2 WHERE t1.x=t2.y AND
     EXISTS (
             SELECT * FROM t2 t2a WHERE t2a.p='string' AND t2a.q=1 AND 
t2a.y=t2.y )

Since the first query is simpler than the second, it seems to me like a bug.

Please advise

Yonatan

Responses

pgsql-performance by date

Next:From: Yonatan GoralyDate: 2003-10-25 22:26:22
Subject: Re: Slow performance with no apparent reason
Previous:From: Hannu KrosingDate: 2003-10-25 21:13:36
Subject: Re: Performance Concern

pgsql-general by date

Next:From: Yonatan GoralyDate: 2003-10-25 22:26:22
Subject: Re: Slow performance with no apparent reason
Previous:From: darrenDate: 2003-10-25 19:15:56
Subject: Re: no records returned

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group