What is the difference between Placement Rules In SQL and Placement Rules?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: Placement Rules In SQL 和 Placement Rules 的区别?

| username: watermelon_cn

I have the following questions:

  1. Is it necessary to have a region label when configuring TiKV for Placement Rules In SQL?

  2. In the DR Auto-sync adaptive synchronization mode, can the placement rule configuration file be adjusted to the Placement Rules In SQL method?

  3. Can Placement Rules In SQL replace Placement Rules? Using Placement Rules requires configuring a configuration file, while Placement Rules In SQL can be done with just one SQL statement.
    For example, to achieve 3 replicas and place all table region leaders of the testdb database on TiKV labeled as bj, you can do it like this:

  4. CREATE PLACEMENT POLICY test_policy PRIMARY_REGION=“bj” REGIONS=“bj,dl,sz” FOLLOWERS=2;

  5. create database testdb placement policy=test_policy;
    If using the Placement Rules configuration file method:
    {
    “group_id”: “pd”,
    “group_index”: 0,
    “group_override”: false,
    “rules”: [
    {
    “group_id”: “pd”,
    “id”: “az-east”,
    “start_key”: “”,
    “end_key”: “”,
    “role”: “voter”,
    “count”: 1,
    “label_constraints”: [
    {
    “key”: “region”,
    “op”: “in”,
    “values”: [
    “bj”
    ]
    }
    ],
    “location_labels”: [
    “rack”,
    “dc”,
    “region”
    ]
    },
    {
    “group_id”: “pd”,
    “id”: “az-west”,
    “start_key”: “”,
    “end_key”: “”,
    “role”: “follower”,
    “count”: 1,
    “label_constraints”: [
    {
    “key”: “region”,
    “op”: “in”,
    “values”: [
    “dl”
    ]
    }
    ],
    “location_labels”: [
    “rack”,
    “dc”,
    “region”
    ]
    },
    {
    “group_id”: “pd”,
    “id”: “az-west”,
    “start_key”: “”,
    “end_key”: “”,
    “role”: “learner”,
    “count”: 1,
    “label_constraints”: [
    {
    “key”: “region”,
    “op”: “in”,
    “values”: [
    “sz”
    ]
    }
    ],
    “location_labels”: [
    “dc”,
    “rack”,
    “region”
    ]
    }

| username: tidb菜鸟一只 | Original post link

Placement rules in SQL still cannot cover all scenarios of placement rules, right?

| username: watermelon_cn | Original post link

Can you provide an example? Which scenarios in SQL cannot be covered?

| username: watermelon_cn | Original post link

Rewrite dr auto sync to in sql mode: 3 Voter replicas in the primary AZ, 2 Follower replicas and 1 Learner replica in the secondary AZ. Please have an expert check if this is supported.

create placement policy test_policy LEADER_CONSTRAINTS="[+az=primary]" FOLLOWER_CONSTRAINTS="{+az=dr:2}" LEARNER_CONSTRAINTS="{+az=dr:1}";
create database testdb placement policy=test_policy;