Hey, so let's say i'm building this contact management system. There is a USER table and a CONTACT_INFO table. For every USER, I can have zero or more CONTACT_INFO records. The way I've defined it, I've setup a foreign key in my CONTACT_INFO table to point to the relevant USER record.
I would like do a search for all the USER records that do not have CONTACT_INFO records.
I expect that this could be done:
SELECT * FROM user u WHERE u.user_id NOT IN (SELECT DISTINCT c.user_id FROM CONTACT_INFO);
My concern is that as the tables grow, this query's performance can degrade significantly.
One idea I'm playing with is to add a column in the USER table that says if it has any CONTACT_INFO records or not. Also, I was wondering, if upon inserting any record into CONTACT_INFO, the DBMS has to verify that the record exists, it would already be accessing that record for the sake of verification and so updating it, when I update a CONTACT_INFO record should not be that costly, performance-wise.
As always, feedback is appreciated.