Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhD8E-0006nG-4Q for pgsql-general@arkaria.postgresql.org; Fri, 05 Jun 2020 14:15:38 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jhD8C-0002C1-Ru for pgsql-general@arkaria.postgresql.org; Fri, 05 Jun 2020 14:15:36 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhD8B-00020E-3i for pgsql-general@lists.postgresql.org; Fri, 05 Jun 2020 14:15:36 +0000 Received: from wout4-smtp.messagingengine.com ([64.147.123.20]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhD87-0004oA-Ur for pgsql-general@lists.postgresql.org; Fri, 05 Jun 2020 14:15:34 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 39624A9E; Fri, 5 Jun 2020 10:15:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 05 Jun 2020 10:15:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm3; bh=G TmCnSdHUmAF9XDXqvfHGXcbfw6oy2YOgdaU6vY52aA=; b=jefs2ei3oZTSZpfOJ QeaWTyX+P4ELMizK6A5R1bU6iVrTtDHkcbxg4NCW8s5b4LicMHXeFepEX1Ju0Va2 y+8reLddEFm1etfNpkvdQqj1lEuqXkknjb62mszUIm31Jz5nTfUUOwMi+oe27hZx vIZbhNdGkVChxsH/uQiDgqoACZqQA8uZC2HzmeMKSVNNAjcsoh7FfL2oWeD4h2vh kjHE4t9JOLAW6sdTns7H0c85G/pjhwSxGynBfvyb8qfsiwXNxZ6k6Y4gBQznF0Zd tcQffdINwIVm8tDoHjJWw+Ss5AyqjsPyYX3xjLzNmYHYhmt88UYLNIq0pQuSouWA Mozlg== 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=fm3; bh=GTmCnSdHUmAF9XDXqvfHGXcbfw6oy2YOgdaU6vY52 aA=; b=Sa3uOxkvaRRvZUfM/0tXeiogz8wjcMNKvExR1s7YQzhpItJ+M7lkDSSud MQ76Xiqh4uHoMUQs9hjKFP/r0X6lN7230DMSV8UwvGtAHsEL2FwsamUuoCYP2tsk kXsmlIearkR0AMWqHQIlvLIa8RNOQTuqNdrBOrGzgbYZqhXOsbso+WfOkcZ8Ds24 jFyHSgZCpN4WTNhYZ/C+XlcfGgYk0WEnojoCyhoi1q8ewq8k7WKWKeirrqmC7eSC 34Xnon5kOeiOlCtv2VJS69pnrYzYyjcLKr45YAz0nUvL1aNXPUdMZ4Qk8G5szGnw JIP1cfkDSwPFnuSoU5r47F6fzz1VQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudegfedgieefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtke ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepveffffethf efudfgkeefteeuheetheekvedukeetheeuieeiuddvhfduudeggfeunecuffhomhgrihhn peguvghpvghsiidrtghomhenucfkphepjeehrddujedvrdehrddvfedunecuvehluhhsth gvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgr vhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.3] (75-172-5-231.tukw.qwest.net [75.172.5.231]) by mail.messagingengine.com (Postfix) with ESMTPA id 0CFD0328005E; Fri, 5 Jun 2020 10:15:27 -0400 (EDT) Subject: Re: Index no longer being used, destroying and recreating it restores use. To: Koen De Groote , Tom Lane Cc: pgsql-general@lists.postgresql.org References: <1251078.1591289012@sss.pgh.pa.us> <1251997.1591290525@sss.pgh.pa.us> From: Adrian Klaver Message-ID: <92ea007a-abe0-1dd2-7e5c-080da70c2e2c@aklaver.com> Date: Fri, 5 Jun 2020 07:15:27 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.1 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 6/5/20 7:05 AM, Koen De Groote wrote: > I've collected all relevant info(I think so at least) and put it here: > > The table in question is used to keep filepath data, of files on a > harddrive. > The query in question is used to retrieve items which should be backed > up, but have not yet been. > > The relevant columns of the table: > >                                                     Table "public.item" >                Column               |            Type             | > Collation | Nullable |                   Default > ------------------------------------+-----------------------------+-----------+----------+---------------------------------------------- >  id                                 | bigint                      | >       | not null | nextval('item_id_seq'::regclass) >  shouldbebackedup                   | boolean                     | >       | not null | true >  backupperformed                    | boolean                     | >       | not null | false >  itemCreated                        | timestamp without time zone | >       |          | now() >  filepath                           | text                        | >       |          | > > > The existing index, which no longer gets used: > "index_in_question" btree (shouldbebackedup, backupperformed, > itemCreated, filepath) WHERE shouldbebackedup = true AND backupperformed > = false > > The new index, made out of the exact same columns and conditions, get > used immediately after creation: > CREATE INDEX CONCURRENTLY index_test ON item USING btree > (shouldbebackedup, backupperformed, itemCreated, filepath) WHERE > shouldbebackedup = true AND backupperformed = false; > > > The query in question will look something like this: > select * from item where shouldbebackedup=true and > itemCreated<='2020-06-05 00:00:00.000' and backupperformed=false order > by filepath asc, id asc limit 100 offset 10400; The result of EXPLAIN ANALYZE for above. > > Having done a count, there are around 13000 items here, without the > offset and limit. > That being said, the amount is entirely dependant on what was added on a > previous day. > > > I tried creating an extended statistic, like this, but it had no effect: > CREATE STATISTICS s1 (dependencies) ON shouldbebackedup, backupperformed > FROM item; > > Settings from the conf file I think are related: > > shared_buffers = 1024MB > effective_cache_size = 2048MB > random_page_cost = 1.1 > effective_io_concurrency = 200 > work_mem = 32MB > > Finally, I state again that this database gets a nightly "vacuum analyze". > > My thanks for looking at this and any suggestions one might have. > > Regards, > Koen > > On Thu, Jun 4, 2020 at 7:08 PM Tom Lane > wrote: > > Adrian Klaver > writes: > > On 6/4/20 9:43 AM, Tom Lane wrote: > >> It's possible that the index had bloated to the point where the > planner > >> thought it was cheaper to use a seqscan.  Did you make a note of the > >> cost estimates for the different plans? > > > I missed the part where the OP pointed to a SO question. In that > > question where links to explain.depesz.com > output. > > Ah, I didn't bother to chase that link either. > > So the cost estimates are only a fraction of a percent apart, making > it unsurprising for not-so-large changes in the index size to cause > a flip in the apparently-cheapest plan.  The real question then is > why the cost estimates aren't actually modeling the real execution > times very well; and I'd venture that that question boils down to > why is this rowcount estimate so far off: > > >                ->  Parallel Seq Scan on oscar mike_three > > (cost=0.000..1934568.500 rows=2385585 width=3141) (actual > > time=159.800..158018.961 rows=23586 loops=3) > >                        Filter: (four AND (NOT bravo) AND (zulu <= > > 'echo'::timestamp without time zone)) > >                        Rows Removed by Filter: 8610174 > > We're not going to be able to answer that if the OP doesn't wish > to decloak his data a bit more ... but a reasonable guess is that > those filter conditions are correlated.  With late-model Postgres > you might be able to improve matters by creating extended statistics > for this table. > >                         regards, tom lane > -- Adrian Klaver adrian.klaver@aklaver.com