| | |
Above 2 lakh makes server crash : mysql 5.1, fedora 8
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
>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:
-> ;
+----+-------------+------------------------+------+---------------+---------------+---------+-----------------------------------------+---------+--------------------------+
| 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)
+----+-------------+-----------------+-------+-------------------------------+-------------------------------+---------+---------------------------------+---------+-------------+
| 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
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)
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 ;
+--------------------+--------------+------+-----+---------------------+----------------+
| 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)
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)
mysql> EXPLAIN SELECT avg(score)*0.8 FROM yk_entity_score,yk_contributor WHERE yk_entity_score.user_id = yk_contributor.user_id -> ;
| 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.
•
•
Join Date: Jun 2008
Posts: 79
Reputation:
Solved Threads: 8
MySQL 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 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)
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/
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/
![]() |
Other Threads in the MySQL Forum
- Previous Thread: getting the 3 queries as optimised single query.. is this possible
- Next Thread: Working with the TEXT datatype in MySQL
| Thread Tools | Search this Thread |
agplv3 alfresco amazon api artisticlicense aws bizspark camparingtocolumns changingprices cmg communityjournalism contentmanagement contractors copyright count court crm data database design developer development distinct drupal dui ec2 email enterprise eudora facebook form foss gartner gnu government gpl greenit groklaw groupware hiring hyperic images innerjoins insert ip joebrockmeier join journalism keyword kickfire laptop legal license licensing linux maintenance mariadb matchingcolumns metron micromanage microsoft microsoftexchange mindtouch montywidenius mozilla multiple music mysql mysqlcolumnupdating mysqldatetimeordermax() mysqlindex mysqlinternalqueries mysqlquery mysqlsearch news open-xchange opendatabasealliance opengovernment opensource oracle penelope php priceupdating query referencedesign reorderingcolumns saas select sharepoint simpledb single sourcecode spotify sql sugarcrm syntax table techsupport thunderbird virtualization





