I am trying to extract duplicate rows from my database. I have a listings table and a listings_meta table which holds additional information. The listings_meta table has over 16,000 rows. When I run the query below it runs REALLY slow.
I don’t understand why. Is there something wrong with my code?
SELECT l.id FROM listings AS l
LEFT JOIN listings_meta AS lm ON lm.listing_id = l.id AND lm.meta_key = 'email'
LEFT JOIN listings_meta AS lm2 ON lm2.listing_id = l.id AND lm2.meta_key = 'submitter_email'
WHERE lm.meta_value = 'test@test.com' OR lm2.meta_value = 'test@test.com' OR l.listing_title RLIKE 'Test'
GROUP BY l.id LIMIT 1
Are there certain things I can do to improve load time of large tables in general?
Indexes
Do you have any indexes – particularly on
LISTINGS_META.listing_id?I re-wrote your query as:
WHERE clause
RLIKE(any of the MySQL regex functionality for that matter) is on par with:Neither can make use of an index on the
LISTING.listing_titlecolumn…The best way to improve the
listing_titlesearch would be if theLISTINGtable is MyISAM, so you could add a Full Text Index to theLISTING.listing_titlecolumn in order to use:…but mind that the minimum word length is 3 characters for Full Text Searching (FTS)….