Re: Analysis Function - Mailing list pgsql-performance

From David Jarvis
Subject Re: Analysis Function
Date
Msg-id AANLkTik3l6uedzVJLqn-nueNva46NAFwxbpSe1XSc26_@mail.gmail.com
Whole thread Raw
In response to Re: Analysis Function  (Tim Landscheidt <tim@tim-landscheidt.de>)
List pgsql-performance
Hi, Tim.

Have you tested DATE_TRUNC()?

Not really; it returns a full timestamp and I would still have to concatenate strings. My goal is to speed up the following code (where p_ parameters are user inputs):

        date(extract(YEAR FROM m.taken)||''-'||p_month1||'-'||p_day1||''') d1,
        date(extract(YEAR FROM m.taken)||''-'||p_month2||'-'||p_day2||''') d2


Using DATE_TRUNC() won't help here, as far as I can tell. Removing the concatenation will halve the query's time. Such as:

dateserial( m.taken, p_month1, p_day1 ) d1,
dateserial( m.taken, p_month2, p_day2 ) d2

My testing so far has shown a modest improvement by using a C function (to avoid concatenation).

Dave

pgsql-performance by date:

Previous
From: Tim Landscheidt
Date:
Subject: Re: Analysis Function
Next
From: Heikki Linnakangas
Date:
Subject: Re: Analysis Function