If you're working with Drupal 6.14, you'll want to be aware of <a href="http://drupal.org/node/284392">http://drupal.org/node/284392</a> (<span class="Apple-style-span" style="font-family: 'Bitstream Vera Sans', Verdana, Helvetica; font-size: 13px; border-collapse: collapse; color: rgb(0, 49, 80); line-height: 17px; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px; "><a href="http://drupal.org/node/284392" title="db_rewrite_sql causing issues with DISTINCT" alt="db_rewrite_sql causing issues with DISTINCT" style="color: rgb(0, 98, 160); font-weight: bold; text-decoration: none; ">db_rewrite_sql causing issues with DISTINCT</a>)</span>, a significant regression.<br>
<br><div class="gmail_quote">On Tue, Nov 24, 2009 at 4:03 AM, Lluís <span dir="ltr"><<a href="mailto:enboig@gmail.com">enboig@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I am using group by module, and db_rewrite_sql is giving me problems<br>
because it cause rows to be selected twice and SUM reports double<br>
their value.<br>
<br>
After doing some research I have found that if I change:<br>
function node_db_rewrite_sql($query, $primary_table, $primary_field) {<br>
if ($primary_field == 'nid' && !node_access_view_all_nodes()) {<br>
$return['join'] = _node_access_join_sql($primary_table);<br>
$return['where'] = _node_access_where_sql();<br>
$return['distinct'] = 1;<br>
return $return;<br>
}<br>
}<br>
<br>
to:<br>
function node_db_rewrite_sql($query, $primary_table, $primary_field) {<br>
if ($primary_field == 'nid' && !node_access_view_all_nodes()) {<br>
if (($where=_node_access_where_sql('view','new_na'))!='') {<br>
$return['where'] = "".$primary_table.".".$primary_field." IN<br>
(SELECT new_na.nid FROM {node_access} new_na WHERE ".$where.")";<br>
return $return;<br>
}<br>
}<br>
}<br>
<br>
everything works as expected.<br>
<br>
Is there any reason why using "INNER JOIN" is better than using "<br>
WHERE nid IN (SELECT ... FROM {node_access} ... )"?<br>
<font color="#888888"><br>
--<br>
*Les normes hi són perquè hi pensis abans de saltar-te-les<br>
*La vida és com una taronja, què esperes a exprimir-la?<br>
*Si creus que l'educació és cara, prova la ignorància.<br>
*La vida és com una moneda, la pots gastar en el que vulguis però<br>
només una vegada.<br>
*Abans d'imprimir aquest missatge, pensa en el medi ambient.<br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Randy Fay<br>Drupal Development, troubleshooting, and debugging<br><a href="mailto:randy@randyfay.com">randy@randyfay.com</a><br>+1 970.462.7450<br><br>