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 1iFmeB-00058G-In for pgsql-general@arkaria.postgresql.org; Wed, 02 Oct 2019 21:58:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFmdA-0007Rg-Tp for pgsql-general@arkaria.postgresql.org; Wed, 02 Oct 2019 21:57:56 +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 1iFmdA-0007RW-Jo for pgsql-general@lists.postgresql.org; Wed, 02 Oct 2019 21:57:56 +0000 Received: from tamriel.snowman.net ([2001:470:e38f::11]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFmd3-0005Ie-BY for pgsql-general@postgresql.org; Wed, 02 Oct 2019 21:57:55 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id D6A285F79F; Wed, 2 Oct 2019 17:57:47 -0400 (EDT) Date: Wed, 2 Oct 2019 17:57:47 -0400 From: Stephen Frost To: Michael Lewis Cc: PegoraroF10 , pgsql-general Subject: Re: Performance on JSONB select Message-ID: <20191002215747.GR6962@tamriel.snowman.net> References: <1570027063947-0.post@n3.nabble.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="J9o5LXK0gE+fPLfF" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --J9o5LXK0gE+fPLfF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Greetings, * Michael Lewis (mlewis@entrata.com) wrote: > Much of indexing strategy depends on knowing the data like how many > distinct values and what the distribution is like. Is JsonBField->>'status' > always set? Are those three values mentioned in this query common or rare? > Can you re-write this query to avoid using an OR in the where clause? Are > you just wanting to add a GIN index for the jsonb paths? Or do you want > indexed like below that are a bit stylized to this query? If you know a field is going to always be there, you're better off, by far, by just having a regular column for that value and a straight up btree for it. This saves a significant amount of space and makes it much easier to index and work with. Thanks, Stephen --J9o5LXK0gE+fPLfF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJdlR1bAAoJEO1sijiDR2RVmTMP/jaboO5E4b8rZQJ81Q6WUFnv sFCrGFyS3qatnc7epl7H+EKuu4wMfgWUAKSNXAaZP3MQQA1f7ZJdVvPX4HxlOZuQ GhMe6gQYe2rvZvRvZX5wSCbQ0aMJhjR7r25jMnwdYy0D7rdlsgOHaHoIzM9UInQO X5rlsc+iMiiMkQMeRqE3/4NnohvvOl5/x576fu00M1CR9isWm/8heAYk8cpQua/J yxP3r8G6mG91CV6ssAkrs2sr3Aym43xDOLgWC43UMGwPql2ggYEarYkPbAfs5FlR p0JiG8eqFNnYPUBm0S0bD1ne8EDHI14Ek0+0yosxU5Lx343OJWcTKOmctmdtisTU 8VjgqQ2CCHNqjmP9DgaZ4/eNwxu1Nki3qp/yVIfIlDIMMMfnPTAIMdukTVANgHlB ZhWjbF3Rhg4C9DFHtHtTg89O984KNYjZjv5c9oBYZGBfO8Qgxhj1HLN+6WbS80fO 1OA+re7u+6UiPICCFDfbrmZrBvQ3Wl1gQ56d0aylnimMlNDNb+Ad0Y3BJMoW1nSy 8m5TE1kaWv55rXuYMq8S7LNitVSRnyaVQWXac4W2h5Zo/K3JFO+o97lYCjxkdhoJ paf4lieE9hnuOxoG9ktQcv42NL+8jV4J33T7R2dQ1mMmh2+mn8jU24sbidZvjNqY WbpCkg4BSY0hzOLciX9B =R7QV -----END PGP SIGNATURE----- --J9o5LXK0gE+fPLfF--