Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9RMn-0006WU-KW for pgsql-general@arkaria.postgresql.org; Thu, 28 Mar 2019 09:30:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9RMm-00061K-7t for pgsql-general@arkaria.postgresql.org; Thu, 28 Mar 2019 09:30:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h9RMl-00061D-ME for pgsql-general@lists.postgresql.org; Thu, 28 Mar 2019 09:30:31 +0000 Received: from mail.wordtothewise.com ([104.225.223.158]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h9RMg-0001Nh-T6 for pgsql-general@lists.postgresql.org; Thu, 28 Mar 2019 09:30:31 +0000 Received: from [10.214.128.117] (unknown [217.173.105.122]) by mail.wordtothewise.com (Postfix) with ESMTPSA id A738B9F146 for ; Thu, 28 Mar 2019 02:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=wordtothewise.com; s=aardvark; t=1553765423; bh=8mjTfkH8wQbQ+7qpOHvH1qJb90Yq/GYrzVHK08Pe6As=; h=From:Subject:Date:References:To:In-Reply-To:From; b=PMtGsYRt4KYLvOPy7vf5EuKFavKGLfK4eFXuLrc35YqSFNI0WQ4kGyLpLGTTZ5zw9 jFY42mfjiHGEGAyqQnYB5wr5ypiyvpUtP8nAArjJCXPH2dZYskyofsDomwSvFQqjCJ GqujkWuAB6AvkRThlKMHRMVRC6TEoRBmrQGmp+NQ= From: Steve Atkins Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: Case Insensitive Date: Thu, 28 Mar 2019 09:30:21 +0000 References: <150586A3-A8F4-4B80-9A4B-310DE265B4B3@blighty.com> To: PG mailing List In-Reply-To: Message-Id: <3C4DCC9E-C7D0-4DD6-90E7-CF3C30FCE146@blighty.com> X-Mailer: Apple Mail (2.3445.102.3) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Mar 28, 2019, at 9:08 AM, Ron wrote: >=20 > On 3/28/19 3:33 AM, Steve Atkins wrote: >>=20 >>> On Mar 28, 2019, at 8:29 AM, Ron wrote: >>>=20 >>> On 3/28/19 3:23 AM, Sameer Kumar wrote: >>> [snip] >>>> You can write a query with upper function: >>>>=20 >>>> select * from emp where upper(ename)=3Dupper('aaa'); >>> That's a guaranteed table scan. >> Unless you have an index on upper(ename). >=20 > Are you sure? I thought the lpart had to be immutable for the query = optimizer to decide to use an index (and upper(ename) is mutable). Yeah. Case insensitive searches like this are pretty much the first = example given for why you might want to use an expression index. The expression in an expression index has to be immutable, but upper() = is - it will always give the same output for a given input. (For values = of "always" that probably depend on not performing major surgery on = collations, but that falls into the "lie to the planner, get rotten = results" category). Check "\df+ upper" Cheers, Steve