I was using the Domain Access module with only one domain and on the front page the pager showed twice as many pages for anonymous users as it should be.
I was really curious why only the anonymous users got the wrong pager, so I traced back until I found out that the $count_query was different:
For anonymous:
SELECT COUNT(*) FROM {node} n INNER JOIN {node_access} na ON na.nid = n.nid WHERE (na.grant_view >= 1 AND ((na.gid = 0 AND na.realm = 'all') OR (na.gid = 0 AND na.realm = 'domain_site') OR (na.gid = 0 AND na.realm = 'domain_id'))) AND ( n.promote = 1 AND n.status = 1 )
And for the admin:
SELECT COUNT(*) FROM {node} n WHERE n.promote = 1 AND n.status = 1
That's because of the if in line 64 in pager.inc.
The upper query returns every node twice. If it would use COUNT(DISTINCT(n.nid)) instead of COUNT(*), this would solve the problem.
Unfortunately that's as far as I got, I didn't have the time to figure out where the $pager_query gets changed for the anonymous user, but if you have any further questions please ask.
Comments
Comment #1
Coornail commentedHah, I thought I'm going to sleep, but this is such a fascinating puzzle, I have to figure it out now:
The solution lies somewhere in the domain.module:2360, where it rewrites the node access rules.It's something else that rewrites the query from node.module:1748.
One interesting thing is that
SELECT * FROM node n INNER JOIN node_access na ON na.nid = n.nidreturns duplicate nodes, because in thenode_accesstable each node is in twice, once with domain_id and once with domain_site realm:Comment #2
agentrickardThis is a core bug in db_rewrite_sql() / pager_query(). There is nothing I can do.
#284392: db_rewrite_sql causing issues with DISTINCT
Comment #3
agentrickardIf anyone comes over here from #284392: db_rewrite_sql causing issues with DISTINCT, the historic problem with COUNT queries is that db_rewrite_sql() altered queries are not passed to the pager_query() function. That needs to get solved in core, in a separate issue.