views integration, left join instead of inner join
guardian - April 26, 2008 - 21:40
| Project: | Radioactivity |
| Version: | 5.x-1.1 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
my suggestion is to change the type of join for the module from inner to left otherwise, nodes which don't have associated radioactivity information (yet) will never appear in the view
please note that the patch also contains the fix for http://drupal.org/node/251651
| Attachment | Size |
|---|---|
| radioactivity.patch | 1 KB |

#1
Is this required by a real use case? I ask this because inner joins should be faster than left outer joins.
In medium/large sites you can expect 10:1, 100:1 or even greater ratio of nodes per rows in radioactivity (per decay profile) which justifies the inner join. This is the case in a site where this module was originally written for. If you really need left join, I see two possibilities:
We could also make this configurable in the radioactivity admin menu, but I wouldn't want to make this kind of setting global.
#2
my use case is the following: i have a view that sorts the nodes by radioactivity then by stickiness then by created time
for my home page, i extract the top node of the view and render it highlighted in a separate div so it makes sense to always have a node returned by the view
this enables me to give more importance to the latest sticky node of the site in case of low activity, but as well keep track of the currently most viewed node in case your site has been digged
if you think that performance might be a problem for medium / large sites, i would prefer having an option on the criterium like "All" and "Only Radioactive". having this option means we find a way to change the type of the join dynamically when the view is built. in case we can't do that, having 2 criteria per profile is an acceptable fallback
thx for the follow up ! i'm eager to see this polished :)
#3
Ok, I looked briefly into this, and attached is a patch that provides 'all' and 'radioactive only' versions of field/sort/filter criteria. However, I'm not fully comfortable with this for two reasons:
I'd like to have at least the second item sorted out before inclusion. So, until someone's up to the task...
#4
please review this one, in the end it seems to work like intended
disclaimer: i have nearly no experience in databases in general but i googled some information about the problem you mentioned regarding PostgreSQL, also this is the first time i'm coding a sort criterion for views
#5
#6
works as intended on mysql, since i don't have postgresql
#7
Ok, I used the patch in comment 4 as a basis and came up with the attached patch. There's some notable changes (in addition to white space changes):
Please, test this patch against the current CVS HEAD ( http://cvs.drupal.org/viewvc.py/drupal/contributions/modules/radioactivi... )
Note that existing views with radioactive energy will get broken after applying this patch.
#8
works for me
you mentioned "field click sorting uses COALESCE for PostgreSQL compatibility" - i'm not experienced in PostgreSQL at all but the reason why my previous patch uses
<?php$query->orderby[] = "$table.$field IS NOT NULL $order, $table.$field $order";
?>
maybe your implementation of
<?phpfunction radioactivity_field_sort_handler_energy($fielddata, $fieldinfo) {
return 'COALESCE('.$fielddata['tablename'].'.energy, 0)';
}
?>
IS NOT NULLinstead ofCOALESCEdepending on the performance ? you decide, as i said i don't know PostgreSQL and can't benchmark it right nowapart from the point mentioned above, ready to be committed ?
#9
Ok, the radioactivity-module-251656-7.patch was almost ready for commit. Two small adjustments:
COALESCEfrom the mysql case. With PostgreSQL we just need to rely on its optimizer for now. AFAICT, we would need to write a real handler to be able to use theIS NOT NULLtrick. Anyway, field click sorting and PostgreSQL combination is not probably that important, even if there was a performance penalty.energy_ftoenergyin 'fields' section. Allows non-hardcoded sort handler.With these two, here's the commit: http://drupal.org/cvs?commit=114748
Thanks!
#10
#11
Automatically closed -- issue fixed for two weeks with no activity.