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'))).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.

this is more of a Postgresql optimization question so I dont have any insight on that.


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?

Table reflection will reflect table indexes, though this is not really important in the case of automapping as indexes do not affect ORM mappings.




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 [email protected]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to