Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWRfi-0004tg-13 for pgsql-performance@arkaria.postgresql.org; Mon, 31 Aug 2015 16:11:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZWRfh-000092-Je for pgsql-performance@arkaria.postgresql.org; Mon, 31 Aug 2015 16:11:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZWRe4-00066X-Dm for pgsql-performance@postgresql.org; Mon, 31 Aug 2015 16:09:20 +0000 Received: from mbob.nabble.com ([162.253.133.15]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZWRdy-0005ka-5C for pgsql-performance@postgresql.org; Mon, 31 Aug 2015 16:09:19 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mbob.nabble.com (Postfix) with ESMTP id 20F7E14694F0 for ; Mon, 31 Aug 2015 09:06:15 -0700 (PDT) Date: Mon, 31 Aug 2015 09:09:11 -0700 (MST) From: twoflower To: pgsql-performance@postgresql.org Message-ID: <1441037351126-5864045.post@n5.nabble.com> Subject: =?UTF-8?Q?Query_>_1000=C3=97_slowdown_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 I have the following three tables: DOCUMENT id (index) documenttype date_last_updated: timestamp(6) (indexed) EXTERNAL_TRANSLATION_UNIT id (indexed) fk_id_document (indexed) EXTERNAL_TRANSLATION id (indexed) fk_id_translation_unit (indexed) Table sizes: DOCUMENT: 381 000 EXTERNAL_TRANSLATION_UNIT: 76 000 000 EXTERNAL_TRANSLATION: 76 000 000 Now the following query takes about 36 minutes to finish: SELECT u.id AS id_external_translation_unit, r.id AS id_external_translation, u.fk_id_language AS fk_id_source_language, r.fk_id_language AS fk_id_target_language, doc.fk_id_job FROM "EXTERNAL_TRANSLATION_UNIT" u JOIN "DOCUMENT" doc ON u.fk_id_document = doc.id JOIN "EXTERNAL_TRANSLATION" r ON u.id = r.fk_id_translation_unit WHERE doc.date_last_updated >= date(now() - '171:00:00'::interval) ORDER BY r.id LIMIT 1000 This is the query plan: If I remove the WHERE condition, it returns immediately. Am I doing something obviously wrong? Thank you for any ideas. -- View this message in context: http://postgresql.nabble.com/Query-1000-slowdown-after-adding-datetime-comparison-tp5864045.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