pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rob Sargent <robjsargent@gmail.com>
To: A. Kretschmer <andreas.kretschmer@schollglas.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: report generation from table.
Date: Wed, 21 Oct 2009 08:48:44 -0600
Message-ID: <4ADF1F4C.8050509@gmail.com> (raw)
In-Reply-To: <20091021121607.GA1086@a-kretschmer.de>
References: <f966c2ee0910210452x4a60093ds772b62063e72fe8c@mail.gmail.com>
	<20091021121607.GA1086@a-kretschmer.de>



A. Kretschmer wrote:
> In response to sathiya psql :
>> Hi All,
>>
>> I have been searching for, Preparing report from a huge table.
>>
>> Queries am executing now are,
>> SELECT count(*) from HUGE_TBL where cond1, cond2;
>> SELECT count(*) from HUGE_TBL where cond1, cond3;
>> --- like this i have different conditions(10-15 different things ) and
>> different amount of conditions ( 2 - 5 condition ).
>>
>> As that is a very huge table, it took time to execute each query ( 2 min ). And
>> finally it takes 15 times that ( 30 min ).  Is there anyway to do the above
>> report efficiently ?
>>
>> Such executing the query only once, and getting all different outputs required
>> ? or fetching result from some cache ?
> 
> select sum(case when <cond1> and <cond2> then 1 else 0 end) as query1,
> sum(case when <cond1> and <cond3> then 1 else 0 end) as query2, ... from
> table;
> 
> 
> It forces a whole seq. scan, but only once.
> 
> 
> Regards, Andreas


Probably should check (analyse) the various queries separately to see if
any of them scan the huge table.  If one does scan the table, then give
Andreas's plan should be fine.  However, it's possible that your
conditions are all hitting indexes and not scanning, in which case you
may be better off as is.



view thread (3+ messages)

Message-ID: <4ADF1F4C.8050509@gmail.com>
Permalink:  ../4ADF1F4C.8050509@gmail.com/
Also on:    postgresql.org/message-id/4ADF1F4C.8050509@gmail.com

 · 

reply

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-sql@postgresql.org
  Cc: robjsargent@gmail.com, andreas.kretschmer@schollglas.com
  Subject: Re: report generation from table.
  In-Reply-To: <4ADF1F4C.8050509@gmail.com>

* 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