如何提示要在MySQL选择查询中使用的索引? [英] How to hint the index to use in a MySQL select query?

查看:232
本文介绍了如何提示要在MySQL选择查询中使用的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MySQL查询(正在运行MySQL 5.0.88),我正在尝试加快该查询的速度.基础表具有多个索引,并且对于所查询的查询,使用了错误的索引(i_active-16.000行,而i_iln-7行).

I have a MySQL query (running MySQL 5.0.88), which I'm trying to speed up. The underlying table has multiple indices and for the query in question, the wrong index is used (i_active - 16.000 rows, vs. i_iln - 7 rows).

我对MySQL不太熟悉,但是读到有一个use index提示,它可以迫使mySQL使用某个索引.我正在这样尝试:

I'm not very experienced with MySQL but read there is a use index hint, which can force mySQL to use a certain index. I'm trying it like this:

 SELECT art.firma USE INDEX (i_iln)
 ...

但这会产生MySQL错误.

but this produces a MySQL error.

问题:
谁能告诉我我在做什么错? (除了运行5.0.88,我无法更改.)

Question:
Can anyone tell me what I'm doing wrong? (Except running 5.0.88, which I can't change.)

推荐答案

您错过了

FROM table

正确的SQL应该是:

SELECT art.firma FROM your_table USE INDEX (i_iln) WHERE ....

这篇关于如何提示要在MySQL选择查询中使用的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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