Is there a way in SQLalchemy to tell the query which index to use?
The reason I need this is that the SQL queries it generates use the “wrong” index – there exists an index for exactly the two fields that I have and it doesn’t use it.
Thanks!
Advertisement
Answer
I think you can use with_hint() for this.
e.g.
session.query(Model).with_hint(Model, 'USE INDEX col1_index')
Honestly, I didn’t really know about this; I discovered it by finding ‘USE INDEX’ in their ORM tests.