The choice of whether to retrieve more objects and then filter or just retrieve the correct objects in the first place depends on the underlying data. Most applications will use a combination of the two.
I would consider the following things:
Network bandwidth and memory requirements
If after filtering there are a small number of results, but a significantly larger number of results before filtering, then this can be a waste of resources and memory resources for filtering in code.
Request speed
Filtering results in a database can be more expensive than executing logic in code β disk and memory. Indexes are needed to make this useful.
maintainability
. sql . db, , .
Java, , . SingleMatcher MultipleMatcher . . , , , , .