<@U0A71G31CDV> Can I restrict certain primary key ...
# questions-and-troubleshooting
m
@Rocky Can I restrict certain primary key tables to a select group of BE nodes?
r
Yes, you can restrict Primary Key tables (and other table types) to a specific group of BE nodes using BE Labels, a feature introduced in StarRocks v3.2.8. By assigning labels to your BE nodes and then specifying those labels in your table's properties, you can control the physical distribution of data replicas. Step 1: Assign Labels to BE Nodes First, group your BE nodes by adding a location label. For example, if you want to group three specific BEs into a "high_perf" group:
Copy code
sql
-- Repeat for each BE in your target group
ALTER SYSTEM MODIFY BACKEND "172.xx.xx.46:9050" SET ("labels.location" = "group:high_perf");
ALTER SYSTEM MODIFY BACKEND "172.xx.xx.47:9050" SET ("labels.location" = "group:high_perf");
ALTER SYSTEM MODIFY BACKEND "172.xx.xx.48:9050" SET ("labels.location" = "group:high_perf");
Step 2: Create or Modify the Primary Key Table When creating the table, use the
labels.location
property to tell StarRocks to only place replicas on nodes with that specific label. At Table Creation:
Copy code
sql
CREATE TABLE pk_table_restricted (
    id BIGINT NOT NULL,
    name STRING,
    value INT
) PRIMARY KEY (id)
DISTRIBUTED BY HASH(id)
PROPERTIES (
    "labels.location" = "group:high_perf",
    "replication_num" = "3"
);
For an Existing Table: If the table already exists, you can alter it. StarRocks will gradually migrate the tablets to the nodes matching the label.
Copy code
sql
ALTER TABLE pk_table_restricted SET ("labels.location" = "group:high_perf");
Important Considerations: * Replication Count: Ensure the number of BEs with the specified label is greater than or equal to your
replication_num
. If there aren't enough nodes in that group, the system may place replicas on other nodes to satisfy the high-availability requirement. * Version: This feature specifically requires v3.2.8 or later. * Shared-Data vs Shared-Nothing: This configuration primarily affects where the data replicas/tablets are stored and processed in a Shared-Nothing architecture. In a Shared-Data (Cloud Native) architecture, compute is typically managed via Compute Nodes (CN) and Warehouse isolation, though similar concepts for local cache affinity exist. If you are using an older version, the primary way to influence placement is through Colocation Groups (which ensures related tables are on the same nodes but doesn't strictly "lock" them to specific nodes) or by using different StarRocks clusters for complete isolation. Referencesadministration/management/resource_management/be_label.mdfaq/resource_isolation_faq.mdadministration/management/resource_management/resource_group.md