Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSiRf-0000IT-BD for pgsql-general@arkaria.postgresql.org; Fri, 30 Nov 2018 13:02:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gSiRd-0006LL-W3 for pgsql-general@arkaria.postgresql.org; Fri, 30 Nov 2018 13:02:57 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSiPI-0005wS-61 for pgsql-general@lists.postgresql.org; Fri, 30 Nov 2018 13:00:32 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gSiPE-00055R-Vk for pgsql-general@lists.postgresql.org; Fri, 30 Nov 2018 13:00:31 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id BD11D21F44; Fri, 30 Nov 2018 08:00:27 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 30 Nov 2018 08:00:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=withers.org; h= subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=mesmtp; bh=s1x+WQGvjrnDyXLzfKfBnhX86Eq8S+YwWjyJjeCusVA=; b=yisJ6+/QQf+J 3RN5WQT3jgeCJOvQ74aiQoBxGzOxJqfMP1zcZOXWPztrQGKDKwow7WpAD8zoqB1P NoC16UCD4ZOX29VQbICkunxtc5SK4QO/jdTwjwykT5jSLeiNau0Jmsi3S2LYxyy5 LRj9A+wp3aj3jlJyr5EQ3obM306JcLY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=s1x+WQGvjrnDyXLzfKfBnhX86Eq8S+YwWjyJjeCus VA=; b=ooN8VYPwPNWjwFKDqCbb2xD1NVU9J/jYP4odBpu89PU2Ou0pahkKp1JjX EpAzrvJiR6wbmy4g8HM95XerfFM4f6KlYGCDgMiLoXdNIukMuXCyUq6qdAavlqwr xX48768fRdhzRywMEdAON7xssrC3RpEKhznOOqaB3iHNUv2QcmXwoOvkELw1PyjC cbuLPIT5Lxn5eu7lGK9oNVIk7VDm2xHzQcGzTujH/efB8h3jgtd6sY1OWmiTCEl9 5z7wpXcBuCqFnxwH616KLssUzOWjrI+44S3oqyvXE3Ectb4Fh9rfPPmm577T0Ogv f8Wd11L3VW65tL3hOiWlKDvL/ibjg== X-ME-Sender: X-ME-Proxy: Received: from [172.25.22.95] (unknown [213.174.214.6]) by mail.messagingengine.com (Postfix) with ESMTPA id CE387E4648; Fri, 30 Nov 2018 08:00:26 -0500 (EST) Subject: Re: surprising query optimisation To: Stephen Frost References: <03a0af57-3ebc-5501-10ef-6a639c7c34b8@withers.org> <20181128224950.GS3415@tamriel.snowman.net> <5d7f8d97-32f3-fd88-44cc-948673579a71@withers.org> Cc: pgsql-general@lists.postgresql.org From: Chris Withers Message-ID: <076fec6e-3bb4-3a99-e71f-dc1cec684cb6@withers.org> Date: Fri, 30 Nov 2018 13:00:26 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:64.0) Gecko/20100101 Thunderbird/64.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 30/11/2018 12:55, Stephen Frost wrote: > > I'd suggest you check out the wiki article written about this kind of > > question: > > > > https://wiki.postgresql.org/wiki/Slow_Query_Questions > > > Have you tried a partial index on state!=‘RSV’? The solution I originally posted, that we do easily enough at our query generation layer, is working perfectly, but this is good to know for next time. My post here is mainly to try and understand what's going on so I can improve my general feel for how to use postgres at it's best. So, why was the query ending up being a big scan rather than some quick lookups based on the index? cheers, Chris