我有两张完全相同的表 - products 和 products_temp。我想比较这两个表,我目前正在使用下面的查询,如果每个表中没有很多产品,它可以正常工作,但是我现在每个表中有大约 10,000 个,它需要永远运行,然后因错误而死' mysql服务器已经消失了'。
请查看下面的查询并建议我如何优化它
SELECT MIN( id ) AS id , product_id, product_name, program_id, program_name, deeplink, price, image_url, merchant_category, category_id, category_path, brand, last_updated, tab
FROM (
SELECT id , product_id, product_name, program_id, program_name, deeplink, price, image_url, merchant_category, category_id, category_path, brand, last_updated, 'Temp' AS tab
FROM products_temp AS alias1
UNION ALL
SELECT id , product_id, product_name, program_id, program_name, deeplink, price, image_url, merchant_category, category_id, category_path, brand, last_updated, 'Current' AS tab
FROM products AS alias2
)AS alias_table
GROUP BY id
HAVING COUNT( id ) =1 #