Which is faster? Get a null record or check for existence?

I have a timer search. I am currently generating and querying the appropriate keys even if they do not exist (getting a null record) in a certain amount of time. Is there a better way to do this? Checking for the presence of a key, before receiving, for example?

thank

+3


source to share


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







All Articles