SQLalchemy指定要使用的索引 [英] SQLalchemy specify which index to use

查看:268
本文介绍了SQLalchemy指定要使用的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQLalchemy中有没有办法告诉查询要使用哪个索引?

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

我需要这个的原因是它生成的SQL查询使用错误 index - 存在一个完全包含两个字段的索引,它没有使用它。

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.

谢谢!

推荐答案

我认为你可以使用 with_hint()

例如

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

老实说,我真的不知道这件事;我通过在他们的 ORM测试中找到'USE INDEX'来发现它

Honestly, I didn't really know about this; I discovered it by finding 'USE INDEX' in their ORM tests.

这篇关于SQLalchemy指定要使用的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆