14

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!

4

1 回答 1

23

我认为您可以为此使用with_hint()

例如

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

老实说,我真的不知道这一点。我通过在他们的ORM 测试中找到“使用索引”来发现它。

于 2012-10-05T02:26:11.757 回答