Thread: Indexes with LIKE
I've noticed a difference in behaviour between a server running version 6.x and one running 7.2.1 in use of indexes with LIKE. With an index on foo, WHERE foo LIKE 'bar%' uses the index (as I would expect it to) on the 6.x box, but uses a sequential scan (really slow) on the 7.2.1 box. It's possible that I've set (or failed to set) a run-time parameter that controls the behaviour, but I don't know what that might be. ANALYZEing the table doesn't modify the behaviour. I can't find any mention of this in the documentation -- any pointers would be appreciated. If the above doesn't ring any bells, I'll put together an example. Many thanks Julian Scarfe
On Sat, 13 Jul 2002, Julian Scarfe wrote: > I've noticed a difference in behaviour between a server running version 6.x > and one running 7.2.1 in use of indexes with LIKE. > > With an index on foo, > > WHERE foo LIKE 'bar%' > > uses the index (as I would expect it to) on the 6.x box, but uses a > sequential scan (really slow) on the 7.2.1 box. > It's possible that I've set (or failed to set) a run-time parameter that > controls the behaviour, but I don't know what that might be. ANALYZEing the > table doesn't modify the behaviour. > > I can't find any mention of this in the documentation -- any pointers would > be appreciated. You need to have made the database in C locale in order to get index scans from LIKE. I think that's mentioned in the Localization section of the admin guide, but I could be remembering that wrong.
On Sat, 13 Jul 2002, Julian Scarfe wrote: > From: "Stephan Szabo" <sszabo@megazone23.bigpanda.com> > > > You need to have made the database in C locale in order to get index scans > > from LIKE. I think that's mentioned in the Localization section of the > > admin guide, but I could be remembering that wrong. > > Thanks very much Stephan. Indeed it's in Admin Guide 5.1.2. I was using > en_GB, not C. > > There is of course no excuse for failing to read every bit of smallprint in > the admin guide before installation :-) but for those lazy unfortunates like > me that don't think to look there to find out what's wrong when indexes > aren't used with LIKE, I've added a DocNote under Pattern Matching. That's a good idea. Alot of the docs are written assuming that you're configuring it from source so that you'd have to turn on locale at configure time, but that's not true for package users. Are you actually using any of the locale features of the locale? If not, you might want to consider setting up in C locale.
From: "Stephan Szabo" <sszabo@megazone23.bigpanda.com> > You need to have made the database in C locale in order to get index scans > from LIKE. I think that's mentioned in the Localization section of the > admin guide, but I could be remembering that wrong. Thanks very much Stephan. Indeed it's in Admin Guide 5.1.2. I was using en_GB, not C. There is of course no excuse for failing to read every bit of smallprint in the admin guide before installation :-) but for those lazy unfortunates like me that don't think to look there to find out what's wrong when indexes aren't used with LIKE, I've added a DocNote under Pattern Matching. Julian Scarfe