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 1ika4a-0003Il-HS for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Dec 2019 20:49:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ika4Y-0001N3-4P for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Dec 2019 20:49:30 +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 1ika4X-0001Mv-SJ for pgsql-bugs@lists.postgresql.org; Thu, 26 Dec 2019 20:49:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ika4Q-0000YG-Do for pgsql-bugs@lists.postgresql.org; Thu, 26 Dec 2019 20:49:29 +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 xBQKnIKe012043; Thu, 26 Dec 2019 15:49:18 -0500 From: Tom Lane To: Zhihong Zhang cc: Jeff Janes , Tomas Vondra , pgsql-bugs Subject: Re: Indexing on JSONB field not working In-reply-to: <0A83C661-EDBB-43C8-9CBB-FB1E321A15CB@gmail.com> References: <0cf001d5b77f$bfe47e10$3fad7a30$@gmail.com> <20191220223005.f6w4ff4kdbgtanpz@development> <83E6A3F7-B1B4-4AD6-905A-BE11D244D35A@gmail.com> <4910.1577386715@sss.pgh.pa.us> <0A83C661-EDBB-43C8-9CBB-FB1E321A15CB@gmail.com> Comments: In-reply-to Zhihong Zhang message dated "Thu, 26 Dec 2019 14:22:30 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <12041.1577393358.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 26 Dec 2019 15:49:18 -0500 Message-ID: <12042.1577393358@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Zhihong Zhang writes: > I looked at pg_stats for all our databases. None of them have stats on i= ndexes. Are there any settings disabling this? No, I don't think so. We only collect stats on index expressions, though, not simple columns (since those would be duplicative of the underlying column's stats). Hmmm ... looking at the pg_stats view, it has a filter WHERE NOT a.attisdropped AND has_column_privilege(c.oid, a.attnum, 'select'::text) AND (c.relrowsecurity =3D false OR NOT row_security_active(c.oid)) The has_column_privilege test might be getting in the way if you're not superuser; it will probably think you have no access privileges for the index. I now recall somebody complaining about that before [1], but no fix has been accepted as yet. Having said that, though, that only accounts for you not seeing the entries in the pg_stats view; it doesn't explain why the optimizer doesn't see them, assuming they're actually there in pg_statistic, which they surely should be. As I recall, RDS doesn't give out superuser access, so it may be hard for you to learn more about what's happening :-( regards, tom lane [1] https://www.postgresql.org/message-id/flat/6369212.CF36pTLAQO%40peanut= s2