SQL query with COUNT(DISTINCT

abautu - February 17, 2007 - 19:30
Project:Drupal
Version:5.1
Component:tracker.module
Category:feature request
Priority:normal
Assigned:abautu
Status:duplicate
Description

Hello,

I'm working on a SQLite layer for Drupal as a hobby. It's very functional, but I have the following problem: your module uses some queries with COUNT(DISTINCT(...)). I'm not sure is this syntax is SQL standard, but it can by rewritten using a GROUP BY clause (in a 100% standard way). For instance:
line 83: 'SELECT COUNT(DISTINCT(n.nid)) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d)'; could be replaced with 'SELECT COUNT(*) FROM {node} n LEFT JOIN {comments} c ON n.nid = c.nid AND (c.status = %d OR c.status IS NULL) WHERE n.status = 1 AND (n.uid = %d OR c.uid = %d)'; . ' GROUP BY n.nid';

You may notice that the queries I'm suggesting are shorter, cleaner (you may cleary see that you are counting all the lines) and maybe faster (because of possible GROUP BY optimizations).

Best wishes,
Andrei.

#1

abautu - February 17, 2007 - 22:10
Assigned to:Anonymous» abautu
Status:active» patch (reviewed & tested by the community)

I learned how to use a CVS, how Drupal CVS works, how patches are made and I thought to give it a try. I've tested the patch on my installation.

AttachmentSize
tracker_4.patch1.38 KB

#2

Crell - February 17, 2007 - 23:11
Status:patch (reviewed & tested by the community)» duplicate

1) Do not post duplicate issues to different issue queues.
2) Do not set your own patch to "ready to be committed".
3) New features go against 6.x, not against the stable version.
4) Do check the issue queue before posting, as there is already an effort for SQLite support: http://drupal.org/node/67349

Thank you.

 
 

Drupal is a registered trademark of Dries Buytaert.