From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jack Coates <jack@lyris.com>
Cc: pgsql-performance <pgsql-performance@postgresql.org>
Subject: Re: query optimization question
Date: Thu, 29 Jan 2004 14:31:11 -0500
Message-ID: <26581.1075404671@sss.pgh.pa.us> (raw)
In-Reply-To: <1075403095.7494.117.camel@cletus.lyris.com>
References: <1075338353.7494.71.camel@cletus.lyris.com>
<10115.1075341889@sss.pgh.pa.us>
<1075396980.7494.107.camel@cletus.lyris.com>
<25064.1075399504@sss.pgh.pa.us>
<1075403095.7494.117.camel@cletus.lyris.com>
Jack Coates <jack@lyris.com> writes:
> jackdb=# explain SELECT DISTINCT members_.memberid_
> jackdb-# FROM members_
> jackdb-# WHERE ( members_.List_='list1'
> jackdb(# AND members_.MemberType_='normal'
> jackdb(# AND members_.SubType_='mail'
> jackdb(# AND members_.emailaddr_ IS NOT NULL )
> jackdb-# GROUP BY memberid_ HAVING (
Um, that's not what I had in mind at all. Does GROUP BY actually do
anything at all here? (You didn't answer me as to whether memberid_
is a unique identifier or not, but if it is, this GROUP BY is just an
expensive no-op.)
What I was envisioning was pulling the sub-selects up to the top level
and using grouping to calculate the count(*) values for all memberids
in parallel. Roughly speaking it would look like (again assuming
memberid_ is unique)
SELECT memberid_ FROM
(
SELECT memberid_ FROM lyrActiveRecips, members_, outmail
WHERE (all the conditions for this case)
UNION ALL
SELECT memberid_ FROM lyrCompletedRecips, members_, outmail
WHERE (all the conditions for this case)
)
GROUP BY memberid_ HAVING count(*) = 3;
However, if you can't change the boilerplate part of your query then
this is all blue-sky speculation anyway. What I'm actually more
interested in is your statement that MSSQL can do the original query
quickly. I find that a bit hard to believe because I don't see any
relevant optimization techniques. Do they have any equivalent to
EXPLAIN that would give some hint how they're doing it?
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, jack@lyris.com
Subject: Re: query optimization question
In-Reply-To: <26581.1075404671@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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