I have two very big tables interleaved by its primary key (just one column, so it is one-to-one relationship). A few rows on the parent table have no child on the other and I want to find them.
Currently, I am doing a JOIN query and searching by NULL values:
SELECT Users.userID
FROM Users
LEFT JOIN Licenses
ON Users.userID = Licenses.userID
WHERE Licenses.license IS NULL
But this query still needs to read all Users table to do the JOIN, what is really slow.
I know that if the license column was in the table Users I could create an index with it and would only need to read the rows with NULL license values, but it is not an option to put the column "license" in the same "Users" table.
Is there a way to just pass through the userIDs that do not have yet a license using different tables? e.g. an index with columns from different tables. (I am using interleaved but would it be better foreign keys?)