From: Tom Lane <tgl@sss.pgh.pa.us>
To: Zac Goldstein <goldzz@gmail.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Index not being used on composite type for particular query
Date: Sat, 20 May 2017 20:00:02 -0400
Message-ID: <3303.1495324802@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+TxaKaot1BEVLZ6PUYCUfZ7Q0uGSpBkmk418S+U9st1Ygp73A@mail.gmail.com>
References: <CA+TxaKaot1BEVLZ6PUYCUfZ7Q0uGSpBkmk418S+U9st1Ygp73A@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>
Zac Goldstein <goldzz@gmail.com> writes:
> This uses the index:
> ...
> But this doesn't:
> EXPLAIN (ANALYZE, BUFFERS) SELECT * FROM shot
> WHERE lower(shot.matchsecond) <@ ((shot.matchsecond).match_id,
> numrange(5, 10))::matchsecond_type;
Well, yeah. After inlining the SQL functions, what you have is
> Filter: ((((matchsecond).match_id)::integer =
> ((matchsecond).match_id)::integer) AND
> ((numrange(lower(((matchsecond).second)::numrange),
> lower(((matchsecond).second)::numrange), '[]'::text))::numrange <@
> ('[5,10)'::numrange)::numrange))
and neither half of the AND has the form "indexed_value indexable_operator
constant", which is the basic requirement for an index condition. We're a
little bit permissive about what "constant" means, but that most certainly
doesn't extend to expressions involving columns of the table. So the
first clause loses because it's got variables on both sides, and the
second loses because the LHS expression is not what the index is on.
You could build an additional index on that expression, if this shape
of query is important enough to you to justify maintaining another index.
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, goldzz@gmail.com
Subject: Re: Index not being used on composite type for particular query
In-Reply-To: <3303.1495324802@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox