pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Yves Dorfsman <yves@zioup.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: extract(year from date) doesn't use index but maybe could?
Date: Sun, 19 Apr 2015 18:29:54 -0400
Message-ID: <6398.1429482594@sss.pgh.pa.us> (raw)
In-Reply-To: <5534269A.10605@zioup.com>
References: <CADhq2b51G0QrjNz_vH6e_SLyu=tR0A0G0zHhFsP7rqRr+6FA3w@mail.gmail.com>
	<5533E8F4.2050400@2ndquadrant.com>
	<CADhq2b67QTAD7AkhGm3GZMwCUDU6kR70mpKEEnM=S5h1yRtdgg@mail.gmail.com>
	<55341A3C.1080101@2ndquadrant.com>
	<6287.1429479191@sss.pgh.pa.us>
	<5534269A.10605@zioup.com>
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Yves Dorfsman <yves@zioup.com> writes:
> What about functions that are simpler such as upper()/lower()?

If you think those are simpler, you're much mistaken :-(.  For instance,
"lower(first_name) = 'yves'" would have to be translated to something
like "first_name IN ('yves', 'yveS', 'yvEs', 'yvES', ..., 'YVES')"
-- 16 possibilities altogether, or 2^N for an N-character string.
(And that's just assuming ASCII up/down-casing, never mind the interesting
rules in some non-English languages.)  In a case-sensitive index, those
various strings aren't going to sort consecutively, so we'd end up needing
a separate index probe for each possibility.

extract(year from date) agrees with timestamp comparison up to boundary
cases, that is a few hours either way at a year boundary depending on the
timezone situation.  So you could translate it to a lossy-but-indexable
timestamp comparison condition and not expect to scan too many index items
that don't satisfy the original extract() condition.  But I don't see how
to make something like that work for mapping case-insensitive searches
onto case-sensitive indexes.

			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



view thread (10+ messages)  latest in thread

Message-ID: <6398.1429482594@sss.pgh.pa.us>
Permalink:  ../6398.1429482594@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/6398.1429482594@sss.pgh.pa.us

 · 

reply

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, yves@zioup.com
  Subject: Re: extract(year from date) doesn't use index but maybe could?
  In-Reply-To: <6398.1429482594@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