我需要一些帮助来优化这个WordPress/WooCommerce查询:
SELECT
p.ID AS order_id
,DATE(p.post_date) AS order_date
,SUBSTR(comment_content,17) AS csr
,SUBSTR(p.post_status,4) AS order_status
,UCASE(CONCAT((SELECT wp_postmeta.meta_value FROM wp_postmeta WHERE meta_key = '_billing_first_name' and wp_postmeta.post_id = p.ID),' ',(SELECT wp_postmeta.meta_value FROM wp_postmeta WHERE meta_key = '_billing_last_name' and wp_postmeta.post_id = p.ID))) AS customer
,(SELECT GROUP_CONCAT(DISTINCT order_item_name ORDER BY order_item_name ASC SEPARATOR ', ') FROM wp_woocommerce_order_items WHERE order_id = p.ID AND order_item_type = 'line_item' GROUP BY order_id) AS products
,(SELECT GROUP_CONCAT(CONCAT(serial_number,'',serial_feature_code)) FROM wp_custom_serial WHERE wp_custom_serial.order_id = p.ID GROUP BY wp_custom_serial.order_id) AS serials
FROM
wp_posts AS p
INNER JOIN wp_comments AS c ON p.ID = c.comment_post_ID
INNER JOIN wp_postmeta AS pm ON p.ID = pm.post_id
WHERE
p.post_type = 'shop_order'
AND comment_content LIKE 'Order placed by%'
GROUP BY p.ID
ORDER BY SUBSTR(comment_content,17) ASC, p.post_date DESC;
我不明白EXPLAIN
告诉我的是什么,我需要一些关于如何加快它的指导.谁能描述一下,在EXPLAIN
的回复中,什么表明了我的问题所在,以及在哪里可以找到答案?
id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
---|---|---|---|---|---|---|---|---|---|---|---|
1 | PRIMARY | c | NULL | ALL | comment_post_ID | NULL | NULL | NULL | 20452 | 11.11 | Using where; Using temporary; Using filesort |
1 | PRIMARY | p | NULL | eq_ref | PRIMARY,post_name,type_status_date,post_parent,post_author | PRIMARY | 8 | db.c.comment_post_ID | 1 | 50.00 | Using where |
1 | PRIMARY | pm | NULL | ref | post_id | post_id | 8 | db.c.comment_post_ID | 33 | 100.00 | Using index |
2 | DEPENDENT SUBQUERY | wp_postmeta | NULL | ref | post_id,meta_key | post_id | 8 | func | 33 | 2.26 | Using where |
3 | DEPENDENT SUBQUERY | wp_postmeta | NULL | ref | post_id,meta_key | post_id | 8 | func | 33 | 2.30 | Using where |
4 | DEPENDENT SUBQUERY | wp_woocommerce_order_items | NULL | ref | order_id | order_id | 8 | func | 2 | 10.00 | Using where |
5 | DEPENDENT SUBQUERY | wp_custom_serial | NULL | ALL | NULL | NULL | NULL | NULL | 5160 | 10.00 | Using where; Using filesort |