cmgmyr Posted April 23, 2008 Share Posted April 23, 2008 Hey All, I'm having a little problem with exporting data from my database. The problem is that the query seems to be too much for PHP and MySQL to handle since it is timing out. Here is the query: SELECT p.id, p.base_no, p.style_no, t1.name AS category1, t2.name as category2, t3.name as category3, p.metal, p.description, c.name as collection, p.price, pe.b2c_desc, pe.meta_title, pe.meta_desc, pe.meta_keys, pe.alt_tag, p.site FROM categories AS t1 LEFT JOIN categories AS t2 ON t2.parentid = t1.id LEFT JOIN categories AS t3 ON t3.parentid = t2.id INNER JOIN products AS p ON t3.id = p.categories_id LEFT JOIN collections AS c ON p.collection = c.id LEFT JOIN products_extended AS pe ON p.style_no = pe.style_no The categories table is a hierarchical setup (id, parentid, name). Do you guys have any ideas about how to make this function better? Any other solutions??? Thanks in advance, -Chris Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/ Share on other sites More sharing options...
cmgmyr Posted April 24, 2008 Author Share Posted April 24, 2008 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526126 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 If it's timing out, just change the timeout length of the script... Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526127 Share on other sites More sharing options...
cmgmyr Posted April 24, 2008 Author Share Posted April 24, 2008 I know that I can do that, but I was looking for a more efficient way to handle this query. If there isn't a solution that way I can change the timeout as a last resort. I don't really want the client waiting 5 min to download/upload and XL file though. Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526136 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 If it's a large database, there's not much you can do. Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526137 Share on other sites More sharing options...
cmgmyr Posted April 24, 2008 Author Share Posted April 24, 2008 It's about a medium size, there is about 1500 products in there right now. Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526149 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 There's no way to pull that entire query off and export the information in the default 30 second timeout. Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526151 Share on other sites More sharing options...
cmgmyr Posted April 24, 2008 Author Share Posted April 24, 2008 I know, I have it at 3 minutes right now. Even running it directly in phpMyAdmin takes 4-5 min usually. Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526155 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 There's honestly no way to optimize that query to run in 30 seconds, so you'd be better off setting a high timeout time and changing the Apache timeout directive. Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526164 Share on other sites More sharing options...
cmgmyr Posted April 24, 2008 Author Share Posted April 24, 2008 I went through the tables in the query and "indexed" all of the connecting columns that weren't already indexed or a key, now it runs in about 5 seconds. Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526291 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Oh, I figured you had indexed them already to try and optimize the time. Just be aware that inserting data will be slower now because MySQL needs to reindex every column every single time you insert a row. >_> Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526294 Share on other sites More sharing options...
cmgmyr Posted April 24, 2008 Author Share Posted April 24, 2008 No problem. Sometimes in the big projects you forget the "little" things until there is a problem. Lesson learned! Quote Link to comment https://forums.phpfreaks.com/topic/102597-solved-exporting-mysql-data-timeout-help/#findComment-526300 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.