I am trying to figure out the best way to handle inserting/updating/deleting large lists.
Specifically, my users need to select large lists of products and they will get reports on those items every night.
To oversimplify it, here is the data model (a simple many to many)
~ 5000 records total
+----------+------------+
| user_id | user_name |
+----------+------------+
| 1 | Ralph |
| 2 | Bill |
| 3 | Joe |
| 4 | Mike |
| 5 | Brian |
| 6 | Jose |
+----------+------------+
~ 6000 records total
+------------+------------+
| product_id | product |
+------------+------------+
| 1 | Widget A |
| 2 | Widget B |
| 3 | Widget C |
| 4 | Widget D |
| 5 | Widget E |
| 6 | Widget F |
+------------+------------+
As many as 30 million total
+----------+------------+
| user_id | product_id |
+----------+------------+
| 1 | 1 |
| 1 | 4 |
| 1 | 6 |
| 2 | 2 |
| 2 | 4 |
| 2 | 5 |
+----------+------------+
The problem is that the products are selected in bulk, so if a user clicks select all (which they frequently do), they are selecting approximately 6000 products which equates to a large insert query.
Also, they can update and delete these lists based off of a bunch of different criteria such as what categories they fall in, price points, etc.
Every time they want to update their list I have to retrieve the products they've selected, delete the products they have deselected, and then insert any new products.
The process seems cumbersome at best and I'd like to know if there is a better solution.
I considered instead of storing the products the users want, store only the product the user doesn't want thereby limiting the overhead of frequent large insert/update queries. This way, every user get's every product available by default.
The problem with that solution is when new items arrive the user may not want those items in the report so then I'll have to maintain a separate table that stipulates what the default items are.
Many thanks to whomever can help me out.
Edit: Just for clarification, the users are not restricted to only selection criteria. They can also directly select products and groups of products. The users are unique in that they are all intimately familiar with the products (most know of almost all 6000 of the items).