pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
simpler query still significantly slower
3+ messages / 3 participants
[nested] [flat]

* simpler query still significantly slower
@ 2001-05-23 08:15  twanger@smartvia.de
  0 siblings, 2 replies; 3+ messages in thread

From: twanger@smartvia.de @ 2001-05-23 08:15 UTC (permalink / raw)
  To: pgsql-admin

Heyho,
we tried several versions of a query which give the same results,
but the one takes 5 secs for the first time and 0.9 secs when i 
execute the query few moments later, while the other takes ~3 secs 
always. How can this be? And how can it be that the second query 
which is in fact simpler than the first takes longer?

Query 1: (5 secs vs 0.9 secs)

select 
	distinct 
	personen_id 
from 
	produktgruppen 
where 
	produktgruppen.produktgruppen_id in (
	select 
		distinct
		r_gruppen_produkte.produktgruppen_id 
	from 
		r_gruppen_produkte 
	where 
         // this and the next cond are removed in 2nd query
		r_gruppen_produkte.gruppen_id = gruppen.gruppen_id
	and 
		gruppen.parent_id=1 
	and 
		r_gruppen_produkte.gruppen_id = r_personen_bereiche.g_id 
	and 
		r_personen_bereiche.p_id = 1234
	)

Query 2: (3 secs)

select 
	distinct 
	personen_id 
from 
	produktgruppen 
where 
	produktgruppen.produktgruppen_id in (
	select 
		distinct
		r_gruppen_produkte.produktgruppen_id 
	from 
		r_gruppen_produkte 
	where 
		r_gruppen_produkte.gruppen_id = r_personen_bereiche.g_id 
	and 
		r_personen_bereiche.p_id = 1234
	)

Our system is Linux 2.2.16, gcc 2.95.2, Postgres 7.0.3 on a Pentium II 450, 128 megs

Thanks in advance

Markus Bertheau
Cenes Data GmbH




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: simpler query still significantly slower
@ 2001-05-23 11:26  Murat YILDIZ <myildiz@bellona.com.tr>
  parent: twanger@smartvia.de
  1 sibling, 0 replies; 3+ messages in thread

From: Murat YILDIZ @ 2001-05-23 11:26 UTC (permalink / raw)
  To: pgsql-admin

use the "explain select  ....."option and paste the outputs for both
queries...

<twanger@smartvia.de> wrote in message
news:2144293809.990605915265.JavaMail.root@mouse.unimessage.net...
> Heyho,
> we tried several versions of a query which give the same results,
> but the one takes 5 secs for the first time and 0.9 secs when i
> execute the query few moments later, while the other takes ~3 secs
> always. How can this be? And how can it be that the second query
> which is in fact simpler than the first takes longer?
>
> Query 1: (5 secs vs 0.9 secs)
>
> select
> distinct
> personen_id
> from
> produktgruppen
> where
> produktgruppen.produktgruppen_id in (
> select
> distinct
> r_gruppen_produkte.produktgruppen_id
> from
> r_gruppen_produkte
> where
>          // this and the next cond are removed in 2nd query
> r_gruppen_produkte.gruppen_id = gruppen.gruppen_id
> and
> gruppen.parent_id=1
> and
> r_gruppen_produkte.gruppen_id = r_personen_bereiche.g_id
> and
> r_personen_bereiche.p_id = 1234
> )
>
> Query 2: (3 secs)
>
> select
> distinct
> personen_id
> from
> produktgruppen
> where
> produktgruppen.produktgruppen_id in (
> select
> distinct
> r_gruppen_produkte.produktgruppen_id
> from
> r_gruppen_produkte
> where
> r_gruppen_produkte.gruppen_id = r_personen_bereiche.g_id
> and
> r_personen_bereiche.p_id = 1234
> )
>
> Our system is Linux 2.2.16, gcc 2.95.2, Postgres 7.0.3 on a Pentium II
450, 128 megs
>
> Thanks in advance
>
> Markus Bertheau
> Cenes Data GmbH
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: simpler query still significantly slower
@ 2001-05-23 16:09  Stephan Szabo <sszabo@megazone23.bigpanda.com>
  parent: twanger@smartvia.de
  1 sibling, 0 replies; 3+ messages in thread

From: Stephan Szabo @ 2001-05-23 16:09 UTC (permalink / raw)
  To: twanger@smartvia.de; +Cc: pgsql-admin


First thing is that you probably want to use exists instead of
in (see FAQ).  Second thing is, do the two queries gather the
same rows?  There are references to tables that don't seem
to be in from lists, which from lists are those tables in?
Finally, what does explain show for the two queries?

On Wed, 23 May 2001 twanger@smartvia.de wrote:

> Heyho,
> we tried several versions of a query which give the same results,
> but the one takes 5 secs for the first time and 0.9 secs when i 
> execute the query few moments later, while the other takes ~3 secs 
> always. How can this be? And how can it be that the second query 
> which is in fact simpler than the first takes longer?
> 
> Query 1: (5 secs vs 0.9 secs)
> 
> select 
> 	distinct 
> 	personen_id 
> from 
> 	produktgruppen 
> where 
> 	produktgruppen.produktgruppen_id in (
> 	select 
> 		distinct
> 		r_gruppen_produkte.produktgruppen_id 
> 	from 
> 		r_gruppen_produkte 
> 	where 
>          // this and the next cond are removed in 2nd query
> 		r_gruppen_produkte.gruppen_id = gruppen.gruppen_id
> 	and 
> 		gruppen.parent_id=1 
> 	and 
> 		r_gruppen_produkte.gruppen_id = r_personen_bereiche.g_id 
> 	and 
> 		r_personen_bereiche.p_id = 1234
> 	)
> 
> Query 2: (3 secs)
> 
> select 
> 	distinct 
> 	personen_id 
> from 
> 	produktgruppen 
> where 
> 	produktgruppen.produktgruppen_id in (
> 	select 
> 		distinct
> 		r_gruppen_produkte.produktgruppen_id 
> 	from 
> 		r_gruppen_produkte 
> 	where 
> 		r_gruppen_produkte.gruppen_id = r_personen_bereiche.g_id 
> 	and 
> 		r_personen_bereiche.p_id = 1234
> 	)
> 
> Our system is Linux 2.2.16, gcc 2.95.2, Postgres 7.0.3 on a Pentium II 450, 128 megs
> 
> Thanks in advance
> 
> Markus Bertheau
> Cenes Data GmbH
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
> 
> http://www.postgresql.org/search.mpl
> 




^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-05-23 16:09 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-05-23 08:15 simpler query still significantly slower twanger@smartvia.de
2001-05-23 11:26 ` Murat YILDIZ <myildiz@bellona.com.tr>
2001-05-23 16:09 ` Stephan Szabo <sszabo@megazone23.bigpanda.com>

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