[drupal-devel] [task] db_num_rows(db_query()) inefficiency

moshe weitzman drupal-devel at drupal.org
Wed Aug 10 18:28:34 UTC 2005

Issue status update for 
Post a follow up: 

 Project:      Drupal
 Version:      4.6.0
 Component:    search.module
 Category:     tasks
 Priority:     minor
 Assigned to:  Anonymous
 Reported by:  Thomas Ilsche
 Updated by:   moshe weitzman
 Status:       patch (code needs review)

those 2 queries are not equivalent. look at the DISTINCT operator.
Furthermore, the COUNT(*) optimization does not apply to multiple table
queries (I think).

db_num_rows() is indeed useful.

moshe weitzman

Previous comments:

Wed, 10 Aug 2005 18:16:30 +0000 : Thomas Ilsche

Attachment: http://drupal.org/files/issues/search.module.patch.txt (848 bytes)

search.module uses

$count = db_num_rows(db_query("SELECT DISTINCT i.sid, i.type FROM
{search_index} i $join WHERE $conditions", $arguments));

I think using COUNT(i.sid) should provide an increase in effiecency.

Waiting for comments.

BTW there are 5 more occurances of "db_num_rows(db_query(" is there any
reason for that?

More information about the drupal-devel mailing list