Every node has an author.

CommentFileSizeAuthor
#1 views_user_0.patch632 byteschx
views_user.patch884 byteschx
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

chx’s picture

FileSize
632 bytes

Uh, uploaded an earlier attempt, sorry -- not every user has a role though :) Now really the trivial oneliner I wanted.

merlinofchaos’s picture

Status: Reviewed & tested by the community » Fixed

Patch applied. Thanks!

FiReaNGeL’s picture

Status: Fixed » Needs work

If theres an author for every node, I guess that means that there is no use case where the author will be NULL. Then what you want is really a LEFT JOIN; INNER JOIN will cause mysql to check each row for null (to see if it can remove it from the dataset) and can cause some problems with indexes, causing performance degradation.

sun’s picture

Assigned: chx » Unassigned

So, what now? FiReaNG3L's argument seems to make sense...

FiReaNGeL’s picture

I guess we should compare both EXPLAIN for INNER and LEFT joins on sizable databases

sun’s picture

mysql> EXPLAIN SELECT node.nid, users.name FROM node INNER JOIN users ON node.uid = users.uid;
+----+-------------+-------+--------+---------------+---------+---------+--------------+--------+-------------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref          | rows   | Extra       |
+----+-------------+-------+--------+---------------+---------+---------+--------------+--------+-------------+
|  1 | SIMPLE      | node  | ALL    | uid           | NULL    | NULL    | NULL         | 251298 |             |
|  1 | SIMPLE      | users | eq_ref | PRIMARY       | PRIMARY | 4       | node.uid     |      1 | Using where |
+----+-------------+-------+--------+---------------+---------+---------+--------------+--------+-------------+
2 rows in set (0.00 sec)

mysql> EXPLAIN SELECT node.nid, users.name FROM node LEFT JOIN users ON node.uid = users.uid;
+----+-------------+-------+--------+---------------+---------+---------+--------------+--------+-------+
| id | select_type | table | type   | possible_keys | key     | key_len | ref          | rows   | Extra |
+----+-------------+-------+--------+---------------+---------+---------+--------------+--------+-------+
|  1 | SIMPLE      | node  | ALL    | NULL          | NULL    | NULL    | NULL         | 251298 |       |
|  1 | SIMPLE      | users | eq_ref | PRIMARY       | PRIMARY | 4       | node.uid     |      1 |       |
+----+-------------+-------+--------+---------------+---------+---------+--------------+--------+-------+
2 rows in set (0.00 sec)
smk-ka’s picture

According to EXPLAIN's output, it seems like FiReaNG3L is right. I didn't realize (until now) that you can rewrite INNER JOIN as LEFT JOIN t WHERE t.col IS NOT NULL (well, I knew the difference for sure, but I was under the impression INNER JOIN would be some kind of optimized, which seems not to be the case).

FiReaNGeL’s picture

These EXPLAIN doesn't prove much as the query is a very simple one, and thus the EXPLAIN are very similar; maybe a 'real world' query with GROUP BY or ORDER BY and some WHERE, such as one generated by views.module, as the patch is for views, would be more appropriate. I still believe that the INNER is useless as there should be no case where a node has no author.

esmerel’s picture

Status: Needs work » Closed (won't fix)

No changes are happening with 1.x