Make WordPress Core

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#32770 closed enhancement (invalid)

sql with unnecessary * in comment.php

Reported by: mesaquesoares's profile 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)

#1 follow-up: @miqrogroove
9 years ago

COUNT(*) is faster. Why would we remove it?

-1

#2 in reply to: ↑ 1 @mesaquesoares
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 @boonebgorges
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.

#4 @SergeyBiryukov
9 years ago

  • Component changed from General to Comments
Note: See TracTickets for help on using tickets.