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 model_id, model.description AS 
model_description, \nFROM model ORDER BY similarity(model.description, 
:similarity_1) DESC\n LIMIT :param_1'

This query works okay, but I'm worried that looking at the query that is 
being used, it doesn't seem to take advantage of some performance 
improvements that are available in this kind of situation. As a simple 
example, I noticed that people recommend not to use `similarity` and 
instead rely on `%` or alternatively, use `WHERE model.description  % 
'string' AND similarity(model.description, 'string') > 0.5`. This is 
apparently related to the efficient use of a "gist" index. 

Another question: In the case of having an index for the trigram matches, 
does sqlalchemy pick up that information automatically when I'm using 
`automap_base()` to reflect my database?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to