I got serious issue with one view, who used flags(link to flag and counters). When I watch query of this view I can see that there is one LEFT JOIN without any purpose(at least in my mind): LEFT JOIN {flag_content} flag_content_node ON node.nid = flag_content_node.content_id AND flag_content_node.fid = '1'

I found that this join is created in file flag_handler_relationships.inc. Class "flag_handler_relationship_content" and function query().

I am using flags module to one project for voting. This view have 2 relationships defined: "Flags: vote (by any user)" and "Flags: vote counter". I havn't hacked any of flag module files. When flag_content table got 10k entries, this view become really slow because of this LEFT JOIN. Second LEFT JOIN to this table is correct.

Can anyone please comment this situation? Thanks in advance!

Comments

joachim’s picture

Check the various Views handlers for Flag -- there is some weird JOIN stuff because for a flag link we have to get the value specifically for the entity or something like that, which IIRC may indeed result in a double join.

maris.abols’s picture

But without this join everything is working just fine(I altered view's query manually). Maybe this join could be removed from source?

podarok’s picture

#2 thanks for help
good to see Your code in patch format here

joachim’s picture

Can you post the piece of the code that's doing this?

joachim’s picture

I suspect what you're talking about is this:

    // Find out if the content is flagged. We can't just peek at some field in
    // our loaded table because it doesn't always reflect the user browsing the
    // page. So we explicitly add the flagging table to find this out.
    // If the relationship is created with 'Current User' checked, we probably
    // already have the appropriate join. We just need the appropriate table
    // alias for that join. We look in the relationship settings to see if
    // user_scope is set to 'current' to determine this.

but if you could give more detail, such as exporting your view, or tell me where you removed the query join, that would help.

ivnish’s picture

Issue summary: View changes
Status: Active » Closed (outdated)

Closed as outdated because Drupal 7 is EOL