I'm trying to run this query, and the table that's being updated has about 10,000 rows. The query takes so long to execute that I can't even be bothered to wait for the return.
In a couple hours this table will have 100,000 rows and so, it's going to take 10 times longer than it does already. Anyone have any ideas to optimize it?
UPDATE
`wpsapi4`.`product_details` AS `pd`,
`r2r`.`partmaster` AS `pm`,
`r2r`.`partpriceinv` AS `ppi`,
`r2r`.`manufacturer` AS `m`
SET
`pd`.`product_name`=`pm`.`ItemName`,
`pd`.`data_source`='R2R',
`pd`.`partmaster`=`pm`.`id`,
`pd`.`pu`=``.`ppi`.`DistributorPartNumberShort`,
`pd`.`de开发者_C百科scription_raw`=`pm`.`ItemDescription`,
`pd`.`dealer_price`=`ppi`.`MSRP`,
`pd`.`weight`=`pm`.`Weight`,
`pd`.`vendor_name`=`m`.`ManufacturerName`
WHERE
(
`pm`.`ManufacturerNumberShort`=`pd`.`vendor_number`
OR
`pm`.`ManufacturerNumberLong`=`pd`.`vendor_number`
)
AND
`pm`.`id`=`ppi`.`DistributorPartNumberShort`
AND
`ppi`.`DistributorID`=2
AND
`pm`.`ManufacturerID`=`m`.`id`
If you think it could be to do with the table structures then please say so, I can't really change the structure at this point but if you know where the indexes should be then that would be great. Indexes are already optimized on the r2r database.
The columns to index are the ones reference in your where clause.
Consider adding the following:
- An index on the pm.ManufacturerNumberShort column.
- An index on the pm.ManufacturerNumberLong column.
- An index on the pm.id column.
- An index on the pm.ManufacturerID column.
- An index on the ppi.DistributorPartNumberShort column.
- An index on the ppi.DistributorID column.
Based on input from Darhazer:
Consider adding one or more of the following:
- An index on the pm.ManufacturerNumberShort, pm.id, and pm.ManufacturerID columns.
- An index on the pm.ManufacturerNumberLong, pm.id, and pm.ManufacturerID columns.
- An index on the ppi.DistributorPartNumberShort and ppi.DistributorID columns.
You are doing an OR
on Vendor Number, I would start by making sure that you have an index on vendor number on both tables.
Looks to me that the other columns already should have indexes.
精彩评论