Welcome Guest, Not a member yet? Register   Sign In
Quick Table Stats?
#1

[eluser]zimco[/eluser]
I was trying to create a quick stats view page that displayed some stats about the number of entries in a couple of tables in my database, but since one table has 38,000 rows and the other table has 743,000 rows it took 65.1814 seconds to do the row count and then render the quick stats page; making it not so quick. I used the Result Helper Function $query->num_rows() mentioned on the User Guide>Database Library>Query Results page in my model to generate the row count for each table.

Am i using this function in a way it was not intended to be used and that why it's so slow? Would i be better off just using a manual query using SELECT Count(*) FROM mytable? Or is it always just going to be this slow due to the size of the tables and i should not be trying to display it in the first place?

Otherwise, does anybody have any suggestions on how i could get the information faster?
#2

[eluser]Pascal Kriete[/eluser]
What was the query you ran before counting the results? If you're grabbing everything from the table and then counting it, it will definitely be slow.
I think what you're looking for a the count_all and count_all_results functions, which are documented on the active record page.
#3

[eluser]zimco[/eluser]
You're right! I did a SELECT * FROM mytable then the query->num_rows()
Quote:If you’re grabbing everything from the table and then counting it, it will definitely be slow.

Thanks for the heads-up on the active record class>>count_all function. That was exactly what i was looking for! The user guide is amazing, maybe someday i'll remember to keep reading the whole section i'm in, before jumping right back into coding.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB