A newer version of Hazelcast Platform is available.

View latest

Partition pruning

Partition pruning is an IMap-specific query optimization technique that automatically prunes members that don’t contain the required data on their partitions, and optimizes the count of Jet scan processors on required members.

  • By default, partition pruning works for primitive __key types (default attribute strategy).

  • It also works for all key types if you configure the attribute based partitioning strategy. See the Attribute Based Partitioning Strategy topic.

The partition pruning may be used only when querying an IMap mapping if the partitioning strategy attribute is enabled.
The query coordinator member is always involved in the query execution, even if it doesn’t contain any required data.

Example

The following example shows the config updates for the IMap partitioning strategy on the Java side, and the SQL query that enables the partition pruning optimizations.

Java:

// first, define a complex key class
class ComplexKey implemetns Serializable {
  private String k1;
  private int k2;

  public ComplexKey(String k1, int k2) {
    this.k1 = k1;
    this.k2 = k2;
  }

  public String getK1() {
    return k1;
  }

  public int getK2() {
    return k2;
  }

  // equals and hashCode omitted for brevity
}

// then, define a map name and configure the map with a partitioning strategy
String mapName = "map";
hz.addMapConfig(new MapConfig(mapName).setPartitioningAttributeConfigs("k2"));

// create IMap and populate it with some data
IMap<ComplexKey, String> map = hz.getMap(mapName);
map.put(new ComplexKey("k1", 21), "v1");
map.put(new ComplexKey("k2", 42), "v2");

SQL queries:

-- Create a mapping to observe IMap in SQL context;
CREATE MAPPING map (k1 VARCHAR, k2 INT, v VARCHAR)
TYPE IMap
OPTIONS ('keyFormat' = 'java', 'valueFormat' = 'varchar');

-- Query IMap with a predicate allowing partition pruning;
SELECT * FROM cities WHERE k2 = 42;