Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWgPk-000399-4S for pgsql-performance@arkaria.postgresql.org; Tue, 01 Sep 2015 07:55:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZWgPj-00010x-Bl for pgsql-performance@arkaria.postgresql.org; Tue, 01 Sep 2015 07:55:31 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZWgO5-0006jM-Sz for pgsql-performance@postgresql.org; Tue, 01 Sep 2015 07:53:50 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZWgO2-0005Vz-Lr for pgsql-performance@postgresql.org; Tue, 01 Sep 2015 07:53:48 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id EDFB714754B0 for ; Tue, 1 Sep 2015 00:50:44 -0700 (PDT) Date: Tue, 1 Sep 2015 00:53:45 -0700 (MST) From: twoflower To: pgsql-performance@postgresql.org Message-ID: <1441094025534-5864164.post@n5.nabble.com> In-Reply-To: References: <1441037351126-5864045.post@n5.nabble.com> <55E47E97.1090202@2ndquadrant.com> <1441047830983-5864075.post@n5.nabble.com> <1441048763332-5864080.post@n5.nabble.com> <1441050416677-5864088.post@n5.nabble.com> <1441053041230-5864101.post@n5.nabble.com> Subject: =?UTF-8?Q?Re:__Re:_Query_>_1000=C3=97_slow?= =?UTF-8?Q?down_after_adding_datetime_comparison?= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.3 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Stefan Keller wrote > So, if I'm understanding you correctly, we're talking solely about > following clause in the query you gave initially: > > WHERE doc.date_last_updated >= date(now() - '171:00:00'::interval) > which initially was > WHERE documenttype = 4 > and now is being replaced by a temporary (I'd say derived) column > WHERE updated > ? > > In any case - I have to go - but run http://explain.depesz.com/ and > give a weblink to the explain plans of your queries. Here's the query plan for the original query I struggled with: WHERE doc.date_last_updated >= date(now() - '171:00:00'::interval) The original slow query with date() Then, just out of curiosity, I replaced the WHERE condition with another one: WHERE doc.documenttype = 4. documenttype is an unindexed integer column. It's fast. Here's the query plan: date() condition replaced with documenttype = 4 Then, as David suggested, I tried to precompute the doc.date_last_updated >= date(now() - '171:00:00'::interval). I created a new boolean temp_eval column on the DOCUMENT table and updated the rows like this: update "DOCUMENT" set temp_eval = date_last_updated >= date(now() - '171:00:00'::interval); Then I analyzed the table and modified the query to only have WHERE temp_eval = TRUE. I expected this to be fast, but it took 41 minutes to complete. Here's the query plan: Precomputed column -- View this message in context: http://postgresql.nabble.com/Query-1-000-000-slowdown-after-adding-datetime-comparison-tp5864045p5864164.html Sent from the PostgreSQL - performance mailing list archive at Nabble.com. -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance