How to Evaluate Multiple ANDs and ORs in JQL Without Parenthesis

How to Evaluate Multiple ANDs and ORs in JQL Without Parenthesis

Issue: When trying to understand or modify a complex JQL (Jira Query Language) query, especially when the query consists of multiple ANDs and ORs without the use of parentheses, it can be challenging to determine the logical order of evaluation. Such queries can become confusing as the absence of parentheses makes it ambiguous to decipher the relationship and precedence between various conditions.

Problem Description: A JQL query example that has caused confusion is:

Field1 = answer1 AND field2 = answer2 AND field3 = answer3 OR field4 = answer4 AND field5 = answer5 OR field6 = answer6 OR field7 = answer7 AND field8 = answer8

Questions arising from this:

  1. Does the first OR group the first three conditions together or is it only combining the evaluation of field3 and field4?
  2. Similarly, for the second OR, is it only evaluating field6 and field7, or does it include conditions both before and after it?

Usual Methods of Tackling the Issue:

  1. Split and Analyze: One approach to understand such a query is to split it into smaller chunks, analyze each segment, and then combine them.
  2. Nested JQL: Some suggest using nested JQL queries to evaluate results from various parts of the main query. However, as of a certain point, this feature was still in progress with Jira.
  3. Referencing Official Documentation: The official documentation suggests that in the absence of parentheses, JQL evaluates conditions from left to right. This means that adding parentheses to ensure correct evaluation might be the most effective way to clear up any confusion.

Proposed Solution for the Problem: Given the left-to-right evaluation rule in JQL, the mentioned query can be written with the following parentheses to ensure clarity:Copy code

( ( ( ((Field1 = answer1) AND (field2 = answer2) AND (field3 = answer3)) OR (field4 = answer4) ) AND (field5 = answer5) ) OR (field6 = answer6) OR (field7 = answer7) ) AND (field8 = answer8)

However, there’s an important consideration to make. When working with such complicated logic, especially when not originally authored by you, it’s essential to interpret the original intent of the query. It’s entirely possible that the original query might not have been yielding the intended results due to its complexity and absence of parentheses. In such cases, understanding the context and rebuilding the query from scratch might be the best approach.