Re: How to make use of partitioned table for faster query? - Mailing list pgsql-general

From John R Pierce
Subject Re: How to make use of partitioned table for faster query?
Date
Msg-id 54015847.1090404@hogranch.com
Whole thread Raw
In response to How to make use of partitioned table for faster query?  (Patrick Dung <patrick_dkt@yahoo.com.hk>)
Responses Re: How to make use of partitioned table for faster query?  (Patrick Dung <patrick_dkt@yahoo.com.hk>)
List pgsql-general
On 8/29/2014 9:38 PM, Patrick Dung wrote:
Suppose the table 'attendance' is very large:
id bigint
student_name varchar
late boolean
record_timestamp timestamp

The table is already partitioned by year (attendance_2012p, attendance_2013p, ...).
I would like to count the number of lates by year.

Instead of specifying the partition tables name:
select count(*) from attendance_2012p where student_name="Student A" and late='true';
select count(*) from attendance_2013p where student_name="Student A" and late='true';
select count(*) from attendance_2014p where student_name="Student A" and late='true';
...

Is it possible to query the master table attendance), and the query could make use of the partitioned table for faster query?


select student_name as student,extract(year from record_timestamp) as year, count(*) as count_lates from attendance where late group by 1,2;

now, if your partitioning is by school year, that will be somewhat trickier.   what are your partitioning expression ?

as far as faster, well, your query has to read from all of the tables.   there won't be any speedup from partition pruning...





-- 
john r pierce                                      37N 122W
somewhere on the middle of the left coast

pgsql-general by date:

Previous
From: Patrick Dung
Date:
Subject: How to make use of partitioned table for faster query?
Next
From: Patrick Dung
Date:
Subject: Re: How to make use of partitioned table for faster query?