Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bn56A-0004pZ-Dw for pgsql-performance@arkaria.postgresql.org; Thu, 22 Sep 2016 14:35:38 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bn56A-0003mF-0t for pgsql-performance@arkaria.postgresql.org; Thu, 22 Sep 2016 14:35:38 +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_2) (envelope-from ) id 1bn569-0003lr-Ay for pgsql-performance@postgresql.org; Thu, 22 Sep 2016 14:35:37 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bn566-0003W2-FL for pgsql-performance@postgresql.org; Thu, 22 Sep 2016 14:35:36 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u8MEZUVL015769; Thu, 22 Sep 2016 10:35:30 -0400 From: Tom Lane To: Igor Neyman cc: "Knels, Udo" , "pgsql-performance@postgresql.org" Subject: Re: Problem with performance using query with unnest after migrating from V9.1 to V9.2 and higher In-reply-to: References: <1d6ce510f1cf4dfcad73b15ff8ff98a4@EXCH-1.ddd-do.de> <283046e4-a37f-d8cb-85dc-52d1286e8ffb@BlueTreble.com> Comments: In-reply-to Igor Neyman message dated "Thu, 22 Sep 2016 13:38:52 -0000" Date: Thu, 22 Sep 2016 10:35:30 -0400 Message-ID: <15768.1474554930@sss.pgh.pa.us> X-Pg-Spam-Score: -5.0 (-----) 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 Igor Neyman writes: > table_a is too small, just 50 records. > Optimizer decided (correctly) that Seq Scan is cheaper than using an index. Yeah. The given test case is quite useless for demonstrating that you have a problem, since it's actually *faster* on 9.5 than 9.1. What I suspect is happening is that 9.2 and up assume that an unnest() will produce 100 rows, whereas 9.1 assumed it would produce only 1 row. The latter happened to be more accurate for this specific case, though in general it could result in selection of very bad plans. If you are intending only one value be selected, don't use unnest(); you'd be better off with "(string_to_array('5010010000',','))[1]" or something like that. In the long run we should teach the planner how to produce better estimates for unnest-on-a-constant-array, though I'm unsure whether that would help your real application as opposed to this test case. regards, tom lane -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance