I have this SQL:
UPDATE products pr
SET pr.product_model_id = (SELECT id FROM product_models pm WHERE pm.category_id = 1 ORDER BY rand() LIMIT 1)
limit 200;
It took the mysql-server more then 15 seconds for these 200 records. and in the tablem there are 220,000 records.
why is that?
edit:
I have these tables which are empty, but I need to fill them with random information for testing.
True estimations shows that I will have:
80 categories
40,000 models
And, around 500,000 products
So, I've manually created:
- ALL the categories.
- 200 models (and used sql to duplicate them to 20k).
- 200 products (and duplicated them to 250k)
I need them all attached.
DB tables are:
categories {id, ...}
product_models {id, category_id, ...}
products {id, product_model_id, category_id}