Class ValueRange

java.lang.Object
dev.frostlake.values.ValueRange

public final class ValueRange extends Object
The closed interval of values an exact-numeric expression can take, as the account's planner reasons about it: a stored column's interval is its statistics (the least and greatest value in the whole table, whatever a WHERE keeps), a literal's is itself, and arithmetic widens it by interval rules. EMPTY is the interval of no value — a NULL, a column with no rows — which every operation keeps empty and a union ignores.

The interval decides the storage tag SYSTEM$TYPEOF prints after an exact NUMBER, which is why it is carried at all: live tags a NUMBER(38,0) column holding 1 and 999 as SB2 on EVERY row, the width of the widest value in the table, and never the width of the row's own value.

Beside its bounds an interval says whether the expression may also answer NULL, which the statistics know of a column and which decides where the planner may stop a COALESCE. A known value never does, arithmetic may only where an operand may, a union may where either side may, and EMPTY is nothing but the NULL.

And it says whether a CONDITION over the expression may be settled by it at all (see isOpaqueToConditions()). The planner reduces a COALESCE whose first argument cannot be NULL to that argument; one it cannot reduce keeps its interval for the storage tag and for LEAST, GREATEST and DECODE, but no comparison over it, or over anything computed from it, is settled: live leaves IFF(COALESCE(n, 0) > 5, 3000.5, 1.5) open over a column holding a NULL, and settles it over one holding none.

  • Field Details

    • EMPTY

      public static final ValueRange EMPTY
      No value at all: a NULL, or a column that holds nothing. Takes the narrowest tag.
    • WIDEST

      public static final ValueRange WIDEST
      Wider than any tag tells apart, for a plan that always accumulates in sixteen bytes.
  • Method Details

    • of

      public static ValueRange of(BigDecimal value)
      The interval of one known value, which is never NULL, or EMPTY for null.
    • between

      public static ValueRange between(BigDecimal a, BigDecimal b)
      The interval between two bounds, in either order, holding no NULL.
    • exactOf

      public static BigDecimal exactOf(Object value)
      A runtime value read exactly, or null for one that is not an exact number — a NULL, a string that does not spell a number, a non-finite double.
    • isEmpty

      public boolean isEmpty()
    • getMin

      public BigDecimal getMin()
    • getMax

      public BigDecimal getMax()
    • isNullable

      public boolean isNullable()
      Whether the expression may answer NULL beside its values; always true of EMPTY.
    • isOpaqueToConditions

      public boolean isOpaqueToConditions()
      Whether no condition over the expression is settled by this interval: the value came through a COALESCE (NVL, IFNULL) the planner could not reduce to its first argument, directly or through the arithmetic, casts and conditionals computed from it. The bounds and the nullability still stand.
    • withNullable

      public ValueRange withNullable(boolean mayBeNull)
      This interval, saying whether the expression may also answer NULL; EMPTY stays itself.
    • opaqueToConditions

      public ValueRange opaqueToConditions()
      This interval, as one no condition is settled by; EMPTY stays itself.
    • withConditionOpacityOf

      public ValueRange withConditionOpacityOf(ValueRange source)
      This interval, opaque to conditions where source is: for a value derived from it.
    • including

      public ValueRange including(BigDecimal value)
      This interval widened to hold value; a null value widens nothing.
    • union

      public ValueRange union(ValueRange other)
      The smallest interval holding both, NULL-able where either side is and opaque to conditions where either side is. An empty side adds no value, only its NULL; an unknown (null) side contributes nothing.
    • negate

      public ValueRange negate()
    • abs

      public ValueRange abs()
    • add

      public ValueRange add(ValueRange other)
    • subtract

      public ValueRange subtract(ValueRange other)
    • multiply

      public ValueRange multiply(ValueRange other)
      The interval of every product of one value from each side: the four corners bound it.
    • scaledBy

      public ValueRange scaledBy(BigDecimal factor)
      Both bounds multiplied by a non-negative factor.
    • symmetric

      public ValueRange symmetric()
      The interval mirrored about zero, so it holds every value of either sign this one can reach.
    • below

      public Boolean below(ValueRange other, boolean orEqual)
      Whether every value of this interval lies below every value of other — or at most, with orEqual: TRUE when every pair does, FALSE when none does, null when the intervals leave it open or either is empty.
    • equalTo

      public Boolean equalTo(ValueRange other)
      Whether this interval's values equal other's: TRUE for one shared point, FALSE when the two are disjoint, null when they leave it open or either is empty.
    • magnitude

      public BigDecimal magnitude()
      The greatest distance from zero this interval reaches; zero when empty.
    • toString

      public String toString()
      Overrides:
      toString in class Object