Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 62E9C1337C19 for ; Wed, 27 Apr 2011 13:18:19 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 98568-02-4 for ; Wed, 27 Apr 2011 16:18:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from gw.wicourts.gov (gwmta.wicourts.gov [165.219.244.99]) by mail.postgresql.org (Postfix) with ESMTP id 5209F1337BD2 for ; Wed, 27 Apr 2011 13:17:56 -0300 (ADT) Received: from Courts-MTA by gw.wicourts.gov with Novell_GroupWise; Wed, 27 Apr 2011 11:17:55 -0500 Message-Id: <4DB7FB5E020000250003CF3D@gw.wicourts.gov> X-Mailer: Novell GroupWise Internet Agent 8.0.1 Date: Wed, 27 Apr 2011 11:17:50 -0500 From: "Kevin Grittner" To: "Dhimant Patel" , Subject: Re: Query Performance with Indexes on Integer type vs. Date type. References: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201104/372 X-Sequence-Number: 43434 Dhimant Patel wrote: > I am a new comer on postgres world and now using it for some > serious (at least for me) projects. I have a need where I am > running some analytical + aggregate functions on data where > ordering is done on Date type column. > > From my initial read on documentation I believe internally a date > type is represented by integer type of data. This makes me wonder > would it make any good to create additional column of Integer type > and update it as data gets added and use this integer column for > all ordering purposes for my sqls - or should I not hasitate using > Date type straight into my sql for ordering? I doubt that this will improve performance, particularly if you ever want to see your dates formatted as dates. > Better yet, is there anyway I can verify impact of ordering on > Date type vs. Integer type, apart from using \timing and explain > plan? You might be better off just writing the code in the most natural way, using the date type for dates, and then asking about any queries which aren't performing as you hope they would. Premature optimization is often counter-productive. If you really want to do some benchmarking of relative comparison speeds, though, see the generate_series function -- it can be good at generating test tables for such things. -Kevin