Re: [sqlalchemy] `func.similarity` performance

2016-04-01 Thread Robert Smith
Mike Bayer: Thank you for your explanation. Yes, I thought `func.XYZ` was more aware of its functions. In the case of `%` and indexes, I think there is an improvement if there is an index, but the query still works as usual even in the absence of an index. However, if the implementation is not

Re: [sqlalchemy] `func.similarity` performance

2016-03-31 Thread Jonathan Vanasco
On Thursday, March 31, 2016 at 6:46:10 PM UTC-4, Robert Smith wrote: > > Thank you. That's a good idea but in this case, I'm really wondering if > sqlalchemy should use that small change to improve performance quite a bit > in this type of queries. > I've been in your place. 1. It sounds like

Re: [sqlalchemy] `func.similarity` performance

2016-03-31 Thread Mike Bayer
On 03/31/2016 06:40 PM, Robert Smith wrote: Mike Bayer: Thank you for your response. I wasn't really asking whether the optimization I described above (using `%` instead of `similarity`) is correct or not. Based on some resources (e.g. Super Fuzzy Searching on PostgreSQL

Re: [sqlalchemy] `func.similarity` performance

2016-03-31 Thread Robert Smith
Jonathan Vanasco: Thank you. That's a good idea but in this case, I'm really wondering if sqlalchemy should use that small change to improve performance quite a bit in this type of queries. Otherwise, I think I would need to rely on raw SQL to perform a similarity operation and I'm not sure if

Re: [sqlalchemy] `func.similarity` performance

2016-03-31 Thread Robert Smith
Mike Bayer: Thank you for your response. I wasn't really asking whether the optimization I described above (using `%` instead of `similarity`) is correct or not. Based on some resources (e.g. Super Fuzzy Searching on PostgreSQL

Re: [sqlalchemy] `func.similarity` performance

2016-03-31 Thread Jonathan Vanasco
On Thursday, March 31, 2016 at 9:43:11 AM UTC-4, Mike Bayer wrote: > > this is more of a Postgresql optimization question so I dont have any > insight on that. > FWIW, I generally handle these types of "optimize postgres" queries using a function to apply the filter - like this: def fil

Re: [sqlalchemy] `func.similarity` performance

2016-03-31 Thread Mike Bayer
On 03/30/2016 09:50 PM, Robert Smith wrote: I'm using sqlalchemy 1.0.12 with postgreSQL 9.4.6 with the pg_trgm extension enabled. Basically, I'm performing a similarity-based query on a single column: In [26]: str(session.query(Model).order_by(desc(func.similarity(Model.description, 'string')

[sqlalchemy] `func.similarity` performance

2016-03-30 Thread Robert Smith
I'm using sqlalchemy 1.0.12 with postgreSQL 9.4.6 with the pg_trgm extension enabled. Basically, I'm performing a similarity-based query on a single column: In [26]: str(session.query(Model).order_by(desc(func.similarity(Model.description, 'string'))).limit(100)) Out[26]: 'SELECT model.id AS m