Hi, I have generated a lot of comments (over 10000 on a single node) with the devel module to have a testing environment. When doing this, I ran over something that seems to be an incompatible SQL query in comment.module.
I am using Drupal 6.1 with PHP 5.2.5 on an Apache 2 Webserver and a PostgreSQL 8.3 DB.
The error message is:
* warning: pg_query() [function.pg-query]: Query failed: FEHLER: mehrere ORDER-BY-Klauseln sind nicht erlaubt in includes/database.pgsql.inc on line 138.
* user warning: query: (SELECT thread FROM drupal_comments WHERE nid = 49 AND status = 0 ORDER BY timestamp DESC LIMIT 500) ORDER BY thread DESC LIMIT 1 in modules/comment/comment.module on line 365.
I don't understand why the query is using parentheses and different LIMIT values - my proposal would be to use something like "SELECT thread FROM {comments} WHERE nid = %d AND status = 0 ORDER BY timestamp DESC, thread DESC LIMIT 1".
I'd be glad to provide more information if needed.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | comment_sql_cleanup.patch | 1.91 KB | penguinchix0r |
Comments
Comment #1
penguinchix0r commentedI was able to reproduce this, and the following patch seems to fix the problem. I'm not entirely sure what the author was intending with the query, however, so I'll take a closer look and make sure the new SQL is doing the right thing.
Comment #2
penguinchix0r commentedComment #3
sirprize commentedSeems to work okay :-)
Will test it some more in the next days.
Comment #4
sirprize commentedUpdating status: I encountered no problems whatsoever, patch looks good too.
Comment #5
pwolanin commentedbug fixes should go to 7.x first
Does this patch still apply?
Comment #6
dries commentedDo we have tests that validate the order of the comments based on these settings?
Comment #7
catchNope. We also don't have a newest first comment order in core any more as of yesterday, so this needs a re-roll.
Comment #8
pwolanin commentedSounds like the existing patch could still be the 6.x backport?
Comment #9
damien tournoud commentedThis is a duplicate of #396388: Fix syntax of comment ordering subquery, even if this one was technically opened first.
Note that the patch is wrong. That query is deliberately complex, and deliberately has an (implicit) sub-query on the FROM clause. Notice that
SELECT FROM (SELECT FROM table ORDER BY x LIMIT xxx) ORDER BY y LIMIT 1is not the same asSELECT FROM table ORDER BY x, y LIMIT 1.