Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YjzLD-0004Sz-Rx for pgsql-performance@arkaria.postgresql.org; Mon, 20 Apr 2015 00:13:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YjzLC-0006zh-N4 for pgsql-performance@arkaria.postgresql.org; Mon, 20 Apr 2015 00:13:34 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YjzLA-0006zI-ET for pgsql-performance@postgresql.org; Mon, 20 Apr 2015 00:13:32 +0000 Received: from mbx.knossos.net.nz ([202.160.48.10]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YjzKy-000213-SZ for pgsql-performance@postgresql.org; Mon, 20 Apr 2015 00:13:25 +0000 Received: from [10.1.1.3] (121-99-189-151.bng1.nct.orcon.net.nz [121.99.189.151]) (authenticated bits=0) by mbx.knossos.net.nz (8.14.4/8.14.4) with ESMTP id t3K0DDwf006419 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT); Mon, 20 Apr 2015 12:13:13 +1200 Message-ID: <55344498.7070101@archidevsys.co.nz> Date: Mon, 20 Apr 2015 12:13:12 +1200 From: Gavin Flower Organization: ArchiDevSys User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Tom Lane , Yves Dorfsman CC: pgsql-performance@postgresql.org Subject: Re: extract(year from date) doesn't use index but maybe could? References: <5533E8F4.2050400@2ndquadrant.com> <55341A3C.1080101@2ndquadrant.com> <6287.1429479191@sss.pgh.pa.us> <5534269A.10605@zioup.com> <6398.1429482594@sss.pgh.pa.us> In-Reply-To: <6398.1429482594@sss.pgh.pa.us> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org On 20/04/15 10:29, Tom Lane wrote: > Yves Dorfsman 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 > > Yeah, an event that happened at 2 am Thursday January 1st 2015 in New Zealand, will be in the year 2014 for people of London in England! Cheers, Gavin -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance