If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Very Large Query Bring down our server.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-04-05, 09:03
Jeremy Ross Jeremy Ross is offline
Registered User
 
Join Date: Feb 2003
Posts: 12
Unhappy Very Large Query Bring down our server.

Hello,

I created a stats program, what happens is our Statistician puts all of his infromation into an MS Access database, and he uses a program to convert the access database into an SQL file. He then uploads the SQL file to the server, and I run a query on a table, that contains over 10 thousand recoards. When we do this MySQL will crash sometimes. I will paste the query here.

Code:
CREATE TABLE tmp_player_2 AS SELECT `Players`.`PID`, sum(`Players`.`GP`) AS `SumOfGamesPlayed`, sum(`Players`.`G`) AS `SumOfGoals`, sum(`Players`.`A`) AS `SumOfAssists`, sum(`Players`.`PIM`) AS `SumOfPIM`, sum(`Players`.`PTS`) AS `SumOfPTS`, sum(`Players`.`PPG`) AS `SumOfPowerPlayGoals`, sum(`Players`.`SHG`) AS `ShortHandedGoals`, sum(`Players`.`ENG`) AS `SumOfEmptyNetGoals`, sum(`Players`.`GW`) AS `SumOfGameWinner`, sum(`Players`.`TG`) AS `SumOfTG`, sum(`Players`.`IG`) AS `SumOfIG`, sum(`G`) / sum(`GP`) AS `SumOfGoalsPerGame`, sum(`PTS`) / sum(`GP`) AS `SumOfPointsPerGame`, sum(`PIM`) / sum(`GP`) AS `SumOfPIMPG`, `Player_IDS`.`Pos`, `Player_IDS`.`No`, `Player_IDS`.`TID` As TID, `Player_IDS`.`Name`, `Player_IDS`.`Rookie`, `Team_IDS`.`Team` FROM `Players` INNER JOIN `Team_IDS` ON (`Player_IDS`.`TID` = `Team_IDS`.`TID`) INNER JOIN `Player_IDS` ON (`Players`.`PID` = `Player_IDS`.`PID`) INNER JOIN `Games` ON (`Players`.`Game` = `Games`.`Game_ID`) WHERE (`Games`.`Type` = 2) GROUP BY `Players`.`PID
What would u recomend me do to this query that will make it work better? Also this query is ran 6 times total, with a rest of 20 seconds between all of them, but it will only crash on the 10 thounsand recoard table.

We are running MySQL 4.0.23-standard. Our server is a 3GHz, with 1GB of ram.
Reply With Quote
  #2 (permalink)  
Old 02-04-05, 09:10
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
do you have indexes defined for the columns being used in the joins?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-04-05, 09:31
Jeremy Ross Jeremy Ross is offline
Registered User
 
Join Date: Feb 2003
Posts: 12
Hello,

Thanks for the fast reply.

I just checked and the only feild that has a Key is the Players Table (with 10 thousand recoards) and that is on the ID feild, witch does not get used in the query.

Thanks,
Jeremy Ross
Reply With Quote
  #4 (permalink)  
Old 02-04-05, 09:55
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
in that case, how about creating some indexes, and running your query again
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-04-05, 13:14
Jeremy Ross Jeremy Ross is offline
Registered User
 
Join Date: Feb 2003
Posts: 12
Hello,

Thanks for the input. So adding index's to the tables would make the processing go faster? I don't want to make any trouble by chaning to much about the database. Just adding indexes to the ID's wouldn't be hard. I dont' want to add too many indexes to each table because that would slow it down, correct?

Thanks,
Jeremy
Reply With Quote
  #6 (permalink)  
Old 02-04-05, 14:28
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
yes, each index makes SELECTs much faster but INSERTs UPDATEs and DELETEs a tiny bit slower

so do the calculation, multiply out how many times per day that each type is executed, times either much or tiny
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 02-04-05, 19:05
jon3k jon3k is offline
Registered User
 
Join Date: Feb 2004
Posts: 10
Does MySQL support a bulk insert feature similiar to Microsoft SQL?

If not, any plans for it in the 5.x releases?
Reply With Quote
  #8 (permalink)  
Old 02-04-05, 19:10
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #9 (permalink)  
Old 02-05-05, 07:18
Jeremy Ross Jeremy Ross is offline
Registered User
 
Join Date: Feb 2003
Posts: 12
Thanks for all your help, I very much appreciate it! The database is now working great!

Thanks so much
Jeremy Ross
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On