什么是“mysqli_query(来自create_at> $ time的表中的SELECT count(*)”的较便宜的替代品

I have a script that I need to run in under 1 second. I have this line that takes 4.4 seconds on average to execute.

    $result = mysqli_query($conn, "SELECT count(*) from record where created_at > '$time'");

The rest of the script takes less than 0.1 second.

I aggree with @xQbert and wonder if COUNT(1) or COUNT(ID) could increase speed... but nevermind...

Edit - just had the answer Count(*) vs Count(1)

You should add an index involving created_at row. Try to add a UNIQUE INDEX on created_at if possible or on created_at and another row (i.e. created_at + user_id). The more restrictive you will be, the faster you will get your results.

Another point is, if you only need 5 results... limit your query with LIMIT 0,5

Believe me... PHP won't be faster than MySQL! ;)