Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Yjxiz-0000HM-Ut for pgsql-performance@arkaria.postgresql.org; Sun, 19 Apr 2015 22:30:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yjxiy-0006cj-HV for pgsql-performance@arkaria.postgresql.org; Sun, 19 Apr 2015 22:30:00 +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 1Yjxix-0006ca-9v for pgsql-performance@postgresql.org; Sun, 19 Apr 2015 22:29:59 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yjxiu-0008W9-FG for pgsql-performance@postgresql.org; Sun, 19 Apr 2015 22:29:57 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t3JMTs6f023361; Sun, 19 Apr 2015 18:29:54 -0400 From: Tom Lane To: Yves Dorfsman cc: pgsql-performance@postgresql.org Subject: Re: extract(year from date) doesn't use index but maybe could? In-reply-to: <5534269A.10605@zioup.com> References: <5533E8F4.2050400@2ndquadrant.com> <55341A3C.1080101@2ndquadrant.com> <6287.1429479191@sss.pgh.pa.us> <5534269A.10605@zioup.com> Comments: In-reply-to Yves Dorfsman message dated "Sun, 19 Apr 2015 16:05:14 -0600" Date: Sun, 19 Apr 2015 18:29:54 -0400 Message-ID: <6398.1429482594@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) 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 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 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance