SELECT DISTINCT p.products_id, p.sj_id, p.px_id, p.products_model, p.products_p_w_picpath, pd.products_name
FROM products AS p LEFT JOIN products_description AS pd ON pd.products_id=p.products_id
WHERE 1 AND p.products_status=1 ORDER BY p.products_date_added DESC LIMIT 0, 20;
功能上线后,发现非常慢。
explian
+----+-------------+-------+------+---------------+---------+---------+-----------------------------+-------+----------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+---------+---------+-----------------------------+-------+----------------------------------------------+
| 1 | SIMPLE | p | ALL | NULL | NULL | NULL | NULL | 71180 | Using where; Using temporary; Using filesort |
| 1 | SIMPLE | pd | ref | PRIMARY | PRIMARY | 4 | banggood_work.p.products_id | 1 | |
+----+-------------+-------+------+---------------+---------+---------+-----------------------------+-------+----------------------------------------------+