Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-24 Thread Jim C. Nasby
On Fri, Mar 24, 2006 at 02:58:54PM +0800, Christopher Kings-Lynne wrote: Yeah. AFAICS the transformation Chris suggested is valid. I'm really dubious that it's worth expending planner cycles to look for it though. LIKE is something that everybody and his brother uses, but who uses this

[HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Christopher Kings-Lynne
Is it worth allowing this: select count(*) from users_users where position('ch' in username) = 0; To be able to use an index, like: select count(*) from users_users where username like 'ch%'; At the moment the position() syntax will do a seqscan, but the like syntax will use an index.

Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Thomas Hallgren
Christopher Kings-Lynne wrote: Is it worth allowing this: select count(*) from users_users where position('ch' in username) = 0; To be able to use an index, like: select count(*) from users_users where username like 'ch%'; At the moment the position() syntax will do a seqscan, but the like

Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Tim Allen
Thomas Hallgren wrote: Christopher Kings-Lynne wrote: Is it worth allowing this: select count(*) from users_users where position('ch' in username) = 0; To be able to use an index, like: select count(*) from users_users where username like 'ch%'; At the moment the position() syntax will do

Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Tom Lane
Tim Allen [EMAIL PROTECTED] writes: Thomas Hallgren wrote: The position function must look for 'ch' everywhere in the string so there's no way it can use an index. I think the '= 0' bit is what Chris was suggesting could be the basis for an optimisation. Yeah. AFAICS the transformation

Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Thomas Hallgren
Tom Lane wrote: Tim Allen [EMAIL PROTECTED] writes: Thomas Hallgren wrote: The position function must look for 'ch' everywhere in the string so there's no way it can use an index. I think the '= 0' bit is what Chris was suggesting could be the basis for an optimisation.

Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Christopher Kings-Lynne
Yeah. AFAICS the transformation Chris suggested is valid. I'm really dubious that it's worth expending planner cycles to look for it though. LIKE is something that everybody and his brother uses, but who uses this position()=0 locution? One of our junior developers :) Which is why I noticed

Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Thomas Hallgren
Thomas Hallgren wrote: Tom Lane wrote: Tim Allen [EMAIL PROTECTED] writes: Thomas Hallgren wrote: The position function must look for 'ch' everywhere in the string so there's no way it can use an index. I think the '= 0' bit is what Chris was suggesting could be the basis

Re: [HACKERS] Worthwhile optimisation of position()?

2006-03-23 Thread Christopher Kings-Lynne
The docs are correct so my initial point was correct. position('ch' in user) = 0 is equivalent to user NOT LIKE '%ch%' and there's no way you can index that. Well = 1 then. Chris ---(end of broadcast)--- TIP 1: if posting/reading through