Improve performance of COUNT Mysql

Asked

Viewed 212 times

0

I have a web application that performs several queries, but a Count query is taking 2 seconds to search and return the data to the application. My table where I perform COUNT has about 230 thousand lines with about 20 columns, how can I optimize this query?


SELECT COUNT(*) FROM myTable WHERE status = 1 AND category = 0;

What is the best way to count data in a table with variation in the query?

Anyone who can help me thank you!

  • 2

    Create indexes for status columns and Category

  • 1

    $result = mysql_query( "select Count(id) as num_rows from myTable WHERE status = 1 AND Category = 0" );

  • $Row = mysql_fetch_object( $result );

  • $total = $Row->num_rows;

  • source https://stackoverflow.com/questions/116824/whats-the-best-way-to-get-total-of-records-in-a-mysql-table-with-php

  • That one count(id) considers possible ids null?

  • You probably do not have indexes in this column, 230mil records is not a considerable volume of data for a query to be taking.

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.