I'm so bad in making good MySQL queries. I've created this one:
SELECT SQL_CALC_FOUND_ROWS
`products_stock`.`products_id`,
`products_stock`.`products_stock_attributes`,
`products_stock`.`products_stock_quantity`,
`products`.`manufacturers_id`,
`products_description`.`products_name`
FROM `products_stock`
LEFT JOIN `products`
ON `products_stock`.`products_id` = `products`.`products_id`
LEFT JOIN `products_description`
ON `products_stock`.`products_id` = `products_description`.`products_id`
LEFT JOIN `products_to_categories`
ON `products_stock`.`products_id` = `products_to_categories`.`products_id`
WHERE `products_stock`.`products_stock_quantity` >=3
AND `products`.`products_status` = 1
AND ISNULL(`products`.`products_image`) = false
AND `products`.`products_image` != ""
AND EXISTS(
select * from `allegro`
where `products_stock`.`products_id` = `allegro`.`product_id`
and `allegro`.`attributes` = `products_stock`.`products_stock_attributes`
) = false
products Table have about 17k rows,
allegro Table have about 3k of rows.
The query Idea is select all products, where stock_quanity > 3, where is photo, and where is no product id in allegro table.
Now the query takes about 10 seconds. I have no idea how I can optimize it.
@SOLVED
I've added indexes to allegro.product_id and allegro.attributes and now query tooks less than half of second. Thanks all for help