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 1gUYKI-0006h5-Rm for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 14:38:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUYKH-0001vX-9o for pgsql-general@arkaria.postgresql.org; Wed, 05 Dec 2018 14:38:57 +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 1gUYKH-0001th-1S for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 14:38:57 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gUYKE-0001dA-7p for pgsql-general@lists.postgresql.org; Wed, 05 Dec 2018 14:38:56 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id 357A85F7AA; Wed, 5 Dec 2018 09:38:53 -0500 (EST) Date: Wed, 5 Dec 2018 09:38:53 -0500 From: Stephen Frost To: Chris Withers Cc: pgsql-general@lists.postgresql.org Subject: Re: surprising query optimisation Message-ID: <20181205143853.GC3415@tamriel.snowman.net> References: <03a0af57-3ebc-5501-10ef-6a639c7c34b8@withers.org> <20181128224950.GS3415@tamriel.snowman.net> <5d7f8d97-32f3-fd88-44cc-948673579a71@withers.org> <20181130153327.GA3415@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mV0x5vRiaQJFucaF" 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 --mV0x5vRiaQJFucaF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Chris Withers (chris@withers.org) wrote: > On 30/11/2018 15:33, Stephen Frost wrote: > >* Chris Withers (chris@withers.org) wrote: > >>On 28/11/2018 22:49, Stephen Frost wrote: > >For this, specifically, it's because you end up with exactly what you > >have: a large index with tons of duplicate values. Indexes are > >particularly good when you have high-cardinality fields. Now, if you > >have a skewed index, where there's one popular value and a few much less > >popular ones, then that's where you really want a partial index (as I > >suggest earlier) so that queries against the non-popular value(s) is > >able to use the index and the index is much smaller. >=20 > Interesting! In my head, for some reason, I'd always assumed a btree index > would break down a char field based on the characters within it. Does that > never happen? Not sure what you mean by 'break down a char field'. > If I changed this to be an enum field, would !=3D still perform poorly or= can > the query optimiser spot that it's an enum and just look for the other > options? I don't believe we've got any kind of optimization like that today for enums. Thanks! Stephen --mV0x5vRiaQJFucaF Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJcB+L8AAoJEO1sijiDR2RVGTQP/1L00REYdfkfaz3ErKrNIxQ8 c98NFc8LIRrmLkuhHyOv3InQbQkA7EZMV/mUu1Zl1mrRLqG7qAasx+zowp6/kd61 Bh2meIZ0UlHExoq5j5o99b3Iqu6u74S6Gw5rIYMo/ET+OWcPhx7CBoVFsD1HmDU5 wCbxJnfce1oyX6HOdEhIm0Vb24ldbSEg5HmnLpRVjOzmwHA6NtxUhIWZRzc26SRj LcNs7Cho8ZzDZf+ljdKUX1ipTSd25zZYF+3Zjmg8xEJkiTxWhG2/Ii3eh6G1juQe mbXR7DfFLO0H2Pef6WmhRMwMLV3I+7xCp2LqcgufqvFa46tY6SHxsgNmPviNoXa7 A73ZGyC9Zg3kKkYPoWy7owwb8Y9szM3GkFffGF+/6CWMSBu5/r6IjjHyFJ99PLu8 djHkhxQbK2G8TCZ4wg5ClI7vUBnPeQ8wkfq9qnxM3H26CjiFw7IWYhsutmZGx1ZO PK8APDyoQ8KASPIJkgAkwWgHbo4OAax+sySx32fvlRagDRfnzgnB/OvwHj0qkYts XXpGhJ0A7NOFwwyKhEHTeJ+jvQYEkbHS97MjOESL2L673LTnqlLMckDFpTT4f6sa BrsxXPBPq2ZX3HmceDnNMGNS/YoJy9+SNzojq2ngJFNNIeg/EMlzM6lZ+phJ+47j 6BUZutV9aW8jnx50WStp =BsrV -----END PGP SIGNATURE----- --mV0x5vRiaQJFucaF--