MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMySQL 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 Dev Shed Forums Sponsor:
  #1  
Old January 6th, 2013, 11:35 PM
siva.wins siva.wins is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 siva.wins User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 7 sec
Reputation Power: 0
Mysql query performance issue

Hi,

We are having the batch job, it will receive the around 250000 records and upload into the mysql database.

table TB10_MESSAGE having aroung 1 crore record and TB60_TMP_MESSAGE_UPLOAD having 250000 records.

Below query executing aroung 6 hours ,

UPDATE TB10_MESSAGE SET TP_PREVIOUS_ACTIVATE_STATUS_DATE = TP_ACTIVATE_STATUS_DATE, TP_PREVIOUS_ACTIVATE_STATUS = TP_ACTIVE_STATUS,TP_ACTIVE_STATUS = 'S', TP_ACTIVATE_STATUS_DATE = NOW(), TP_LAST_REMOVE_DATE = NOW(), TP_QUANTITY = 0 where concat(TP_TAG_GROUPING_ID,TP_GP_NUMBER,TP_PART_NUMBER,TP_PIB_TYPE) NOT IN(select concat(TMP_TAG_GROUPING_ID,TMP_TP_GP_NUMBER,TMP_TP_PART_NUMBER,TMP_TP_PIB_TYPE) from TB60_TMP_MESSAGE_UPLOAD where TMP_TP_DEL IS NULL ) AND TP_PART_NUMBER is not null AND TP_ACTIVE_STATUS != 'S';

But we would to optimize the query. Please help me!

Reply With Quote
  #2  
Old January 7th, 2013, 02:45 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
How about something like this...

Code:
UPDATE TB10_MESSAGE x
  LEFT 
  JOIN TB60_TMP_MESSAGE_UPLOAD y
    ON y.TP_TAG_GROUPING_ID = x.TP_TAG_GROUPING_ID
   AND y.TP_GP_NUMBER       = x.TP_GP_NUMBER   
   AND y.TP_PART_NUMBER     = x.TP_PART_NUMBER 
   AND y.TP_PIB_TYPE        = x.TP_PIB_TYPE 
   AND y.TMP_TP_DEL IS NULL 
   SET TP_PREVIOUS_ACTIVATE_STATUS_DATE = TP_ACTIVATE_STATUS_DATE
     , TP_PREVIOUS_ACTIVATE_STATUS = TP_ACTIVE_STATUS
     , TP_ACTIVE_STATUS = 'S'
     , TP_ACTIVATE_STATUS_DATE = NOW()
     , TP_LAST_REMOVE_DATE = NOW()
     , TP_QUANTITY = 0 
 WHERE x.TP_PART_NUMBER is not null 
   AND x.TP_ACTIVE_STATUS != 'S';

Reply With Quote
  #3  
Old January 7th, 2013, 03:27 AM
siva.wins siva.wins is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 2 siva.wins User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m 7 sec
Reputation Power: 0
is below query is matched with intial posted query,

UPDATE TB10_MESSAGE M
LEFT
JOIN TB60_TMP_MESSAGE _UPLOAD T
ON (CONCAT(M.TP_TAG_GROUPING_ID,M.TP_GP_NUMBER,M.TP_PART_NUMBER,M.TP_PIB_TYPE)=concat(T.TMP_TAG_GROUPIN G_ID,T.TMP_TP_GP_NUMBER,T.TMP_TP_PART_NUMBER,T.TMP_TP_PIB_TYPE) AND T.TMP_TP_DEL IS NULL)
SET TP_PREVIOUS_ACTIVATE_STATUS_DATE = TP_ACTIVATE_STATUS_DATE
, TP_PREVIOUS_ACTIVATE_STATUS = TP_ACTIVE_STATUS
, TP_ACTIVE_STATUS = 'S'
, TP_ACTIVATE_STATUS_DATE = NOW()
, TP_LAST_REMOVE_DATE = NOW()
, TP_QUANTITY = 0
WHERE (T.TMP_TAG_GROUPING_ID IS NULL AND T.TMP_TP_GP_NUMBER IS NULL AND T.TMP_TP_PART_NUMBER IS NULL AND T.TMP_TP_PIB_TYPE IS NULL)
AND M.TP_PART_NUMBER IS NOT NULL
AND M.TP_ACTIVE_STATUS != 'S';

Reply With Quote
  #4  
Old January 7th, 2013, 04:06 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Mar 2008
Posts: 1,923 cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level)cafelatte User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 5 Days 16 h 21 m 8 sec
Reputation Power: 377
No. But I can see that my query should look more like this (still might be some errors)...
Code:
UPDATE tb10_message x
  LEFT 
  JOIN tb60_tmp_message_upload y
    ON y.tmp_tag_grouping_id = x.tp_tag_grouping_id
   AND y.tmp_gp_number       = x.tp_gp_number   
   AND y.tmp_part_number     = x.tp_part_number 
   AND y.tmp_pib_type        = x.tp_pib_type 
   AND y.tmp_tp_del IS NULL 
   SET tp_previous_activate_status_date = tp_activate_status_date
     , tp_previous_activate_status = tp_active_status
     , tp_active_status = 'S'
     , tp_activate_status_date = NOW()
     , tp_last_remove_date = NOW()
     , tp_quantity = 0 
 WHERE x.tp_part_number IS NOT NULL
   AND x.tp_active_status != 'S'
   AND y.tmp_tag_grouping_id IS NULL;

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Mysql query performance issue

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap