#32770 closed enhancement (invalid)
sql with unnecessary * in comment.php
Reported by: | mesaquesoares | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2.2 |
Component: | Comments | Keywords: | |
Focuses: | performance | Cc: |
Description
line: 1681
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
change the COUNT( * ) for COUNT( comment_ID )
will be now:
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( comment_ID ) AS num_comments FROM {$wpdb->comments} {$where} GROUP BY comment_approved", ARRAY_A );
Change History (4)
#2
in reply to:
↑ 1
@
9 years ago
Replying to miqrogroove:
COUNT(*)
is faster. Why would we remove it?
-1
asterisks have a great cost to sql because he demands a new discover of all columns in the table and this make indexing very poorly.
#3
@
9 years ago
- Milestone Awaiting Review deleted
- Resolution set to invalid
- Status changed from new to closed
Hi mesaquesoares - COUNT(*)
should be at least as fast as COUNT(comment_ID)
, and possibly faster, as miqrogroove points out. See eg http://stackoverflow.com/a/4216154 and http://stackoverflow.com/questions/1697137/countid-vs-count-in-mysql. If you have an EXPLAIN
that shows otherwise, please feel free to post it.
COUNT(*)
is faster. Why would we remove it?-1