[英]How too speed up a UNION TABLE query on milion record mysql?
这是我的查询
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 ";
现在使用phpmyadmin开发php。
每张桌子只有4列
如何使其更快?
您不需要外部子查询:
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
我认为您的LIKE
条件将导致product_name
列上的索引不可用,从而导致全表扫描。 但是也许您可以改善搜索方法以利用索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.