![]() Topic awaiting preservation: Php MySQL Website dragging real slow - how do I speed it up??? (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: you tell me |
![]() Man we're on to initial deployment and so far my program seems to be really draggin itself real slow like. There doesn't seem to be anything wrong with the SQL for they seem optimised enough.. trhe problem comes on pages where search queries or results are listed out ... how do I optimise my code or do I have to tweak the server ? There are a load of function calls and I'm passing my user objects as parameters.... help guys !!! |
Paranoid (IV) Inmate From: Norway |
![]() Where is it slow ? at generating page or loading it in the browser ? |
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() ok... impossible to tell where it's slow without further information... code: function do_query($strQuery) { return mysql_query($strQuery); } with function do_query($strQuery) { $startTime = getmicrotime(); $result = mysql_query($strQuery); $timeNeeded = getmicrotime() - $startTime; writeToLog($strQuery,$timeNeeded); return $result; }
|
Bipolar (III) Inmate From: you tell me |
![]() Hmmmm after following your advice Tyberius I've found a couple of Queries that seem to be taking a bit more time than they actually should and the interesting part is that both these queries have like LEFT JOINS. But I can't think of a workaround for this - I heard somewhere that JOINS would slow down queries but how do I like make the change. Like for example here is one query : code: Select c.`id`, c.`salutation`, c.`first_name`, c.`last_name`, GROUP_CONCAT(d.`contact_comm` SEPARATOR ','), GROUP_CONCAT(d.`details` SEPARATOR ',') From contacts c LEFT Join cmm_details d ON c.`id` = d.`contact_item` AND d.`contact_item` = 'person' GROUP BY c.`id` ORDER BY c.`id` DESC
|
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() loops. code: explain Select c.`id`, c.`salutation`, c.`first_name`, c.`last_name`, GROUP_CONCAT(d.`contact_comm` SEPARATOR ','), GROUP_CONCAT(d.`details` SEPARATOR ',') From contacts c LEFT Join cmm_details d ON c.`id` = d.`contact_item` AND d.`contact_item` = 'person' GROUP BY c.`id` ORDER BY c.`id` DESC
|
Bipolar (III) Inmate From: you tell me |
![]() OK I've changed it a bit so now instead of it reading code: contacts c LEFT Join cmm_details d ON c.`id` = d.`contact_item` AND d.`contact_item` = 'person'
code: contacts c LEFT Join cmm_details d ON c.`id` = d.`contact_item` WHERE d.`contact_item` = 'person'
|
Maniac (V) Mad Scientist From: Rochester, New York, USA |
![]() Have you created indexes on your columns that you are joining on? |
Bipolar (III) Inmate From: you tell me |
![]() Interesting, I wasn't quite aware of this - none of my tables had any indexes apart from Primary keys... I've added an index to the required column in the table worked upon and the result is amazingly quick... The weird part is that the last guy who worked here also didn't put any indexes on the tables in the project he was working on - that was terribly slow man and now I think I know why. |
Paranoid (IV) Inmate From: Norway |
![]() |
Maniac (V) Mad Scientist From: Rochester, New York, USA |
![]() It is pretty easy to get into MySQL development, and indexes are something that a lot of people are not aware of, or think are some fearful thing to watch out for. |
Maniac (V) Mad Scientist with Finglongers From: Germany |
![]() Indices are a trade off. |
Bipolar (III) Inmate From: you tell me |
![]() I get the picture guys... I reindexed all my tables - added indexes on columns which were being use din conditional operations etc and its working great... |