c_pattle Posted December 9, 2011 Share Posted December 9, 2011 I have the following query that takes 69 seconds, which I reckon is going to be a tad bit too slow to use on a public facing website . I was wondering if anyone knows how I can speed up the query. SELECT product_data.*, products.supplier_ref, product_pricing.sales_price_inc_vat, products.type_id, MATCH(product_data.product_name) AGAINST ("Metacam") AS score FROM product_data, products, product_pricing WHERE products.type_id = 1 AND product_data.product_id=products.product_id AND product_data.product_id=product_pricing.product_id AND products.type_id = 1 ORDER BY score DESC LIMIT 20 Let me know if you want me to put the table structures on here but they are quite big! Thanks Link to comment https://forums.phpfreaks.com/topic/252824-query-takes-ages/ Share on other sites More sharing options...
fenway Posted December 9, 2011 Share Posted December 9, 2011 Start by posting EXPLAIN output -- my guess is that you don't have a full-text index, or that those joins aren't using indexes. Link to comment https://forums.phpfreaks.com/topic/252824-query-takes-ages/#findComment-1296231 Share on other sites More sharing options...
c_pattle Posted December 12, 2011 Author Share Posted December 12, 2011 Thanks, this was the results id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE product_data ALL NULL NULL NULL NULL 12432 Using temporary; Using filesort 1 SIMPLE product_pricing ALL NULL NULL NULL NULL 5558 Using where 1 SIMPLE products eq_ref PRIMARY PRIMARY 4 animed.product_data.product_id 1 Using where So I guess I need to add some indexes? Link to comment https://forums.phpfreaks.com/topic/252824-query-takes-ages/#findComment-1297037 Share on other sites More sharing options...
fenway Posted December 12, 2011 Share Posted December 12, 2011 Yup. A FULLTEXT index on (product_data.product_name). An INDEX on product_data.product_id. An INDEX on product_pricing.product_id. Link to comment https://forums.phpfreaks.com/topic/252824-query-takes-ages/#findComment-1297146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.