pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedTwo Permance Questions
2+ messages / 2 participants
[nested] [flat]
* Two Permance Questions
@ 2002-09-20 02:07 CN LIOU <cnliou@graffiti.net>
0 siblings, 1 reply; 2+ messages in thread
From: CN LIOU @ 2002-09-20 02:07 UTC (permalink / raw)
To: pgsql-sql
Hi!
Q1. Is subquery better or join?
For subquery:
SELECT t1.c1,(SELECT t2.c2 FROM t2 WHERE t2.c1 = t1.c1) FROM t1
I wonder it will loop n times if t1 returns n rows. If this is the case, is it better to use join like this:
SELECT t1.c1,t2.c2 FROM t1,t2 WHERE t2.c1 = t1.c1
Q2. If the query is not optimize like this:
SELECT t1.c1,t2.c2 FROM t1,t2,t1,t2,t2 WHERE t2.c1=t1.c1 AND t1.c1=t2.c1 AND t1.c1=t2.c1
and the size of this clause can soar up to several kbytes, then can this query cause performance problem?
Regards,
--
_______________________________________________
Get your free email from http://www.graffiti.net
Powered by Outblaze
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Two Permance Questions
@ 2002-09-20 18:42 CoL <col@mportal.hu>
parent: CN LIOU <cnliou@graffiti.net>
0 siblings, 0 replies; 2+ messages in thread
From: CoL @ 2002-09-20 18:42 UTC (permalink / raw)
To: pgsql-sql
The select without subselect of course is better, and faster.
Check your "explain analyze select ..." to se the performance, and to
check the index usage if any.
C.
CN LIOU wrote:
> Hi!
>
> Q1. Is subquery better or join?
>
> For subquery:
>
> SELECT t1.c1,(SELECT t2.c2 FROM t2 WHERE t2.c1 = t1.c1) FROM t1
>
> I wonder it will loop n times if t1 returns n rows. If this is the case, is it better to use join like this:
>
> SELECT t1.c1,t2.c2 FROM t1,t2 WHERE t2.c1 = t1.c1
>
> Q2. If the query is not optimize like this:
>
> SELECT t1.c1,t2.c2 FROM t1,t2,t1,t2,t2 WHERE t2.c1=t1.c1 AND t1.c1=t2.c1 AND t1.c1=t2.c1
>
> and the size of this clause can soar up to several kbytes, then can this query cause performance problem?
>
> Regards,
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2002-09-20 18:42 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-09-20 02:07 Two Permance Questions CN LIOU <cnliou@graffiti.net>
2002-09-20 18:42 ` CoL <col@mportal.hu>
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