Re: Query Performance with Indexes on Integer type vs. Date type.

From: Maciek Sakrejda <msakrejda(at)truviso(dot)com>
To: Dhimant Patel <drp4kri(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query Performance with Indexes on Integer type vs. Date type.
Date: 2011-04-27 16:12:32
Message-ID: BANLkTi=14-tJAZO8QVf8ThHmmkcr_VqBFw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> 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?

Keep in mind what Michael A. Jackson (among others) had to say on
this: "The First Rule of Program Optimization: Don't do it. The Second
Rule of Program Optimization (for experts only!): Don't do it yet."
For one thing, adding an extra column to your data would mean more
data you need to cram in the cache as you query, so even if the *raw*
integer versus date ordering is faster, the "optimization" could still
be a net loss due to the fatter tuples. If you're willing to live with
*only* integer-based dates, that could help, but that seems
exceptionally painful and not worth considering unless you run into
trouble.

> Better yet, is there anyway I can verify impact of ordering on Date type vs. Integer type, apart from using \timing and explain plan?

Remember to use explain analyze (and not just explain) when validating
these sorts of things. Explain is really just a guess. Also remember
to ensure that stats are up to date before you test this.

---
Maciek Sakrejda | System Architect | Truviso

1065 E. Hillsdale Blvd., Suite 215
Foster City, CA 94404
(650) 242-3500 Main
www.truviso.com

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Kevin Grittner 2011-04-27 16:17:50 Re: Query Performance with Indexes on Integer type vs. Date type.
Previous Message Tom Lane 2011-04-27 16:11:57 Re: Query Performance with Indexes on Integer type vs. Date type.