Welcome Guest, Not a member yet? Register   Sign In
count_all_results() - is it optimized?
#1

So what is faster? $this->db->count_all_results()
or manually write a query and get count result?
Reply
#2

I think that the ideal is use the cli for mysql in CI, I don't sure what is more fast method, in my case ever try to use the CI cli mode, I mean to this method in modal side:

$this->db->count_all_results();

Anyway you can use maybe this in your views printing the load time showing the load time:

{elapsed_time}

And test in different pages each one with one method :-), or think thats better use the class Benchmarking:

https://www.codeigniter.com/userguide3/l...hmark.html
Reply
#3

(10-17-2017, 09:56 AM)glorsh66 Wrote: So what is faster? $this->db->count_all_results()
or manually write a query and get count result?

I'd recommend you to use the built-in method in CodeIgniter for this purpose, this is, $this->db->count_all_results().

There are two reasons:

- CodeIgniter code is optimized to ensure not only speed, but also security in each operation.

- If you don't use CodeIgniter as it is intended, then you might just stop using CodeIgniter at all.

Henceforth, $this->db->count_all_results() is your best option if you intend to properly use CodeIgniter.
Reply
#4

(10-17-2017, 09:56 AM)glorsh66 Wrote: So what is faster? $this->db->count_all_results()
or manually write a query and get count result?

Manual is faster.

(10-24-2017, 08:49 AM)oscarenzo Wrote: I think that the ideal is use the cli for mysql in CI, I don't sure what is more fast method, in my case ever try to use the CI cli mode, I mean  to this method in modal side:

$this->db->count_all_results();

Anyway you can use maybe this in your views printing the load time showing the load time:

{elapsed_time}

And test in different pages each one with one method :-), or think thats better use the class Benchmarking:

https://www.codeigniter.com/userguide3/l...hmark.html

You're saying stuff, but it doesn't really mean stuff.

(10-24-2017, 09:15 AM)fbarrera Wrote: I'd recommend you to use the built-in method in CodeIgniter for this purpose, this is, $this->db->count_all_results().

There are two reasons:

- CodeIgniter code is optimized to ensure not only speed, but also security in each operation.

- If you don't use CodeIgniter as it is intended, then you might just stop using CodeIgniter at all.

Henceforth, $this->db->count_all_results() is your best option if you intend to properly use CodeIgniter.

Nonsense. Your "two reasons" listed are sound, but don't relate to the question at all ...

1. count_all_results() has nothing to do with security.
2. The DB classes are designed for portability, and that very often comes at the expense of sacrificing performance. count_all_results() in particular can be very, very, very slow.
3. Using CI components as they are intended means don't use them for the wrong purpose; it does NOT mean you have to use everything the framework has.
Reply
#5

(10-24-2017, 12:48 PM)Narf Wrote: 2. The DB classes are designed for portability....

I'm wondering how often the need for this portability happens. I've only had one instance where portability might have been useful, but the app was a complete rewrite anyway. In a lot of apps I've worked on, I've had to write such complex queries that I couldn't use the query builder, and so the portability is broken. Is it common for people to one day simply decide that they're going to switch their database and the portability is actually a benefit?
Reply
#6

(10-25-2017, 08:12 AM)skunkbad Wrote:
(10-24-2017, 12:48 PM)Narf Wrote: 2. The DB classes are designed for portability....

I'm wondering how often the need for this portability happens. I've only had one instance where portability might have been useful, but the app was a complete rewrite anyway. In a lot of apps I've worked on, I've had to write such complex queries that I couldn't use the query builder, and so the portability is broken. Is it common for people to one day simply decide that they're going to switch their database and the portability is actually a benefit?

Well, it requires discipline to maintain your codebase in a portable state, and to be honest it's not worth it just for a potential switch. The actual benefits come if you're developing an app that you would distribute for others to install (like a CMS, for example), and they then have the choice of which database platform to use.
Reply
#7

(10-25-2017, 08:36 AM)Narf Wrote: Well, it requires discipline to maintain your codebase in a portable state, and to be honest it's not worth it just for a potential switch. The actual benefits come if you're developing an app that you would distribute for others to install (like a CMS, for example), and they then have the choice of which database platform to use.

That's something interesting to think about, being that I never seem to have a need for portability.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB