Java 如何使用mysql';s";使用索引();hibernate标准中的子句?
我在我的项目中使用CriteriaAPI,但是从hibernate创建的查询速度非常慢 当我对查询运行explain时,我发现没有使用所需的索引。所以我尝试使用MYSQL提供的Java 如何使用mysql';s";使用索引();hibernate标准中的子句?,java,mysql,hibernate,criteria-api,Java,Mysql,Hibernate,Criteria Api,我在我的项目中使用CriteriaAPI,但是从hibernate创建的查询速度非常慢 当我对查询运行explain时,我发现没有使用所需的索引。所以我尝试使用MYSQL提供的“use index()”子句,查询只花了5秒。花了70秒 但问题是我正在使用criteria API,我想知道criteria API中是否有使用“use index()”子句的选项。尽管已使用HQL进行了测试,但它也可能与criteria API一起工作 您基本上定义了一个新的Hibernate函数,因此对于此HQL:
“use index()”
子句,查询只花了5秒。花了70秒
但问题是我正在使用criteria API,我想知道criteria API中是否有使用“use index()”
子句的选项。尽管已使用HQL进行了测试,但它也可能与criteria API一起工作
您基本上定义了一个新的Hibernate函数,因此对于此HQL:
您将得到以下SQL:
select table
from MyTable table
where useindex(table, my_index) is true and table.feature is not null
select table
from MyTable table
where useindex(table, my_index) is true and table.feature is not null