I was updating the sql-server patch when I came across this query:

SELECT COUNT(cid) FROM comments WHERE pid = 0 AND nid = 2 AND subject = 'This is a comment i''m' AND comment = 'This is a comment i''m adding.' 

This throws an error in sql-server for reasons I won't go into here (and it has to do with the way sql-server/oracle/sybase work and not anything wrong with drupal).

Now, the comment field is not indexed, nor is the subject; On a large system as it scales out, and if there is a lot of user activity creating comments, I think this may turn into a performance issue.

I'm proposing that an md5 hash be created up-front, and that it be used to check for duplicates instead of trying to match the actual strings. perhaps something like md5("$subject.$comment"). The md5 could thus be indexed, and make for a much improved system. Yes, I know we're doing more work on the front end (creating the md5), however, front-end like this work leads to a better, smoother running system later down the road.

I haven't posted a patch, i'm opening for discussion first, and then rolling a patch if need be.

Comments

steven jones’s picture

Status: Active » Closed (cannot reproduce)

I can't see this query in Drupal core, so I'm closing the issue, was the query being generated by something else? If so feel free to re-open against that project.