Home » Documentation » Using VoltDB


@GetPartitionKeys — Returns a list of partition values, one for every partition in the database.


@GetPartitionKeys String datatype


The @GetPartitionKeys system procedure returns a set of partition values that you can use to reach every partition in the database. This procedure is useful when you want to run a stored procedure in every partition but you do not want to use a multi-partition procedure. By running multiple single-partition procedures, you avoid the impact on latency and throughput that can result from a multi-partition procedure. This is particularly true for longer running procedures. Using multiple, smaller procedures can also help for queries that modify large volumes of data, such as large deletes.

When you call @GetPartitionKeys you specify the datatype of the keys to return as the second parameter. You specify the datatype as a case-insensitive string. Valid options are "INTEGER", "STRING", and "VARCHAR" (where "STRING" and "VARCHAR" are synonyms).

Note that the results of the system procedure are valid at the time they are generated. If the cluster is static (that is, no nodes are being added and any rebalancing is complete), the results remain valid until the next elastic event. However, during rebalancing, the distribution of partitions is likely to change. So it is a good idea to call @GetPartitionKeys once to get the keys, act on them, then call the system procedure again to verify that the partitions have not changed.

Return Values

Returns one VoltTable with a row for every unique partition in the cluster.

PARTITION_IDINTEGERThe numeric ID of the partition.
PARTITION_KEYINTEGER or STRINGA valid partition key for the partition. The datatype of the key matches the type requested in the procedure call.


The following example shows the use of sqlcmd to get integer key values from @GetPartitionKeys:

1> exec @GetPartitionKeys integer;

The next example shows a Java program using @GetPartitionKeys to execute a stored procedure to clear out old records, one partition at a time.

VoltTable[] results = client.callProcedure("@GetPartitionKeys", 
VoltTable keys = results[0];
for (int k=0;k<keys.getRowCount();k++) {
    long key = keys.fetchRow(k).getLong(1);
    client.callProcedure("PurgeOldData", key);