The new postgres db_distinct_field function in Drupal 5.9 doesn't eliminate duplicates properly in some circumstances.

I'm seeing this problem when I use a view of a custom data type which is viewable by multiple roles, and the user is a member of more than one of those roles.

The interesting part of the query looked like this on Drupal 5.7 (and probably 5.8, I didn't look):

SELECT distinct(node.nid), node.title FROM node node INNER JOIN node_access na ON na.nid = node.nid ;

But like this on Drupal 5.9:

SELECT node.nid, node.title FROM (SELECT DISTINCT ON (nid) * FROM node) node INNER JOIN node_access na ON na.nid = node.nid ;

The problem is the INNER JOIN is happening after the DISTINCT, so they don't end up distinct at all. For example, when I run this query:

SELECT node.nid, node.title, na.gid, na.realm FROM (SELECT DISTINCT ON (nid) * FROM node) node INNER JOIN node_access na ON na.nid = node.nid WHERE node.nid = 104;

I get these results:

 nid |  title   | gid |          realm
----+----------+-----+--------------------------
 104 | New Deal |   1 | node_privacy_byrole_role
 104 | New Deal |   1 | node_privacy_byrole_user
 104 | New Deal |   2 | node_privacy_byrole_role
(3 rows)

Reverting to the database.pgsql.inc from 5.7 fixed the problem. That version still has the problem described in http://drupal.org/node/128846; I'm using a different fix for that problem I'd be happy to share if it's useful.

Comments

dpearcefl’s picture

Status: Active » Closed (won't fix)

Considering the time elapsed between now and the last comment plus the fact that D5 is no longer supported, I am closing this ticket.