我正在构建一个角度测验应用程序与nodejs mysql作为后端。测验问题表具有诸如id、title、choice_a、choice_b..choice_d、subject_id fk、topic_id fk、rand1、rand2、rand3等字段
排序为id asc、id desc、rand1 asc、rand1 desc、rand2 asc、rand2 desc、rand3 asc、rand3 desc等,以使顺序随机化
rand字段包含随机分配的1- 20之间的值,以提供随机测验
我的问题是针对如下所示的查询
SELECT question.*,subject.title as subject_title,region.title as region_title,topic.title as topic_title FROM question LEFT JOIN subject ON
(question.subject_id = subject.id) LEFT JOIN region ON (question.region_id = region.id) LEFT JOIN topic ON (question.topic_id =
topic.id) WHERE ((question.subject_id = '4')) ORDER BY rand1 DESC LIMIT 20在这里,使用rand1(随机分配)过滤结果。现在我想知道为(subject_id,rand1)添加一个组合索引是否有帮助?
如果是这样,那么我将不得不为(subject_id,rand1) (subject_id,rand2) (subject_id,rand3) (subject_id,id)添加组合索引,因为它们是常用的过滤+排序组合?
在这种情况下,使用postgresql而不是mysql有帮助吗?
复合索引中的最大字段数是多少?
发布于 2015-11-22 10:27:02
我已经想出了答案。通过创建不同的复合索引,我能够将节点服务器的每秒请求数增加到两倍以上。复合索引很多,可以精确地优化频繁查询。通过在添加索引之前和之后对查询进行基准测试,我能够进行最大程度的优化。谢谢大家……
https://stackoverflow.com/questions/33850778
复制相似问题