I need to maintain an application of mass email sender. The last programmer did a nice job, but the boss feel that a little optimizations could be done on the database treatment. When a campaing is finished, the report gives the option to save the selected segment. For instance, we send 50000 emails, and we want to save the segment of people who open the newsletter (2000) The tool now creates a new segment duplicating the contacts (with an INSERT), but I think we could improve the tool by saving the id of each contact.
I would like to know if saving the contacts whith an sql IN statement would increase the performance of the tool, or there is another way to perform this. Something like:
-
Create a list of the ids of the contacts SELECT * FROM contacts
-
SELECT * FROM contacts WHERE idContact IN (all_contacts_comma_separated) –> I would save
this
Thanks in advance
PD: It’s a production environment, so I need to be sure before made any changes 🙁
You didn’t say where the list of people who opened the email currently resides. If it’s not in the database what code/process will you use to generate your
INstatement list? If it is in the database why notJOINyour tables to get the information?Either way I’d not recommend using
INwhen you have 2000 items in the list.It might also be worth you reading the following:
SQL Server: JOIN vs IN vs EXISTS – the logical difference
It’s written with SQL server in mind (and I’m not sure it all directly applies to MySQL) but the concepts are interesting and you should perform testing before changing your production environment, as eggyal’s comment suggested.