SQLalchemy Indicates Which Index To Use

Is there a way in SQLalchemy to specify the query which index to use?

The reason I need this is because the SQL queries it generates use the β€œwrong” index - there is an index for exactly the two fields that I have, and it does not use it.

Thanks!

+7
source share
2 answers

I think you can use with_hint () for this.

eg.

session.query(Model).with_hint(Model, 'USE INDEX col1_index') 

Honestly, I really did not know about this; I discovered this by finding "USE INDEX" in my ORM tests .

+11
source
+1
source

All Articles