From: Kevin Grittner <Kevin.Grittner@wicourts.gov>
To: Dhimant Patel <drp4kri@gmail.com>
To: pgsql-performance@postgresql.org
Subject: Re: Query Performance with Indexes on Integer type vs. Date type.
Date: Wed, 27 Apr 2011 11:17:50 -0500
Message-ID: <4DB7FB5E020000250003CF3D@gw.wicourts.gov> (raw)
In-Reply-To: <BANLkTi=6obZB2vamHxbsUTYdQFrhrAz7_g@mail.gmail.com>
References: <BANLkTi=6obZB2vamHxbsUTYdQFrhrAz7_g@mail.gmail.com>
Dhimant Patel <drp4kri@gmail.com> 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
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, drp4kri@gmail.com
Subject: Re: Query Performance with Indexes on Integer type vs. Date type.
In-Reply-To: <4DB7FB5E020000250003CF3D@gw.wicourts.gov>
References: <BANLkTi=6obZB2vamHxbsUTYdQFrhrAz7_g@mail.gmail.com> <4DB7FB5E020000250003CF3D@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