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 > Slow performance

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-27-11, 07:22
sudiptaaps sudiptaaps is offline
Registered User
 
Join Date: Jul 2011
Location: Kolkata, West Bengal, India
Posts: 1
Slow performance

Hi!
I'm 1st time in this site and hope you all are fine.

Please consider the following SQL:

SELECT ptntPatientDetails.patientID,
CF.CustomField,
CF.FiledTitle,
CF.fieldValue
FROM ptntPatientDetails
LEFT JOIN
(

SELECT customFieldMaster.customFieldID AS CustomField,
customFieldMasterLang.customFieldTitle AS FiledTitle,
GROUP_CONCAT(CAST(IF((customFieldMaster.fieldTypeI D = 1 OR customFieldMaster.fieldTypeID = 2),
ptntPatientToCustomFieldMatchDetails.fieldDetailsV alue,
COALESCE(IF((ptntPatientToCustomFieldMatchDetails. isChecked=1),customFieldTypeDetails.fieldOptionNam e,NULL))) AS CHAR)) AS fieldValue,
ptntPatientToCustomFieldMatch.patientID
FROM
customFieldMaster
INNER JOIN customFieldMasterLang
ON customFieldMaster.customFieldID = customFieldMasterLang.customFieldID

INNER JOIN customFieldTypeDetails
ON customFieldMaster.customFieldID = customFieldTypeDetails.customFieldID

LEFT JOIN ptntPatientToCustomFieldMatch
ON customFieldTypeDetails.customFieldID = ptntPatientToCustomFieldMatch.customFieldID
LEFT JOIN ptntPatientToCustomFieldMatchDetails
ON (customFieldTypeDetails.fieldDetailsID = ptntPatientToCustomFieldMatchDetails.fieldDetailsI D
AND ptntPatientToCustomFieldMatch.ID = ptntPatientToCustomFieldMatchDetails.ID)
WHERE customFieldMaster.statusID = 1
AND customFieldMaster.isDeleted = 0
AND customFieldTypeDetails.isDeleted = 0
AND customFieldMasterLang.langID = 1
GROUP BY ptntPatientToCustomFieldMatch.patientID,customFiel dMaster.customFieldID
ORDER BY ptntPatientToCustomFieldMatch.patientID

) CF
ON ptntPatientDetails.patientID = CF.patientID
WHERE ptntPatientDetails.isDeleted = 0;


in the inner part the alias CF is executing in few seconds as per expectation, but when it is Left joined with `ptntPatientDetails` it slows down and takes several minutes. I'm using MySQL 5.1

`ptntPatientDetails` contains all the patients records

(total patients >6000, total rows returned >12044)

CF returns like this:

Customfield FiledTitle value patientID
1 SSN 1234 5000
2 Hobby swiming 5000
1 SSN 5678 5001
1 SSN 7484 5020

but it does not returns all patients, i.e. patients not associated with any customfiled or have not entered values for any field, but as I need to return all the patients even if they don't entered value for any cusomfield, I left joined as:
ptntPatientDetails left join ( SELECT customFieldMaster.customFieldID,....)CF

so that I can have all the patients at least with null values if they didn't entered value.
but due to this join it slows down( result of CF returns multiple rows for a patient depending upon no. of custom field but in `ptntPatientDetails` only single row per patient).

any help will be appreciated.
tell me am I clear or need further specification..
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