Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
  #1  
Old December 6th, 2003, 07:09 PM
pickleman78 pickleman78 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Dallas,TX,USA
Posts: 582 pickleman78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to pickleman78
Efficency

I need some help here, a website I work on had been shut down for running too many slow queries and overloading the server. I need some help here, where can I fund information on making my queries more efficent, or do any of you have any tips? Some of these select queries run on tables with over 10000 entries in them, and I need some advice. Any tips would be appreciated. Thanks

Reply With Quote
  #2  
Old December 6th, 2003, 10:43 PM
zackcoburn zackcoburn is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 184 zackcoburn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: Efficency

Show some of your queries in this thread. One tip I can give you immediately: if you are using select queries, only select the fields you are going to use. Don't fall into the trap of always using "select * from table".

Reply With Quote
  #3  
Old December 10th, 2003, 12:19 AM
pickleman78 pickleman78 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Dallas,TX,USA
Posts: 582 pickleman78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to pickleman78
RE: Efficency

# User@Host: username @ localhost []
# Query_time: 16 Lock_time: 0 Rows_sent: 0 Rows_examined: 1769

SELECT id, name, description, count(*), count(DISTINCT topicid),
max(timestamp), type,lockedf,theorder
FROM forums, posts where forumid=id group by forumid order by type
desc,forumid;


Thats the query that showed up the most in the slow log(approxamately 100 times in a very short time frame, I just got a shortened bersion of the log) The time on that query runs from 8-20, it varies. Any suggestions?

Reply With Quote
  #4  
Old December 10th, 2003, 06:53 AM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
RE: Efficency

Yipeeee, that is but a biiiig query.

Code:
SELECT id, name, description, count(*), count(DISTINCT topicid),
max(timestamp), type,lockedf,theorder
FROM forums, posts where forumid=id group by forumid order by type
desc,forumid;


So, what is problematic about this query? It has three agregate functions, one distinct and one order by. This is extreme load for one query.
But what to do with it? Question is if you really need all this informations. If you really need them, query will be slow. There is no way to avoid it.
So my sugestion is to think carefuly about "what information I really need?". Focus on agregate functions (count, max in your query), distinct and order by operators. Do you really need them all?

Reply With Quote
  #5  
Old December 10th, 2003, 11:35 AM
zombie zombie is offline
Codewalkers Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2007
Location: serbia
Posts: 1,876 zombie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: Efficency

you could cache some of the data returned by the query (like that agregate funcitons)

Reply With Quote
  #6  
Old December 11th, 2003, 12:34 AM
pickleman78 pickleman78 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Dallas,TX,USA
Posts: 582 pickleman78 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via AIM to pickleman78
RE: Efficency

So would it be more efficent to get the info, put into an array, then use PHP to sort it? that would be far less SQL load I beleive, and I have done some stuff with the count, like eliminated it, and the query across multiple tables with the count(I think the mysql manual advises against that). I didn't write most of these queries, this is a mess I have gotten stuck with after the previos programmer made a mess of things. Thanks for the help

Reply With Quote
  #7  
Old December 11th, 2003, 05:10 AM
Danicek Danicek is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Czech Republic
Posts: 79 Danicek User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to Danicek
RE: Efficency

Generaly: to do it in PHP would be much much slower. However if load on SQL server is very big, or if SQL server is very slow, it could be better to do it in array or to do part of it in array.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > Efficency


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway