Incorrect filter group OR behavior, LEFT JOIN changed to INNER JOIN

Created on 1 September 2012, almost 13 years ago
Updated 1 May 2024, about 1 year ago

Problem/Motivation

As title says - Incorrect filter group OR behavior, INNER JOIN instead of expected LEFT JOIN

From @SoulReceiver #139 comment

Steps to reproduce

  1. Install Drupal
  2. Create an article with the tag 'test'
  3. Create a view of articles and add 'Tags' as an exposed filter with 'Is one of', twice, using OR operator
  4. Set both filters to 'test'
  5. Confirm there are no results, when you should expect the test article to appear

I note that it works as expected if the exposed filters are set to 'Is all of'.
From @pameeela #121 comment

Proposed resolution

  1. Use INNER JOIN only if the join is not for filter group with OR operator
  2. Add tests to replicate the bug and check the fix.

Remaining tasks

---

User interface changes

---

API changes

---

Data model changes

---

Release notes snippet

---

Original summary D7

I have a view, in code, which uses two groups of ANDed filters, with group behaviour OR. Since updating to views 3.5 (from 3.3+173-dev), the filter OR no longer works correctly - I am getting only the nodes that match the second filter group, not nodes that match either group. There is nothing very special about the filters, which operate on node type, status, nid and taxonomy terms. Aggregation is enabled.

I am pulling values from view arguments and supplying those to the filters in hook_views_query_alter(), but if I disable that and use static filter values in the view the OR still fails as above, so I don't think that is the problem.

The relevant query in 3.3 used a LEFT JOIN, this has changed to INNER JOIN in 3.5. See the second join in each query below.

7.x-3.3+173-dev:

SELECT DISTINCT node.title AS node_title, node.nid AS nid, COUNT(field_data_field_related_article.field_related_article_tid) AS field_data_field_related_article_field_related_article_tid, COUNT(field_data_field_related_article.delta) AS field_data_field_related_article_delta, COUNT(field_data_field_related_article.language) AS field_data_field_related_article_language, COUNT(field_data_field_related_article.bundle) AS field_data_field_related_article_bundle
FROM 
{node} node
INNER JOIN {field_data_field_related_article} field_data_field_related_article ON node.nid = field_data_field_related_article.entity_id AND (field_data_field_related_article.entity_type = 'node' AND field_data_field_related_article.deleted = '0')
LEFT JOIN {field_data_field_related_delivery} field_data_field_related_delivery ON node.nid = field_data_field_related_delivery.entity_id AND (field_data_field_related_delivery.entity_type = 'node' AND field_data_field_related_delivery.deleted = '0')
INNER JOIN {node_access} na ON na.nid = node.nid
WHERE (( (node.status = '1') AND (node.type IN  ('article', 'programme')) AND (node.nid != '68') AND (field_data_field_related_article.field_related_article_tid IN  ('54')) )OR( (node.status = '1') AND (node.type IN  ('article', 'programme')) AND (node.nid != '68') AND (field_data_field_related_delivery.field_related_delivery_value IN  ('distance')) ))AND(( (na.gid = '0') AND (na.realm = 'all') )OR( (na.gid = '0') AND (na.realm = 'domain_site') )OR( (na.gid = '3') AND (na.realm = 'domain_id') ))AND (na.grant_view >= '1') 
GROUP BY node_title, nid
ORDER BY node_title ASC

7.x-3.5:

SELECT DISTINCT node.title AS node_title, node.nid AS nid, COUNT(field_data_field_related_article.field_related_article_tid) AS field_data_field_related_article_field_related_article_tid, COUNT(field_data_field_related_article.delta) AS field_data_field_related_article_delta, COUNT(field_data_field_related_article.language) AS field_data_field_related_article_language, COUNT(field_data_field_related_article.bundle) AS field_data_field_related_article_bundle
FROM 
{node} node
INNER JOIN {field_data_field_related_article} field_data_field_related_article ON node.nid = field_data_field_related_article.entity_id AND (field_data_field_related_article.entity_type = 'node' AND field_data_field_related_article.deleted = '0')
INNER JOIN {field_data_field_related_delivery} field_data_field_related_delivery ON node.nid = field_data_field_related_delivery.entity_id AND (field_data_field_related_delivery.entity_type = 'node' AND field_data_field_related_delivery.deleted = '0')
INNER JOIN {node_access} na ON na.nid = node.nid
WHERE (( (node.status = '1') AND (node.type IN  ('article', 'programme')) AND (node.nid != '68') AND (field_data_field_related_article.field_related_article_tid IN  ('54')) )OR( (node.status = '1') AND (node.type IN  ('article', 'programme')) AND (node.nid != '68') AND (field_data_field_related_delivery.field_related_delivery_value IN  ('distance')) ))AND(( (na.gid = '0') AND (na.realm = 'all') )OR( (na.gid = '0') AND (na.realm = 'domain_site') )OR( (na.gid = '3') AND (na.realm = 'domain_id') ))AND (na.grant_view >= '1') 
GROUP BY node_title, nid
ORDER BY node_title ASC
πŸ› Bug report
Status

Fixed

Version

10.2 ✨

Component
ViewsΒ  β†’

Last updated 2 days ago

Created by

πŸ‡³πŸ‡ΏNew Zealand john pitcairn

Live updates comments and jobs are added and updated live.
  • needs backport to 7.x-3.x

    The patch should be considered for backport to the 7.x-3.x branch. Note: This tag should generally remain even after the backport has been written, approved, and committed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024