NOR filters use a double left join, which gives incorrect results.
Example with DB:
# @n: node.nid
# nn: term_node.nid
# nt: term_node.tid
# dt: term_data.tid
# dv: term_data.vid
nn nt dt dv
1 1 1 1
1 2 2 2
2 2 2 2
When wanting « Vocabulary in None of 1 », we get a query saying:
# @: node
# n: term_node
# d: term_data
@ LJ n ON @n =nn LJ d ON nt = dt AND dv IN (1) WHERE (nt IS NULL AND dt IS NULL)
There we get excessive filtering:
Joins being from left to right, internally to the database the join before the WHERE clause looks like that:
@n nn nt dt dv
1 1 1 1 1
1 1 2 - -
2 2 2 - -
Thus none has both NULL conditions fulfilled, the query returns no result (whereas it should have returned entry 2, which has no connexion to vocabulary 1).
(and removing the constraint of having both fields to NULL would give false positives)
Problem is, the n - d join should be handled as one entity.
Instead of:
@ LJ n ON @n =nn LJ d ON nt = dt AND dv IN (1) WHERE (nt IS NULL AND dt IS NULL)
We want:
@ LJ (n LJ d ON nt = dt AND dv IN (1)) ON @n =nn WHERE (nt IS NULL AND dt IS NULL)
Guess what? This is just what the attached patch allows.
It contains two parts:
- in views_query.inc: add_table_group and end_table_group, to bracket some add_tables.
- In views_taxonomy.inc: use of this structure for NOR filters.
Internally, groups are stored in tablequeue, with their own sub-tablequeue. SQL rendering is done by recursively calling query() (I added a defaulted parameter to it so that it knows if it should return a whole query or just a parenthesed fragment). joininfo is preserved as table ''.
Question is, or are:
- doing this, do I stay in Drupal spirit (I'm a 2-weeks-long beginner)?
- Can this be considered standard SQL (PostGreSQL anyone)?
- is there somewhere a comprehensive and automated set of tests to see if this doesn't induce regressions (on results, or performance)?
| Comment | File | Size | Author |
|---|---|---|---|
| hierarchical_tablequeue.patch | 4.75 KB | guillaume.outters |
Comments
Comment #1
guillaume.outters commented(submitted with bad status)
Comment #2
esmerel commentedAt this time, only security fixes will be made to the 5.x version of Views.