I have a join which deletes rows that match another table but the joining fields have to be a large varchar (250 chars). I know this isn’t ideal but I can’t think of a better way. Here’s my query:
DELETE P
FROM dbo.FeedPhotos AS P
INNER JOIN dbo.ListingPhotos AS P1 ON P.photo = P1.feedImage
INNER JOIN dbo.Listings AS L ON P.accountID = L.accountID
WHERE P.feedID = @feedID
This query is constantly timing out even though there are less than 1000 rows in the ListingPhotos table.
Any help would be appreciated.
I’d probably start by removing this line, as it doesn’t seem to be doing anything:
There might not be a lot of rows in
ListingPhotos, but if there are a lot of rows inListingsthen the join won’t be optimized out.Also check your indexing, as any join is bound to be slow without the appropriate indexes. Although you should generally try to avoid joining on character fields anyway, it’s usually a sign that the data is not normalized properly.