Class SpatialRules

java.lang.Object
org.apache.calcite.rel.rules.SpatialRules

@Enclosing public abstract class SpatialRules extends Object
Collection of planner rules that convert calls to spatial functions into more efficient expressions.

The rules allow Calcite to use spatial indexes. For example the following query:

SELECT ... FROM Restaurants AS r WHERE ST_DWithin(ST_Point(10, 20), ST_Point(r.longitude, r.latitude), 5)

is rewritten to

SELECT ... FROM Restaurants AS r WHERE (r.h BETWEEN 100 AND 150 OR r.h BETWEEN 170 AND 185) AND ST_DWithin(ST_Point(10, 20), ST_Point(r.longitude, r.latitude), 5)

if there is the constraint

CHECK (h = Hilbert(8, r.longitude, r.latitude))

If the Restaurants table is sorted on h then the latter query can be answered using two limited range-scans, and so is much more efficient.

Note that the original predicate ST_DWithin(ST_Point(10, 20), ST_Point(r.longitude, r.latitude), 5) is still present, but is evaluated after the approximate predicate has eliminated many potential matches.

  • Field Details

    • INSTANCE

      public static final RelOptRule INSTANCE