Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

should I use one large sql query in model or break it up into smaller queries?

I'm using codeigniter for one of my projects, and right now what I have is a table with PROJECT information, and I'm displaying all the PROJECTS in a specific view.

Now, I also want that same view to display other related information about the projects such as the number of views as well as the associated tags. But this would require multiple JOINS in the model(which would require me to alter the existing query...) but it would keep the view from having to call the model directly.

Would I get better performance if I simply break up the queries, and have 2 separate queries related to the other information in the VIEW? I find this to be more clear, but I wonder if it's slower since I'm calling the model for EACH project in a loop.

like image 710
Kira Avatar asked Jan 22 '26 13:01

Kira


1 Answers

Why dont you just code both - and test using CI Profilier?

Then you will be 100% sure. Furthermore - if the results are "close" you can just go with the option that suits your programming logic better.

p.s. you could also loop the multiple calls to the model into an array (like $projects) in the controller, and pass that variable to the view, so in either scenario the "view" is NEVER calling the "MODEL" directly.

like image 194
Laurence Avatar answered Jan 25 '26 04:01

Laurence



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!