Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which is better, filtering results at db or application?

A simple question. There are cases when I fetch the data and then process it in my BLL. But I realized that the same processing/filtering can be done in my stored procedure and the filtered results returned to BLL.

Which is better, processing at DB or processing in BLL? And Why?

consider the scenario, I want to check whether a product exists in my db and if it exists add that to the order (Example taken from answer by Nour Sabony below)now i can do this checking at my BLL or I an do this at the stored procedure as well. If I combine things to one procedure, i reduce the whole operation to one db call. Is that better?

like image 999
shashi Avatar asked Nov 29 '22 04:11

shashi


1 Answers

At the database level.

Databases should be optimized for querying, so why go through all the effort to return a large dataset, and then do filtering in your application afterwards?

like image 104
LittleBobbyTables - Au Revoir Avatar answered Dec 23 '22 14:12

LittleBobbyTables - Au Revoir