Re: planner not using index for like operator - Mailing list pgsql-performance

From Sriram Dandapani
Subject Re: planner not using index for like operator
Date
Msg-id 6992E470F12A444BB787B5C937B9D4DF0406B26C@ca-mail1.cis.local
Whole thread Raw
In response to planner not using index for like operator  ("Sriram Dandapani" <sdandapani@counterpane.com>)
List pgsql-performance
The col is a varchar. I am currently testing with the inet data type(and
also the ipv4 pgfoundry data type).

Due to time constraints, I am trying to minimize code changes.

What kind of index do I need to create to enable efficient range scans
(e.g anything between 172.16.x.x thru 172.31.x.x) on the inet data type?

Thanks

Sriram

-----Original Message-----
From: Jim C. Nasby [mailto:jnasby@pervasive.com]
Sent: Tuesday, April 25, 2006 11:25 AM
To: Sriram Dandapani
Cc: Pgsql-Performance (E-mail)
Subject: Re: [PERFORM] planner not using index for like operator

On Tue, Apr 25, 2006 at 10:08:02AM -0700, Sriram Dandapani wrote:
Here's the key:

> "  Filter: ((col1)::text ~~ '172.%'::text)"

In order to do a like comparison, it has to convert col1 (which I'm
guessing is of type 'inet') to text, so there's no way it can use an
index on col1 (maybe a function index, but that's a different story).

Is there some reason you're not doing

WHERE col1 <<= '172/8'::inet

?
--
Jim C. Nasby, Sr. Engineering Consultant      jnasby@pervasive.com
Pervasive Software      http://pervasive.com    work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf       cell: 512-569-9461

pgsql-performance by date:

Previous
From: "Jim C. Nasby"
Date:
Subject: Re: planner not using index for like operator
Next
From: Scott Marlowe
Date:
Subject: Re: Large (8M) cache vs. dual-core CPUs