可用版本:Dev (3.21) | 最新 (3.20) | 3.19 | 3.18 | 3.17

算术表达式

适用于 ✅ 开源版   ✅ 专业版   ✅ 企业版

一些算术表达式是不必要的,可能会使 SQL 查询变得模糊,从而可能阻止原本可能的优化。有时,这被用作一种技巧,例如,为了防止不希望的索引访问

使用 Settings.transformPatternsArithmeticExpressions,可以实现以下转换

标识列

-- With Settings.transformPatternsArithmeticExpressions active, this:
SELECT 0 + x, 1 * x, POWER(x, 1)
FROM tab;

-- ... is transformed into the equivalent expression:
SELECT x, x, x FROM tab;
-- With Settings.transformPatternsArithmeticExpressions active, this:
SELECT
  0 - x,
  x + (-y),
  x - (-y),
  (-x) * (-y),
  (-x) / (-y),
  (-1) * x,
  -(x - y)
FROM tab;

-- ... is transformed into the equivalent expression:
SELECT
  -x,     -- 0 - x
  x - y,  -- x + (-y)
  x + y,  -- x - (-y)
  x * y,  -- (-x) * (-y)
  x / y,  -- (-x) / (-y)
  -x      -- (-1) * x
  (y - x) -- -(x - y)
FROM tab;
-- With Settings.transformPatternsArithmeticExpressions active, this:
SELECT
  1 / y * x,
  x * x,
  x + const,
  x * const
FROM tab;

-- ... is transformed into the equivalent expression:
SELECT
  x / y,     -- 1 / y * x
  SQUARE(x), -- x * x
  const + x, -- x + const
  const * x  -- x * const
FROM tab;

反馈

您对此页面有任何反馈吗? 我们很乐意听取您的意见!

The jOOQ Logo