Employing these functions will prevent any automatic resharding
of data to allow the query to succeed. Use only when a better query plan
(with respect to data distribution) is known than any the system can devise.
KI_REPLICATE()
KI_REPLICATE()
Force a scalar result set to be replicated (query/subquery with no
GROUP BY)KI_REPLICATE_GROUP_BY(0)
KI_REPLICATE_GROUP_BY(0)
Force an aggregated result set to be replicated (query/subquery with
GROUP BY)KI_MATCH_COLUMN(0)
KI_MATCH_COLUMN(0)
KI_SHARD_KEY(<column list>)
KI_SHARD_KEY(<column list>)
Force the result set to be sharded on the given columns.
This will override any implicitly-derived or explicitly-defined
replication status the table would have had.
The column(s) listed in
column list must also appear in the
SELECT list; KI_SHARD_KEY merely identifies which of the
selected columns should be used as the shard key.Sharding Example
For example, a query for all employees and their total employees managed, including employees who don’t manage anyone, could employ a UNION like this:Sharding Example
employee table is sharded on id.
Since the first part of the UNION aggregates on manager_id, the result
will be replicated. The second part of the UNION does
no aggregation and includes the shard key in the SELECT
list; the result of this will be sharded.
Prior to Kinetica v7.0, the limitation of UNION
operations requiring that both parts of a UNION have to be distributed the
same way, would make the query fail, with the following message:
UNION to match the second
part:
Re-shard Example
KI_SHARD_KEY is used to make the selected
manager_id column the new shard key for the first part of the UNION.
Now, the shard key for the first part of the UNION (manager_id) aligns
with the shard key for the second part (id), and the query succeeds. Note
the use of KI_MATCH_COLUMN, which aligns the selected column lists on each
side of the UNION. Without this matching distribution function, the
UNION would appear to be merging three columns from the first part of the
query into two columns in the second part and would fail.
The
manager_id column must exist in the SELECT list in order
for the KI_SHARD_KEY function to designate it as the shard key.