查询语句
SELECT customer_id,title,content FROM `product_comment` WHERE audit_status=1 AND product_id=199726 LIMIT 0,5
这里的索引有audit_status和product_id,可以建立联合索引。但是哪个放左边就要计算区分度。
计算方法
SELECT COUNT(DISTINCT audit_status)/COUNT(*) AS audit_rate, COUNT(DISTINCT product_id)/COUNT(*) AS product_rate FROM product_comment;
区分度越高越好,放左边。结论product_rate>audit_rate
建立联合索引
CREATE INDEX idx_productID_auditStatus ON product_comment(product_id,audit_status)