Hi,
The CCK Views Integration have a limit on the number of fileds on views.
If I add many cck fields from the same content type (same table), the integration system make a join with the content table for each field ... Why??
I think is better make only 1 join with the content table.
example query:
SELECT node.nid, node.created AS node_created, node.title AS node_title, node.changed AS node_changed, node_data_field_donaz_imp.field_donaz_imp_value AS node_data_field_donaz_imp_field_donaz_imp_value, node_data_field_donaz_freq.field_donaz_freq_value AS node_data_field_donaz_freq_field_donaz_freq_value, node_data_field_donaz_link.field_donaz_link_url AS node_data_field_donaz_link_field_donaz_link_url, node_data_field_donaz_link.field_donaz_link_title AS node_data_field_donaz_link_field_donaz_link_title, node_data_field_donaz_link.field_donaz_link_attributes AS node_data_field_donaz_link_field_donaz_link_attributes, users.name AS users_name, users.uid AS users_uid, node_data_field_donaz_stato.field_donaz_stato_value AS node_data_field_donaz_stato_field_donaz_stato_value FROM node node LEFT JOIN node_donazione node_data_field_donaz_imp ON node.vid = node_data_field_donaz_imp.vid LEFT JOIN node_donazione node_data_field_donaz_freq ON node.vid = node_data_field_donaz_freq.vid LEFT JOIN node_donazione node_data_field_donaz_link ON node.vid = node_data_field_donaz_link.vid LEFT JOIN users users ON node.uid = users.uid WHERE (node.type IN ('donazione')) ORDER BY node.created DESC LIMIT 0, 10
Thanks.
Giuseppe Rizzo
Comments
Comment #1
karens commentedThat's the way it's supposed to work and it can't be done any differently. The CCK fields you add to views are not always in the same table, in fact they often aren't, and the tables can change if the field is changed from a single to a multiple or shared value field.
Comment #2
moshe weitzman commentedIt is true that this is by design, but that doesn't mean the design is good. This is a major shortcoming, andI don't see Views changing to solve this for us. When we move field modules into core, we might want to revisit this and see if we can do this is a Views friendly manner. Personally, I would prefer to have faster Views than shared fields across content types. Not sure if it makes sense to compare those two ...
Yes, I know the Views thing can be worked around in the theme, but still.
ok, down from my soapbox ...
Comment #3
karens commentedI was tired when I posted my response to this so sorry if my answer seemed dismissive. This is something that would not be impossible, but certainly quite difficult to do. We can leave it out as a feature request. I'm not sure I would consider it a critical bug report though. It's only an issue if you want to create a views table with a very large number of individual CCK fields. A normal table with 4 or 5 fields in it works fine. I do that all the time.
There is a workaround. If you want to do anything with Views and a large number of CCK fields, the fastest method is to leave the fields out of the view (except any that are needed for filtering or sorting), then in your theme do a node_load() on each record returned and put the table together there. I know that is certainly not an ideal answer, but it works for now.
Comment #4
eaton commentedAlso, note that if you use a given field in *just* a single content type, and do *not* choose 'multiple values', CCK can consolidate the data into a single table, the same way you would use a single table to store information when designing your own module.
This is subtle, but important. In the query above, it's not actually doing a join for EACH field, only for those that have been split out into separate tables (by being stuck into multiple node types or being flagged as 'multiple values'). If you were writing your own module from scratch and storing data in that way you'd have to do the joins, too: it's not a problem with CCK per se.
It might make sense to give CCK a way to 're-unify' or denormalize its structures if one realizes that one doesn't need multiple values or fields-shared-across-types anymore, but that could be a bit complicated.
Comment #5
karens commentedThis was solved by a recent patch to Views by bjaspan that optimizes the Views queries, so marking it fixed.
Comment #6
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #7
roychri commentedThe patch mentioned by KarenS is #256381: Remove redundant joins from Views queries