Efficiency Question

Options
Hello! 

Context: 
I have 2 tables, User and User Invite. I would like to check if a User or User Invite already exists, before creating a new User Invite record, in bulk (so inviting a list of email addresses to the application). 

Question on which approach is more efficient with regards to Xano:
A) 
1. Query all records for both User and User Invite tables. 
2. For Each loop that checks each email address against the list from A1. 
3. Creates User Invite if A2 is false

B) 
• For Each loop that: 1. Checks if any User exists with the email address
2. Checks if any User Invite exists with the email address
3. Creates User Invite if false in both B1 and B2.

Comments

  • Ray Deck
    Ray Deck Trusted Xano Expert ✭✭✭
    Options
    In almost every situation, B is far more efficient. You can make it screamingly fast if you add a unique index to the email address field (which, if email address is unique in your business model, should work fine).

    There are limited circumstances where A is more efficient, but that would require knowing more details about relative data sizes of your tables and invite actions. But intuitively this seems unlikely. 
  • Felix Tan-2030210
    Options
    Thanks Ray! :))