From: Tom Lane <tgl@sss.pgh.pa.us>
To: Marinos J. Yannikos <mjy@geizhals.at>
Cc: pgsql-performance@postgresql.org
Subject: Re: (partial?) indexes, LIKE and NULL
Date: Tue, 27 Jan 2004 17:46:38 -0500
Message-ID: <29758.1075243598@sss.pgh.pa.us> (raw)
In-Reply-To: <4016BB4E.7030107@geizhals.at>
References: <4016BB4E.7030107@geizhals.at>
"Marinos J. Yannikos" <mjy@geizhals.at> writes:
> Shouldn't queries that use
> ... where t like '%something%'
> benefit from [an index on t] when t is NULL in almost all cases, since
> the query planner could use [it] to access the few non-NULL rows
> quickly?
No, and the reason is that the planner *can't* use the index that way.
To do that we'd have to support "x IS NOT NULL" as an indexable
operator, which we don't. This is exactly the same stumbling block as
for more-direct uses of indexes to search for NULL or NOT NULL rows.
See the pghackers archives for more details.
> (I assume that it would make no difference if the index "a" was partial,
> excluding NULLs)
You could do
create index a on foo(t) where t is not null;
and then this index would likely get used for any query explicitly
mentioning "AND t is not null". The planner will not induce such a
where clause entry from the presence of other tests on t, however.
regards, tom lane
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, mjy@geizhals.at
Subject: Re: (partial?) indexes, LIKE and NULL
In-Reply-To: <29758.1075243598@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