Above 2 lakh makes server crash : mysql 5.1, fedora 8

Reply

Join Date: Apr 2005
Posts: 183
Reputation: hbmarar is an unknown quantity at this point 
Solved Threads: 0
hbmarar's Avatar
hbmarar hbmarar is offline Offline
Junior Poster

Above 2 lakh makes server crash : mysql 5.1, fedora 8

 
0
  #1
Nov 27th, 2008
Hi,

For 2 lakh records, this works well but when the total number of queries is more than 5 lakh it does not . Actually i have 64 lakh records to work with and this gets forever.
  1. UPDATE tmp_yk_contributor SET score_last_update = '$date' , ykscore = (IFNULL((SELECT avg(score)*0.8 FROM yk_entity_score WHERE yk_entity_score.user_id = tmp_yk_contributor.user_id) , 4) + IFNULL((SELECT avg(participation_score)*2 FROM yk_participation_score WHERE yk_participation_score.user_id = tmp_yk_contributor.user_id), 1)) WHERE tmp_yk_contributor.user_id IS NOT NULL ;
>desc yk_contributor
+--------------------+--------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+--------------+------+-----+---------------------+----------------+
| contributor_id | int(10) | NO | PRI | NULL | auto_increment |
| type | char(1) | NO | MUL | E | |
| identifier | varchar(255) | NO | | | |
| verified | char(1) | NO | | N | |
| ykscore | float | YES | | NULL | |
| user_id | int(11) | YES | MUL | NULL | |
| primary_identifier | char(1) | NO | | N | |
| date_added | date | NO | | 0000-00-00 | |
| score_last_update | datetime | NO | | 0000-00-00 00:00:00 | |
| opt_out | char(1) | YES | | N | |
| image | blob | YES | | NULL | |
+--------------------+--------------+------+-----+---------------------+----------------+
and
tmp_yk_contributor above in query is the temporary table made of yk_contributor.

Explain of individual queries gives me the following:
  1. mysql> EXPLAIN SELECT avg(participation_score)*2 FROM yk_participation_score,yk_contributor WHERE yk_participation_score.user_id = yk_contributor.user_id
-> ;
+----+-------------+------------------------+------+---------------+---------------+---------+-----------------------------------------+---------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------------------+------+---------------+---------------+---------+-----------------------------------------+---------+--------------------------+
| 1 | SIMPLE | yk_participation_score | ALL | NULL | NULL | NULL | NULL | 1041624 | |
| 1 | SIMPLE | yk_contributor | ref | index_user_id | index_user_id | 5 | scorecsa.yk_participation_score.user_id | 56924 | Using where; Using index |
+----+-------------+------------------------+------+---------------+---------------+---------+-----------------------------------------+---------+--------------------------+
2 rows in set (0.00 sec)
  1. mysql> EXPLAIN SELECT avg(score)*0.8 FROM yk_entity_score,yk_contributor WHERE yk_entity_score.user_id = yk_contributor.user_id
  2. -> ;
+----+-------------+-----------------+-------+-------------------------------+-------------------------------+---------+---------------------------------+---------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-----------------+-------+-------------------------------+-------------------------------+---------+---------------------------------+---------+-------------+
| 1 | SIMPLE | yk_contributor | index | index_user_id | index_user_id | 5 | NULL | 1024638 | Using index |
| 1 | SIMPLE | yk_entity_score | ref | index_yk_entity_score_user_id | index_yk_entity_score_user_id | 5 | scorecsa.yk_contributor.user_id | 1 | Using where |
+----+-------------+-----------------+-------+-------------------------------+-------------------------------+---------+---------------------------------+---------+-------------+
2 rows in set (23.52 sec)

I am stuck here and do not know how to go ahead with some optimisation. Request some help. thanks in advance

Saff
Last edited by peter_budo; Nov 28th, 2008 at 12:49 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: varmadba is an unknown quantity at this point 
Solved Threads: 8
varmadba varmadba is offline Offline
Junior Poster in Training

Re: Above 2 lakh makes server crash : mysql 5.1, fedora 8

 
0
  #2
Dec 1st, 2008
  1.  
  2. 1.
  3. mysql> EXPLAIN SELECT avg(participation_score)*2 FROM yk_participation_score,yk_contributor WHERE yk_participation_score.user_id = yk_contributor.user_id
  4.  
  5. mysql> EXPLAIN SELECT avg(participation_score)*2 FROM yk_participation_score,yk_contributor WHERE yk_participation_score.user_id = yk_contributor.user_id
  6. -> ;
  7. +----+-------------+------------------------+------+---------------+---------------+---------+-----------------------------------------+---------+--------------------------+
  8. | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
  9. +----+-------------+------------------------+------+---------------+---------------+---------+-----------------------------------------+---------+--------------------------+
  10. | 1 | SIMPLE | yk_participation_score | ALL | NULL | NULL | NULL | NULL | 1041624 | |
  11. | 1 | SIMPLE | yk_contributor | ref | index_user_id | index_user_id | 5 | scorecsa.yk_participation_score.user_id | 56924 | USING WHERE; USING index |
  12. +----+-------------+------------------------+------+---------------+---------------+---------+-----------------------------------------+---------+--------------------------+
  13. 2 rows IN SET (0.00 sec)

it clearly says on yk_participation_score database is doing a full table scan

Does yk_participation_score have any index on user_id?
Does yk_contributor have index on user_id?

if not add index on these 2 tables on user_id column and review explain o/p
:- Varma

We are Happy to inform launch of a new site with loads of database related information Site offers wide range of functionality Forums,Blogs,Articles,Editorials and much more
http://www.sqllibrarian.info/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC