Designing Segmented Projections for K-Safety
Projections must comply with database K-safety requirements. In general, you must create buddy projections for each segmented projection, where the number of buddy projections is K+1. Thus, if system K-safety is set to 1, each projection segment must be duplicated by one buddy; if K-safety is set to 2, each segment must be duplicated by two buddies.
Automatic Creation of Buddy Projections
You can use CREATE PROJECTION
so it automatically creates the number of buddy projections required to satisfy K-safety, by including SEGMENTED BY ... ALL NODES
. If CREATE PROJECTION
specifies K-safety (KSAFE=n)
, Vertica uses that setting; if the statement omits KSAFE
, Vertica uses system K-safety.
In the following example, CREATE PROJECTION
creates segmented projection ttt_p1
for table ttt
. Because system K‑safety is set to 1, Vertica requires a buddy projection for each segmented projection. The CREATE PROJECTION
statement omits KSAFE
, so Vertica uses system K‑safety and creates two buddy projections: ttt_p1_b0
and ttt_p1_b1
:
=> SELECT mark_design_ksafe(1); mark_design_ksafe ---------------------- Marked design 1-safe (1 row) => CREATE TABLE ttt (a int, b int); WARNING 6978: Table "ttt" will include privileges from schema "public" CREATE TABLE => CREATE PROJECTION ttt_p1 as SELECT * FROM ttt SEGMENTED BY HASH(a) ALL NODES; CREATE PROJECTION => SELECT projection_name from projections WHERE anchor_table_name='ttt'; projection_name ----------------- ttt_p1_b0 ttt_p1_b1 (2 rows)
Vertica automatically names buddy projections by appending the suffix _bn
to the projection base name—for example ttt_p1_b0
.
Manual Creation of Buddy Projections
If you create a projection on a single node, and system K-safety is greater than 0, you must manually create the number of buddies required for K-safety. For example, you can create projection xxx_p1
for table xxx
on a single node, as follows:
=> CREATE TABLE xxx (a int, b int); WARNING 6978: Table "xxx" will include privileges from schema "public" CREATE TABLE => CREATE PROJECTION xxx_p1 AS SELECT * FROM xxx SEGMENTED BY HASH(a) NODES v_vmart_node0001; CREATE PROJECTION
Because K-safety is set to 1, a single instance of this projection is not K-safe. Attempts to insert data into its anchor table xxx
return with an error like this:
=> INSERT INTO xxx VALUES (1, 2); ERROR 3586: Insufficient projections to answer query DETAIL: No projections that satisfy K-safety found for table xxx HINT: Define buddy projections for table xxx
In order to comply with K-safety, you must create a buddy projection for projection xxx_p1
. For example:
=> CREATE PROJECTION xxx_p1_buddy AS SELECT * FROM xxx SEGMENTED BY HASH(a) NODES v_vmart_node0002; CREATE PROJECTION
Table xxx
now complies with K-safety and accepts DML statements such as INSERT
:
VMart=> INSERT INTO xxx VALUES (1, 2); OUTPUT -------- 1 (1 row)
See Also
For general information about segmented projections and buddies, see Projection Segmentation in Vertica Concepts. For information about designing for K-safety, see Designing for K-Safety and Designing for Segmentation.