DEV Community

loading...

Discussion on: When query db should I check if data exists first then select it ?

Collapse
molly profile image
Molly Struve (she/her)

I actually wrote a post that talks about tradeoffs of making lots of database hits even if they are simple. You might find it helpful!

In your scenario it really depends.

  • How many of these selects are you making?
    • If you are making millions then it might not be worth it to double up the hits.
  • How big is the expected data set you are going to get back?
    • If you have a large dataset coming back then it might be worth it to do the exists. If the dataset is small then it is probably not worth it.