Re: Speed up the query

From: Hengky Lie <hengkyliwandouw(at)gmail(dot)com>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Speed up the query
Date: 2013-12-01 16:14:38
Message-ID: CADvRrxP-FZeJZc2pa=cHgm5BA6O4nkjxEwArF-MS=dVjiF1TVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Thanks Kevin. You are absolutely right. I should use parentheses, it is
what i want for the query to do.

It also increasing processing time to 5.444 seconds. Should be okay i think.

On Sun, Dec 1, 2013 at 11:02 PM, Kevin Grittner <kgrittn(at)ymail(dot)com> wrote:

> Hengky Liwandouw <hengkyliwandouw(at)gmail(dot)com> wrote:
>
> > where jualid is not null
> > and extract(year from tanggal)='2013')
>
> > But the problem is : when i change the where clause to :
> >
> > where jualid is not null or returjualid is not null
> > and extract(year from tanggal)='2013')
> >
> > (there is additional or returjualid is not null,) the query needs
> > 56 second to display the result.
>
> Before worrying about the run time, I would worry about whether you
> are getting the results you expect. That will be interpreted as:
>
> where jualid is not null
> or (returjualid is not null and extract(year from tanggal) = '2013')
>
> ... not:
>
> where (jualid is not null or returjualid is not null)
> and extract(year from tanggal) = '2013'
> AND has higher priority than OR; so if you want to limit by year
> from tanggal even when jualid is not null, you must use
> parentheses.
>
> --
> Kevin Grittner
> EDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Hengky Lie 2013-12-01 17:33:03 Re: Speed up the query
Previous Message Kevin Grittner 2013-12-01 16:02:05 Re: Speed up the query