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 1jgt2k-0005xV-VD for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 16:48:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jgt2j-0001wi-Oi for pgsql-general@arkaria.postgresql.org; Thu, 04 Jun 2020 16:48:37 +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 1jgt2j-0001wT-Gn for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 16:48:37 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jgt2c-0001t4-U3 for pgsql-general@lists.postgresql.org; Thu, 04 Jun 2020 16:48:36 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 3385F5C00F1; Thu, 4 Jun 2020 12:48:30 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Thu, 04 Jun 2020 12:48:30 -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=i 2B4OdNyJuS7ouS/0DwvO+6XLmF93oW0+Ve1Qf/ZiAc=; b=iw22XPgYC5pP1qN+o 2PZ6PbK0rv9GW4SgyTdJoFuzGxGUMQ87wumB1kKb+gpUrpD2Um8+TwyT0vSX+7XI E73e/cYn01Nk1lpX118mx9dAXLvpKmHMJbPNtUVYoxPMpI85Xbu1bPc15RJZ+DPL A6oQVcD6v4oN1zyWfteDg3R5Mx4rprAdkUghbWrHLs6eOX4uspFkqlev3RVSc8Tg eGCw/r1MvR0PUGkxx4zonAkbOGuiWimMEGThSoNp2ol2WmOgeJtwXOvL63oaLoFa Uq2r/+6Q3xFC7q7BvyKuaMR9F1sa5BtBj9lHCQvSiE+UutFIj4yQA8nQ+XZDApF8 +zUkg== 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=fm2; bh=i2B4OdNyJuS7ouS/0DwvO+6XLmF93oW0+Ve1Qf/Zi Ac=; b=OQ9KKx0n3yMhoojBvBA/ptDdmDoNh0GdQ/QQW+xZ8APQ//wpVRYkKh6rH c5BtIKweKW/fCjiF0hwGseG4/K5cuMNaK1bm5MqZunWp/cgrCIFarCPGserFQczJ z5E68rM8D+o920WIP297xRLEvqv3ZL1Opq+cXgAkRoP7kyAoBfEp9ccnD/LzAqAh jo5IKU3OOI+oqeuwk3uf43BVDmk13+0klIq+uB9MNJ+YhlKJ81zfBaYVDdS64ij9 tWCBCGlbITPU+bJ4Hnxpq9M6FE+lVISfcq9jITZZ7+mRDb7VJ8uTdgYqQ7R/4SEr a6f/TUt5uzlZdDJwI03ofHW1dxMLg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudeguddgleeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfhfhffkffgfgggjtgfgsehtje ertddtfeejnecuhfhrohhmpeetughrihgrnhcumfhlrghvvghruceorggurhhirghnrdhk lhgrvhgvrhesrghklhgrvhgvrhdrtghomheqnecuggftrfgrthhtvghrnhepkedujeefve fhgfevgeevjeffvefhheehgeffgeduueeuveegtefhheekheeuveffnecuffhomhgrihhn 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 4A49E328005D; Thu, 4 Jun 2020 12:48:29 -0400 (EDT) Subject: Re: Index no longer being used, destroying and recreating it restores use. To: Tom Lane , Koen De Groote Cc: pgsql-general@lists.postgresql.org References: <1251078.1591289012@sss.pgh.pa.us> From: Adrian Klaver Message-ID: Date: Thu, 4 Jun 2020 09:48:28 -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: <1251078.1591289012@sss.pgh.pa.us> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 6/4/20 9:43 AM, Tom Lane wrote: > Koen De Groote writes: >> I've got a table with about 30 million rows and a particular index that up >> until recently was actively being used. >> And then it stopped being used and the query that the index was made for, >> is now doing sequential scans. >> Deleting the index and creating it again, seems to fix the problem. The new >> index, which is identical in composition, is being used and the query in >> question no longer uses sequential scans. > > 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. So: With index(https://explain.depesz.com/s/H5X9y): Limit (cost=5964059.790..5964071.460 rows=100 width=3141) (actual time=2534.648..2547.352 rows=100 loops=1) Buffers: shared hit=30 read=27753 -> Gather Merge (cost=5959707.820..6516383.180 rows=4771170 width=3141) (actual time=2193.611..2542.835 rows=37400 loops=1) Workers Planned: 2 Workers Launched: 2 Buffers: shared hit=30 read=27753 -> Sort (cost=5958707.790..5964671.760 rows=2385585 width=3141) (actual time=1833.278..1838.731 rows=12528 loops=3) Sort Key: mike_romeo, quebec Sort Method: quicksort Memory: 24449kB Worker 0: Sort Method: quicksort Memory: 28634kB Worker 1: Sort Method: quicksort Memory: 18065kB Buffers: shared hit=30 read=27753 -> Parallel Bitmap Heap Scan on oscar mike_three (cost=4282.840..1923544.730 rows=2385585 width=3141) (actual time=150.297..659.047 rows=23586 loops=3) Recheck Cond: ((zulu <= 'echo'::timestamp without time zone) AND four AND (NOT bravo)) Heap Blocks: exact=9759 Buffers: shared read=27753 -> Bitmap Index Scan on foxtrot (cost=0.000..2851.490 rows=5725405 width=0) (actual time=245.459..245.459 rows=70759 loops=1) Index Cond: (zulu <= 'echo'::timestamp without time zone) Buffers: shared read=2028 Planning time: 437.187 ms Execution time: 2549.633 ms W/O index(https://explain.depesz.com/s/n6bP): Limit (cost=5975083.560..5975095.230 rows=100 width=3141) (actual time=159708.476..159718.368 rows=100 loops=1) Buffers: shared hit=1082 read=1798654 -> Gather Merge (cost=5970731.590..6527406.950 rows=4771170 width=3141) (actual time=159309.819..159713.861 rows=37400 loops=1) Workers Planned: 2 Workers Launched: 2 Buffers: shared hit=1082 read=1798654 -> Sort (cost=5969731.570..5975695.530 rows=2385585 width=3141) (actual time=159214.623..159219.579 rows=12531 loops=3) Sort Key: mike_romeo, quebec Sort Method: quicksort Memory: 24459kB Worker 0: Sort Method: quicksort Memory: 22650kB Worker 1: Sort Method: quicksort Memory: 24038kB Buffers: shared hit=1082 read=1798654 -> 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 Buffers: shared hit=1014 read=1798652 Planning time: 0.807 ms Execution time: 159720.208 ms > > regards, tom lane > > -- Adrian Klaver adrian.klaver@aklaver.com