pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedQuestion about Sql SELECT and optimizer
2+ messages / 2 participants
[nested] [flat]
* Question about Sql SELECT and optimizer
@ 2006-03-02 16:19 Chaz. <eprparadocs@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: Chaz. @ 2006-03-02 16:19 UTC (permalink / raw)
To: pgsql-sql
I am trying to understand something I have seen happen. I had a select
that looked like:
select f(A) from A, B, C where g(A)
Where f(A) is the select that only depends on table A;
g(A) is the where part that only depends on table A.
What I saw happen was the optimizer will waste a lot of time (seconds!)
bringing in table B and C. I was wondering why doesn't the optimizer
drop references to tables B and C since they aren't used any where?
Peace and thanks in advance
Chuck Wegrzyn
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Question about Sql SELECT and optimizer
@ 2006-03-02 17:04 Michael Fuhr <mike@fuhr.org>
parent: Chaz. <eprparadocs@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Fuhr @ 2006-03-02 17:04 UTC (permalink / raw)
To: Chaz. <eprparadocs@gmail.com>; +Cc: pgsql-sql
On Thu, Mar 02, 2006 at 11:19:32AM -0500, Chaz. wrote:
> I am trying to understand something I have seen happen. I had a select
> that looked like:
>
> select f(A) from A, B, C where g(A)
>
> Where f(A) is the select that only depends on table A;
> g(A) is the where part that only depends on table A.
>
> What I saw happen was the optimizer will waste a lot of time (seconds!)
> bringing in table B and C. I was wondering why doesn't the optimizer
> drop references to tables B and C since they aren't used any where?
The above query does a cross join. Even though you're not using
values from B and C they're still contributing rows to the result
set.
test=> SELECT * FROM a;
aid
-----
a1
a2
(2 rows)
test=> SELECT * FROM b;
bid
-----
b1
b2
(2 rows)
test=> SELECT * FROM c;
cid
-----
c1
c2
(2 rows)
test=> SELECT a.*, b.*, c.* FROM a, b, c WHERE a.aid = 'a1';
aid | bid | cid
-----+-----+-----
a1 | b1 | c1
a1 | b2 | c1
a1 | b1 | c2
a1 | b2 | c2
(4 rows)
test=> SELECT a.*, b.* FROM a, b, c WHERE a.aid = 'a1';
aid | bid
-----+-----
a1 | b1
a1 | b2
a1 | b1
a1 | b2
(4 rows)
test=> SELECT a.* FROM a, b, c WHERE a.aid = 'a1';
aid
-----
a1
a1
a1
a1
(4 rows)
--
Michael Fuhr
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2006-03-02 17:04 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-02 16:19 Question about Sql SELECT and optimizer Chaz. <eprparadocs@gmail.com>
2006-03-02 17:04 ` Michael Fuhr <mike@fuhr.org>
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