From b489cf13b03d93b18cad6d01c041dae19792e3a9 Mon Sep 17 00:00:00 2001
From: Arseniy Volynets <vol0ncar@yandex.ru>
Date: Sun, 4 Aug 2024 20:13:55 +0300
Subject: [PATCH] feat(sql): infer shard key from primary key

- sbroad submodule was already updated and
has commit supporting inferring sk from pk
- add integration test to check inference
is working
---
 CHANGELOG.md         |  2 ++
 test/int/test_sql.py | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index dad3ff8186..eeb14041c9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,8 @@ with the `YY.MINOR.MICRO` scheme.
 
 - Fix error "Read access to space '_raft_state' is denied"
   when executing a DML query on global tables
+- SQL now supports inferring sharding key from primary key, when
+  the former is not specified in `create table` clause
 
 ### Configuration
 
diff --git a/test/int/test_sql.py b/test/int/test_sql.py
index 1df31106c3..8c31661d6a 100644
--- a/test/int/test_sql.py
+++ b/test/int/test_sql.py
@@ -1748,6 +1748,23 @@ def test_create_drop_table(cluster: Cluster):
     assert ddl["row_count"] == 1
     cluster.raft_wait_index(i1.raft_get_index())
 
+    # check distribution can be skipped and sharding key
+    # will be inferred from primary key
+    ddl = i1.sql(
+        """
+        create table "infer_sk" ("a" string, "b" string,
+        primary key ("b", "a"))
+    """
+    )
+    assert ddl["row_count"] == 1
+    data = i1.sql(
+        """
+        select "distribution" from "_pico_table"
+        where "name" = 'infer_sk'
+    """
+    )
+    assert data == [[{"ShardedImplicitly": [["b", "a"], "murmur3", "default"]}]]
+
     with pytest.raises(TarantoolError, match="global spaces can use only memtx engine"):
         i1.sql(
             """
-- 
GitLab