Which is faster? Get a null record or check for existence?
1 answer
Just find the records you want.
My rule of thumb is, "If you really only need to know if a key exists, just check it out. However, if the first thing you're going to do for an existing key is to get a value, then just get the values."
To check if it exists, it must do a key search. The only difference between this and returning a value is actually getting the value. The get operation would have done the same search. If the value is none, then there is no additional overhead to return the value, other than a couple of extra bytes to store "null" instead false
. However, if you only need to know that the key exists, then there is no reason to return the entire content, if any.
+6
source to share