如何提示要在 MySQL 选择查询中使用的索引?

2023-10-25数据库问题
3

本文介绍了如何提示要在 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 应该是:

Correct SQL should be:

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

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

The End

相关推荐

Mysql目录里的ibtmp1文件过大造成磁盘占满的解决办法
ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致...
2025-01-02 数据库问题
151

按天分组的 SQL 查询
SQL query to group by day(按天分组的 SQL 查询)...
2024-04-16 数据库问题
77

SQL 子句“GROUP BY 1"是什么意思?意思是?
What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)...
2024-04-16 数据库问题
62

MySQL groupwise MAX() 返回意外结果
MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)...
2024-04-16 数据库问题
13

MySQL SELECT 按组最频繁
MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)...
2024-04-16 数据库问题
16

在 Group By 查询中包含缺失的月份
Include missing months in Group By query(在 Group By 查询中包含缺失的月份)...
2024-04-16 数据库问题
12