[英]How too speed up a UNION TABLE query on milion record mysql?
this is my query 这是我的查询
SELECT * FROM (
SELECT simple_sku, picture_url, product_name, discounted_price, tracking_link, 'Lazada.co.id' AS table_identity
FROM `list_lazada`
UNION
SELECT id_product, picture_url, product_name, sale_price, tracking_link, 'Simulation.com' AS table_identity
FROM `list_simulation`
) AS big_table
WHERE product_name LIKE '%$search%' ORDER BY big_table.discounted_price ASC
LIMIT 12 ";
now develop php with phpmyadmin. 现在使用phpmyadmin开发php。
Every table has 4 coloumn only 每张桌子只有4列
How to make it faster? 如何使其更快?
You don't need the outer subquery: 您不需要外部子查询:
SELECT simple_sku, picture_url, product_name, discounted_price, tracking_link,
'Lazada.co.id' AS table_identity
FROM `list_lazada`
UNION
SELECT id_product, picture_url, product_name, sale_price, tracking_link,
'Simulation.com' AS table_identity
FROM `list_simulation`
WHERE product_name LIKE '%$search%'
ORDER BY discounted_price ASC
LIMIT 12
I think your LIKE
condition will render an index on the product_name
column not usable, resulting in a full table scan. 我认为您的
LIKE
条件将导致product_name
列上的索引不可用,从而导致全表扫描。 But maybe you can improve your search approach to take advantage of an index. 但是也许您可以改善搜索方法以利用索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.