django mysql强制使用索引 [英] django mysql force usage of index

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

问题描述

我正在使用django orm和mysql。
从某种原因mysql使用错误的索引。
我想手动覆盖使用的索引。
我看到django团队从跨平台的原因决定了阻止使用强制索引的add_hints扩展名。
如果解决方案\建议我有什么可以让mysql使用正确的索引然后通过django吗?



谢谢

解决方案

Django支持原始的sql查询以满足您的需要,请参阅文档文章执行原始SQL查询


当模型查询API不够远,您可以回到编写原始SQL。 Django为您提供执行原始SQL查询的两种方式:可以使用Manager.raw()来执行原始查询并返回模型实例,也可以完全避免模型层,并直接执行自定义SQL。



I'm using django orm and mysql. From some reason mysql is using the wrong index. I want to manually override the index used. I saw that the django team decided from cross platform reason to prevent usage of with_hints extension that would force an index. Does anyone have any kind if solution \ proposal how I could get mysql to use the correct index then through django?

Thanks

解决方案

Django supports raw sql queries to fit your needs, see the documentation article Performing raw SQL queries.

When the model query APIs don’t go far enough, you can fall back to writing raw SQL. Django gives you two ways of performing raw SQL queries: you can use Manager.raw() to perform raw queries and return model instances, or you can avoid the model layer entirely and execute custom SQL directly.

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

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