Hi agentrickard!
I have to do a performance tuning on a large drupal 7 site using the doman module.
While investigating, I compared the sql queries with a normal drupal 7 installation. I found out, that every view is rewritten into a SELECT DISTINT query.
Without Domain Access
SELECT node.title AS node_title, node.nid AS nid, node.language AS node_language, node.created AS node_created, 'test:default' AS view_name
FROM
{node} node
INNER JOIN {node_access} na ON na.nid = node.nid
WHERE (( (node.status = '1') AND (node.type IN ('story')) ))AND(( (na.gid = '0') AND (na.realm = 'all') )OR( (na.gid = '0') AND (na.realm = 'domain_site') )OR( (na.gid = '2') AND (na.realm = 'domain_id') ))AND (na.grant_view >= '1')
ORDER BY node_created DESC
LIMIT 10 OFFSET 0
With Domain Access
SELECT DISTINCT node.title AS node_title, node.nid AS nid, node.language AS node_language, node.created AS node_created, 'test:default' AS view_name
FROM
{node} node
INNER JOIN {node_access} na ON na.nid = node.nid
WHERE (( (node.status = '1') AND (node.type IN ('story')) ))AND(( (na.gid = '0') AND (na.realm = 'all') )OR( (na.gid = '0') AND (na.realm = 'domain_site') )OR( (na.gid = '2') AND (na.realm = 'domain_id') ))AND (na.grant_view >= '1')
ORDER BY node_created DESC
LIMIT 10 OFFSET 0
As far as I can see, the $query->distinct() is always set in domain_content/domain.module:
.....
// Prevent duplicate records.
$query->distinct();
// Find all instances of the base table being joined -- could appear
// more than once in the query, and could be aliased. Join each one to
// the node_access table.
$grants = node_access_grants($op, $account);
if ($type == 'entity') {
....
As we all know, the SELECT DISTINCT is quite expensive, because every query have to be grouped to reduce duplicates. On my test system, I disabled the $query->distinct() line and had no impact in my environment (we did not see views with duplicates). I know this is not a solution, but to it seems, that the DISTINCT is not necessary in every use case.
I don't know well the architecture of domain access. Could you give me a litte help here? We feel a performance improvement disabling the "DISTINCT" in domain access. May I disable it and set the "DISTINCT" in views manually if necessary? Is there a solution for sites that would like to avoid the "DISTINCT" in every query because of performance reasons?
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 1889356-da-admin-rewrite.patch | 5.49 KB | agentrickard |
Comments
Comment #1
agentrickardThe query you are pointing at only affects user 1 and users who can bypass node access and then only if a setting is enabled. Disable the "Enforce access rules on administrators" setting of the module.
This used to be how core handled it, but since core moved to a subquery, the distinct() can be removed.
The domain_alter_node_query() function is essentially a clone of http://api.drupal.org/api/drupal/modules!node!node.module/function/_node...
Please submit a patch that brings the two functions back in line.
Comment #2
agentrickardComment #3
ayalon commentedHi agentrickard
Thanks for your response. I really appreciate your help. I see that you are one of these developers, that are gold worth for the drupal community.
You are right, I tested this issue with an admin user and I have the option "Restrict node views for administrators" activated because the we have multiple domains and don't want to see the content of every domain on all domains. I cannot disable this option.
I tried to find a solution myself, then I saw you wrote a patch. I studied the code and will test the patch on my system. But to be honest, I would never come to this solution and I understood the solution only partially.
Maybe you can bring a litte light in your solution.
Comment #4
ayalon commentedThe patch works as expected!
Comment #5
agentrickardThe solution is simple: we are copying a core function that does not apply to user 1 and making it apply to user 1. (See domain_admin_filter() for the logic.)
The core query was optimized within the last 4 months or so, and we haven't updated our code yet.
Comment #6
agentrickardCommitted.