1

What is the best approach for searching?What will be difference if i filter the all data in controller and get result, and use where query in model and get result ?Please suggest your opinion.

2
  • 1
    Database engines are designed to work with large amounts of data. Application servers are not. Bring to your application only the data you need. Commented May 31, 2016 at 11:42
  • Basically - it depends from case-by-case on what data you're talking about, your datamodels, and what you want to do with it. A relational database is good at relational stuff and code layers are good at their things as well - so using the right tool for the job more than one-solution-fits-all. Commented May 31, 2016 at 11:48

1 Answer 1

1

It depends on the complexity of your query.. You can try to mesure the time of processing by putting flags in your code between each steps in order to measure the time of processing.

Then you make one test of speed processing like:

print time_flag 1
var results_sql_processing = *complex query* 
print time flag 2
var raw_results_script_processing = *dump query*
print time flag 3
var results_script_processing = *processing the data*
print time flag 4

and make sure results_script_processing == results_sql_processing. You can also set different datasets size (limit 100, 500, 1000) and see how the difference evolves between both solutions

Also, i would recommend to take a look at the query builders you might find in many frameworks (I use laravel's query builder). They are usually a very good compromise when the query isn't too complex (no data aggregation, complex concat,....), you can still use joins, union and many filters on them. But in case you want to get a super complex pivot table for instance, just build a strong sql query and then fire it in your code!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.