Re: Date vs Timestamp without timezone Partition Key - Mailing list pgsql-performance

From David Rowley
Subject Re: Date vs Timestamp without timezone Partition Key
Date
Msg-id CAApHDvqA8zY4vGXYhP6DUZU3RkzqdY1bWgcMOXiM3G=+P4Bv3w@mail.gmail.com
Whole thread Raw
In response to Re: Date vs Timestamp without timezone Partition Key  (Cedric Leong <cedricleong@gmail.com>)
Responses Re: Date vs Timestamp without timezone Partition Key  (Cedric Leong <cedricleong@gmail.com>)
List pgsql-performance
On Sat, 6 Jun 2020 at 14:49, Cedric Leong <cedricleong@gmail.com> wrote:
> It's less of a complaint rather than just a warning not to do what I did.

My point was really that nobody really knew what you did or what you
did it on. So it didn't seem like a worthwhile warning as it
completely lacked detail.

> These tests are running the exact same query on two different tables with the exception that they use their
respectivepartition keys.
 

Are you sure?  It looks like the old one does WHERE date =
((now())::date - '7 days'::interval) and the new version does
(date(created_at) = ((now())::date - '7 days'::interval). I guess you
renamed date to "created_at" and changed the query to use date(). If
that expression is not indexed then I imagine that would be a good
reason for the planner to have moved away from using the index on that
column. Also having date(created_at) will also not allow run-time
pruning to work since your partition key is "created_at".

You might be able to change the query to query a range of value on the
new timestamp column. This will allow you to get rid of the date()
function. For example:

where created_at >= date_trunc('day', now() - '7 days'::interval) and
created_at < date_trunc('day', now() - '6 days'::interval)

David



pgsql-performance by date:

Previous
From: Cedric Leong
Date:
Subject: Re: Date vs Timestamp without timezone Partition Key
Next
From: Cedric Leong
Date:
Subject: Re: Date vs Timestamp without timezone Partition Key