I have a DB that stores some complex objects of my app. When my app starts I load the objects into list and store them on the RAM. But sometimes I would like to search for an objects that fulfills conditions (filtering), even the conditions are complexes.
I was always wrote a for loop (sometimes a very complex one) for this thing, that runs on these objects. But I heard recently that DB and SQL queries have a lot optimization mechanisms (dependent the DB company), and its works faster then regular search. If I understand it correctly, it's better to write a SQL query that search these objects and returns objects IDs. And then by them IDs, get the relevant objects.
Its look like the ultimate solution for searching objects.
But I'm a little bit doubtful about this idea, because all the time we learned that DB is slow, and it's better to load the objects to RAM and work on them...
So I have two questions:
1) Are the queries actually more faster then regular search (for complex searches)?
2) Maybe its true for many many objects (thousands), but is it true for few objects (tens)?