当前位置:   article > 正文

mysql sqlalchemy 索引_SQLAlchemy中指定想要使用的索引

sqlalchemy force index

我们知道在MySQL中可以使用FORCE INDEX(index_name,...)来强制使用索引,那在SQLAlchemy如何指定呢?

经过多方查找和实践,我发现了一个叫with_hint的函数。

我们看下源码

def with_hint(self, selectable, text, dialect_name="*"):

r"""Add an indexing or other executional context hint for the given

selectable to this :class:`.Select`.

The text of the hint is rendered in the appropriate

location for the database backend in use, relative

to the given :class:`.Table` or :class:`.Alias` passed as the

``selectable`` argument. The dialect implementation

typically uses Python string substitution syntax

with the token ``%(name)s`` to render the name of

the table or alias. E.g. when using Oracle, the

following::

select([mytable]).\

with_hint(mytable, "index(%(name)s ix_mytable)")

<
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/527519
推荐阅读
相关标签
  

闽ICP备14008679号