Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aLNhO-0003SP-BB for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Jan 2016 04:15:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aLNhN-000878-EL for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Jan 2016 04:15:17 +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) (envelope-from ) id 1aLNhM-00083l-3T for pgsql-bugs@postgresql.org; Tue, 19 Jan 2016 04:15:16 +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) (envelope-from ) id 1aLNhJ-0004FY-MH for pgsql-bugs@postgresql.org; Tue, 19 Jan 2016 04:15:14 +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 u0J4FBOQ029067; Mon, 18 Jan 2016 23:15:11 -0500 From: Tom Lane To: Michael Paquier cc: hukim99@gmail.com, PostgreSQL mailing lists Subject: Re: BUG #13874: The index of a json field which is created after data are inserted doesn't work. In-reply-to: References: <20160118123942.2961.98513@wrigleys.postgresql.org> Comments: In-reply-to Michael Paquier message dated "Tue, 19 Jan 2016 10:32:52 +0900" Date: Mon, 18 Jan 2016 23:15:11 -0500 Message-ID: <29066.1453176911@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Michael Paquier writes: > On Mon, Jan 18, 2016 at 9:39 PM, wrote: >> The only difference between two instructions above is whether the index is >> created before or after data insertion. Isn't it a bug? > My guess is that there are invalid statistics on this table. If you > run ANALYZE on json_test you should be able to see a sequential scan > in the first case as well. It is weird that the planner chooses a > bitmap scan in the first case for one tuple. Yes, after an ANALYZE you'd get the same plan either way. The difference in behavior here is because you get sort of a half-baked ANALYZE (specifically, an update in the table's recorded tuple count) at the time of CREATE INDEX. I don't think this is a bug; and I note that for this size of table, it really hardly matters which plan the planner chooses. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs