943,856 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 906
  • MySQL RSS
Nov 27th, 2008
0

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

Expand Post »
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.
sql Syntax (Toggle Plain Text)
  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:
sql Syntax (Toggle Plain Text)
  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)
sql Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Junior Poster
hbmarar is offline Offline
187 posts
since Apr 2005
Dec 1st, 2008
0

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

MySQL Syntax (Toggle Plain Text)
  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
Reputation Points: 22
Solved Threads: 9
Junior Poster in Training
varmadba is offline Offline
83 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: getting the 3 queries as optimised single query.. is this possible
Next Thread in MySQL Forum Timeline: Working with the TEXT datatype in MySQL





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC