Re: PostgreSQL 9.1 : why is this query slow?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Kevin Grittner" <Kevin.Grittner@xxxxxxxxxxxx> wrote:
 
> If you really want the intersection, perhaps:
 
Or maybe closer:
 
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 counts,
        count(case when filetype = 'n' then 1 else null end)
          as countn
      from unique_words
      group by word
  )
select word, least(countf, counts, countn) from x
  where countf > 0 and counts > 0 and countn > 0
  order by word;
 
Cranked out rather quickly and untested.
 
-Kevin

-- 
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance


[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux