SQL query with COUNT(DISTINCT

abautu - February 17, 2007 - 19:15
Project:Drupal
Version:5.1
Component:statistics.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 287: SELECT COUNT(DISTINCT(path)) FROM {accesslog} could be replaced with SELECT COUNT(*) FROM {accesslog} GROUP BY path
line 321: SELECT COUNT(DISTINCT(CONCAT(uid, hostname))) FROM {accesslog} could be replaced with SELECT COUNT(*) FROM {accesslog} GROUP BY uid, hostname

You may notice that the queries I'm suggesting are shorter, cleaner (you may cleary see that you are counting all the lines) and faster (notice there is no CONCAT call in the later example).

Best wishes,
Andrei.

#1

abautu - February 17, 2007 - 22:06
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
statistics_13.patch2.02 KB

#2

Crell - February 17, 2007 - 23:10
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) 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.