From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl>
Cc: pgsql-performance@postgresql.org
Subject: Re: PostgreSQL 9.1 : why is this query slow?
Date: Mon, 28 Nov 2011 11:32:15 -0600
Message-ID: <4ED3713F020000250004355E@gw.wicourts.gov> (raw)
In-Reply-To: <1322500982.3343.30.camel@panoramix.Askesis.nl>
References: <1322498526.3343.22.camel@panoramix.Askesis.nl>
<1322499469.3343.25.camel@panoramix.Askesis.nl>
<4ED36AF0020000250004354F@gw.wicourts.gov>
<1322500982.3343.30.camel@panoramix.Askesis.nl>
Joost Kraaijeveld <J.Kraaijeveld@Askesis.nl> wrote:
> I would like the answer to be "the number of times the word
> appears in all three the queries", the intersection of the three
> queries.
That's still not entirely clear to me. If there are two 'f' rows,
three 's' rows, and four 'n' rows, do you want to see an answer of 2
(which seems like the intersection you request here), 9 (which is
the sum), 24 (which is the product), or something else?
If you really want the intersection, perhaps:
with x as
(
select
word,
count(*) as countall,
count(case when filetype = 'f' then 1 else null end)
as countf,
count(case when filetype = 's' then 1 else null end) as
as counts,
count(case when filetype = 'n' then 1 else null end) as
as countn
from unique_words
)
select word, least(countf, counts, countn) from x
where countf > 0 and counts > 0 and countn > 0
order by word;
-Kevin
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: Kevin.Grittner@wicourts.gov, J.Kraaijeveld@Askesis.nl
Subject: Re: PostgreSQL 9.1 : why is this query slow?
In-Reply-To: <4ED3713F020000250004355E@gw.wicourts.gov>
References: <1322498526.3343.22.camel@panoramix.Askesis.nl> <1322499469.3343.25.camel@panoramix.Askesis.nl> <4ED36AF0020000250004354F@gw.wicourts.gov> <1322500982.3343.30.camel@panoramix.Askesis.nl> <4ED3713F020000250004355E@gw.wicourts.gov>
* 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