From: Kevin Grittner <kgrittn@ymail.com>
To: Hengky Liwandouw <hengkyliwandouw@gmail.com>
To: pgsql-performance@postgresql.org <pgsql-performance@postgresql.org>
Subject: Re: Speed up the query
Date: Sun, 1 Dec 2013 08:02:05 -0800 (PST)
Message-ID: <1385913725.4005.YahooMailNeo@web162901.mail.bf1.yahoo.com> (raw)
In-Reply-To: <B097B80F-2D51-4F42-BC0D-5A38CBCD0C01@gmail.com>
References: <B097B80F-2D51-4F42-BC0D-5A38CBCD0C01@gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
Hengky Liwandouw <hengkyliwandouw@gmail.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
--
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
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 using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: kgrittn@ymail.com, hengkyliwandouw@gmail.com
Subject: Re: Speed up the query
In-Reply-To: <1385913725.4005.YahooMailNeo@web162901.mail.bf1.yahoo.com>
* 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