From: | Cedar Cox <cedarc(at)visionforisrael(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | subselects - which is faster? |
Date: | 2003-06-12 10:20:54 |
Message-ID: | Pine.LNX.4.21.0306121259480.3203-100000@nanu.visionforisrael.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
It's been a while since I've done much SQL..
. I'm wondering which of these two queries is faster (both get the
same result)?
. Which one is more correct? Does it even matter or are they the
same? The first one reads easier to me.
. What's the difference between "InitPlan" and "SubPlan"?
explain SELECT eqid,
(select name from tbleqattrtypes where id=
(select eqattrtypeid from tbleqattrs
where id=main.eqattrid))
as attrtype, eqattrid from tbleqattrmap as main;
NOTICE: QUERY PLAN:
Seq Scan on tbleqattrmap main (cost=0.00..1.15 rows=15 width=8)
SubPlan
-> Seq Scan on tbleqattrtypes (cost=0.00..1.04 rows=1 width=12)
InitPlan
-> Seq Scan on tbleqattrs (cost=0.00..1.09 rows=1 width=4)
explain SELECT eqid,
(select
(select name from tbleqattrtypes where id=sec.eqattrtypeid)
from tbleqattrs as sec where id=main.eqattrid)
as attrtype, eqattrid from tbleqattrmap as main;
NOTICE: QUERY PLAN:
Seq Scan on tbleqattrmap main (cost=0.00..1.15 rows=15 width=8)
SubPlan
-> Seq Scan on tbleqattrs sec (cost=0.00..1.09 rows=1 width=4)
SubPlan
-> Seq Scan on tbleqattrtypes (cost=0.00..1.04 rows=1 width=12)
One additional detail: right now the tables are all very small, and
tbleqattrtypes will not grow much, but tbleqattrs will eventually be
very large.
Thanks, and sorry for bothering you all..
- Cedar
From | Date | Subject | |
---|---|---|---|
Next Message | Christoph Haller | 2003-06-12 11:16:27 | Re: How to make a IN without a table... ? |
Previous Message | David Pradier | 2003-06-12 09:19:14 | How to make a IN without a table... ? |