Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17

This is experimental functionality, and as such subject to change. Use at your own risk!

Normalise associative operations

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

Associative operations are operations whose chaining can be done as (a op b) op c or a op (b op c) without changing the result. Examples of such operations are:

  • +
  • *
  • AND
  • OR

In order to simplify all of these pattern replacements, we normalise associative ops to always flatten tree structures into lists.

Using Settings.transformPatternsNormaliseAssociativeOps, the following transformations can be achieved:

-- With Settings.transformPatternsNormaliseAssociativeOps active, this:
SELECT
  (a + b) + (c + d),
  (a * b) * (c * d),
  (a AND b) AND (c AND d),
  (a OR b) OR (c OR d)
FROM tab;

-- ... is transformed into the equivalent expression:
SELECT
  ((a + b) + c) + d,       -- (a + b) + (c + d)
  ((a + b) + c) + d,       -- (a * b) * (c * d)
  ((a AND b) AND c) AND d, -- (a AND b) AND (c AND d)
  ((a OR b) OR c) OR d     -- (a OR b) OR (c OR d)
FROM tab;

Note that the unnecesary parentheses may not be generated in either case, but the in-memory data structure still looks as though the parentheses were there.

References to this page

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo