【发布时间】:2021-02-27 08:04:31
【问题描述】:
我有一个包含 1000 万个实体的 MySQL 数据库表。我必须搜索具有多个参数的实体。 示例:
select * from result_table where roll=12345 and reg=6789 and Exam='ABC';
我正在寻找一种有效的方法来使用 JPA 批量实体搜索或使用单个查询或任何其他优化选项的本机查询。 示例:
select * from result_table where roll=1234 and reg=1234 and exam='ABC';
select * from result_table where roll=1234 and reg=1234 and exam='DEF';
select * from result_table where roll=2222 and reg=3333 and exam='XYZ';
Mysql IN Operator 无法解决我的问题,因为 roll 和 reg 在不同的考试中可以相同。谢谢。
【问题讨论】:
-
为了改进显示的查询,通过组合 WHERE 中使用的所有 2 列以任意顺序创建复合索引。
CREATE INDEX idx ON result_table (roll, reg, exam); -
roll+reg+exam 唯一
标签: mysql hibernate jpa persistence