[Solved] Do record types affect the performance of a migration with kingswaysoft?

How to optimize this SQL query?

In case you have your own slow SQL query, you can optimize it automatically here.

For the query above, the following recommendations will be helpful as part of the SQL tuning process.
You'll find 3 sections below:

  1. Description of the steps you can take to speed up the query.
  2. The optimal indexes for this query, which you can copy and create in your database.
  3. An automatically re-written query you can copy and execute in your database.
The optimization process and recommendations:
  1. Create Optimal Indexes (modified query below): The recommended indexes are an integral part of this optimization effort and should be created before testing the execution duration of the optimized query.
Optimal indexes for this query:
ALTER TABLE `LicenseMethod` ADD INDEX `licensemethod_idx_licensemethodid` (`LicenseMethodID`);
ALTER TABLE `RevisionHardware_Desktop` ADD INDEX `revisionhardware_d_idx_revisionhardwareid` (`RevisionHardwareID`);
ALTER TABLE `RevisionHardware_Server` ADD INDEX `revisionhardware_s_idx_revisionhardwareid` (`RevisionHardwareID`);
ALTER TABLE `RevisionHardware_iSeries` ADD INDEX `revisionhardware_i_idx_revisionhardwareid` (`RevisionHardwareID`);
ALTER TABLE `RevisionHardware_zSeries` ADD INDEX `revisionhardware_z_idx_revisionhardwareid` (`RevisionHardwareID`);
The optimized query:
SELECT
        rh.RevisionHardwareID AS 'Machine_Information_Id__c',
        COALESCE(lmi.Name,
        lmz.Name) AS 'License_Method__c',
        rhd.Servers AS 'Servers__c',
        rhd.Managers AS 'Managers__c',
        COALESCE(rhd.LicenseCount,
        rhs.CPUCount,
        rhz.MIPS,
        rhi.CPW) AS 'Quantity__c',
        CASE 
            WHEN rhd.RevisionHardwareID IS NOT NULL THEN '0122J00000023maQAA' 
            WHEN rhi.RevisionHardwareID IS NOT NULL THEN '0122J00000023mcQAA' 
            WHEN rhz.RevisionHardwareID IS NOT NULL THEN '0122J00000023mdQAA' 
            WHEN rhs.RevisionHardwareID IS NOT NULL THEN '0122J00000023mbQAA' END AS 'RecordTypeId' 
FROM
RevisionHardware rh 
LEFT JOIN
RevisionHardware_Desktop rhd 
    ON rhd.RevisionHardwareID = rh.RevisionHardwareID 
LEFT JOIN
RevisionHardware_iSeries rhi 
    ON rhi.RevisionHardwareID = rh.RevisionHardwareID 
LEFT JOIN
RevisionHardware_zSeries rhz 
    ON rhz.RevisionHardwareID = rh.RevisionHardwareID 
LEFT JOIN
RevisionHardware_Server rhs 
    ON rhs.RevisionHardwareID = rh.RevisionHardwareID 
LEFT JOIN
LicenseMethod lmi 
    ON lmi.LicenseMethodID = rhi.LicenseMethod_ISeriesID 
LEFT JOIN
LicenseMethod lmz 
    ON lmz.LicenseMethodID = rhz.LicenseMethod_ZSeriesID 
WHERE
CASE 
    WHEN rhd.RevisionHardwareID IS NOT NULL THEN 'Desktop' 
    WHEN rhi.RevisionHardwareID IS NOT NULL THEN 'iSeries' 
    WHEN rhz.RevisionHardwareID IS NOT NULL THEN 'zSeries' 
    WHEN rhs.RevisionHardwareID IS NOT NULL THEN 'Server' END IS NOT NULL

Related Articles



* original question posted on StackOverflow here.