aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordcherednik <dcherednik@ydb.tech>2023-11-22 21:12:23 +0300
committerdcherednik <dcherednik@ydb.tech>2023-11-23 01:16:32 +0300
commit9d6a9ad2fbde71948aa0402976a8e3ed43bc0da7 (patch)
treec7a873c02b208b27ec80df84c883ba0174e3941c
parentb2cadd1314b6fb7246fba40f6a2fd7439692aba1 (diff)
downloadydb-9d6a9ad2fbde71948aa0402976a8e3ed43bc0da7.tar.gz
FeatureFlag to disable UUID as primary key
-rw-r--r--ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp6
-rw-r--r--ydb/core/kqp/ut/yql/kqp_yql_ut.cpp72
-rw-r--r--ydb/core/protos/feature_flags.proto1
-rw-r--r--ydb/core/testlib/basics/feature_flags.h1
-rw-r--r--ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp8
-rw-r--r--ydb/core/tx/schemeshard/schemeshard_utils.cpp7
6 files changed, 93 insertions, 2 deletions
diff --git a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
index cff91a5cac..e1a288a85a 100644
--- a/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
+++ b/ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
@@ -1917,7 +1917,8 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
}
Y_UNIT_TEST(CreateTableWithPartitionAtKeysUuid) {
- TKikimrSettings kikimrSettings;
+ TKikimrSettings kikimrSettings = TKikimrSettings()
+ .SetEnableUuidAsPrimaryKey(true);
TKikimrRunner kikimr(kikimrSettings);
auto db = kikimr.GetTableClient();
auto session = db.CreateSession().GetValueSync().GetSession();
@@ -1961,7 +1962,8 @@ Y_UNIT_TEST_SUITE(KqpScheme) {
}
Y_UNIT_TEST(CreateTableWithUniformPartitionsUuid) {
- TKikimrSettings kikimrSettings;
+ TKikimrSettings kikimrSettings = TKikimrSettings()
+ .SetEnableUuidAsPrimaryKey(true);
TKikimrRunner kikimr(kikimrSettings);
auto db = kikimr.GetTableClient();
auto session = db.CreateSession().GetValueSync().GetSession();
diff --git a/ydb/core/kqp/ut/yql/kqp_yql_ut.cpp b/ydb/core/kqp/ut/yql/kqp_yql_ut.cpp
index 3c5c414943..8ae6687ed6 100644
--- a/ydb/core/kqp/ut/yql/kqp_yql_ut.cpp
+++ b/ydb/core/kqp/ut/yql/kqp_yql_ut.cpp
@@ -521,12 +521,83 @@ Y_UNIT_TEST_SUITE(KqpYql) {
CompareYson(R"([[[%true]]])", FormatResultSetYson(result.GetResultSet(0)));
}
+ Y_UNIT_TEST(UuidPrimaryKeyDisabled) {
+ NKikimrConfig::TAppConfig appConfig;
+ appConfig.MutableTableServiceConfig()->SetEnablePreparedDdl(true);
+ auto setting = NKikimrKqp::TKqpSetting();
+ auto serverSettings = TKikimrSettings()
+ .SetAppConfig(appConfig)
+ .SetKqpSettings({setting});
+ TKikimrRunner kikimr(serverSettings.SetWithSampleTables(false));
+
+ auto db = kikimr.GetTableClient();
+ auto session = db.CreateSession().GetValueSync().GetSession();
+
+ {
+ const auto query = Q_(R"(
+ CREATE TABLE test(
+ key uuid NOT NULL,
+ val int,
+ PRIMARY KEY (key)
+ );
+ )");
+ auto result = session.ExecuteSchemeQuery(query).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::PRECONDITION_FAILED, result.GetIssues().ToString());
+ }
+
+ {
+ const auto query = Q_(R"(
+ CREATE TABLE test(
+ key uuid,
+ val int,
+ PRIMARY KEY (key)
+ );
+ )");
+ auto result = session.ExecuteSchemeQuery(query).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::PRECONDITION_FAILED, result.GetIssues().ToString());
+ }
+
+ {
+ const auto query = Q_(R"(
+ CREATE TABLE test(
+ key int,
+ val uuid,
+ PRIMARY KEY (key),
+ INDEX val_index GLOBAL SYNC ON (val)
+ );
+ )");
+ auto result = session.ExecuteSchemeQuery(query).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::BAD_REQUEST, result.GetIssues().ToString());
+ }
+
+ {
+ const auto query = Q_(R"(
+ CREATE TABLE test(
+ key int,
+ val uuid,
+ PRIMARY KEY (key)
+ );
+ )");
+ auto result = session.ExecuteSchemeQuery(query).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString());
+ }
+
+ {
+ const auto query = Q_(R"(
+ ALTER TABLE test ADD INDEX val_index GLOBAL SYNC ON (val);
+ )");
+ auto result = session.ExecuteSchemeQuery(query).ExtractValueSync();
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::GENERIC_ERROR, result.GetIssues().ToString());
+ }
+ }
+
Y_UNIT_TEST(UuidPrimaryKey) {
NKikimrConfig::TAppConfig appConfig;
appConfig.MutableTableServiceConfig()->SetEnablePreparedDdl(true);
auto setting = NKikimrKqp::TKqpSetting();
auto serverSettings = TKikimrSettings()
.SetAppConfig(appConfig)
+ .SetEnableUuidAsPrimaryKey(true)
.SetKqpSettings({setting});
TKikimrRunner kikimr(serverSettings.SetWithSampleTables(false));
@@ -671,6 +742,7 @@ Y_UNIT_TEST_SUITE(KqpYql) {
Y_UNIT_TEST(UuidPrimaryKeyBulkUpsert) {
auto settings = TKikimrSettings()
+ .SetEnableUuidAsPrimaryKey(true)
.SetWithSampleTables(false);
auto kikimr = TKikimrRunner{settings};
auto db = kikimr.GetTableClient();
diff --git a/ydb/core/protos/feature_flags.proto b/ydb/core/protos/feature_flags.proto
index 86f9ffa41a..66de8709de 100644
--- a/ydb/core/protos/feature_flags.proto
+++ b/ydb/core/protos/feature_flags.proto
@@ -119,4 +119,5 @@ message TFeatureFlags {
optional bool EnableUniqConstraint = 104 [default = false];
optional bool EnableChangefeedDebeziumJsonFormat = 105 [default = false];
optional bool EnableStatistics = 106 [default = false];
+ optional bool EnableUuidAsPrimaryKey = 107 [default = false];
}
diff --git a/ydb/core/testlib/basics/feature_flags.h b/ydb/core/testlib/basics/feature_flags.h
index 173e51e6ea..00bf98e982 100644
--- a/ydb/core/testlib/basics/feature_flags.h
+++ b/ydb/core/testlib/basics/feature_flags.h
@@ -53,6 +53,7 @@ public:
FEATURE_FLAG_SETTER(ForceColumnTablesCompositeMarks)
FEATURE_FLAG_SETTER(EnableUniqConstraint)
FEATURE_FLAG_SETTER(EnableTopicMessageMeta)
+ FEATURE_FLAG_SETTER(EnableUuidAsPrimaryKey)
#undef FEATURE_FLAG_SETTER
};
diff --git a/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp b/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp
index 67ac63a6eb..1528bfa4dd 100644
--- a/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp
+++ b/ydb/core/tx/schemeshard/schemeshard__operation_create_table.cpp
@@ -23,6 +23,14 @@ bool CheckColumnTypesConstraints(NKikimrSchemeOp::TTableDescription& desc, TStri
THashSet<TString> keyColumns(desc.GetKeyColumnNames().begin(), desc.GetKeyColumnNames().end());
for (const auto& column : desc.GetColumns()) {
+ const auto& type = column.GetType();
+ if (type == "Uuid") {
+ if (!AppData()->FeatureFlags.GetEnableUuidAsPrimaryKey() && keyColumns.contains(column.GetName())) {
+ errMsg = TStringBuilder() << "Uuid as primary key is forbiden by configuration: " << column.GetName();
+ return false;
+ }
+ }
+
if (column.GetNotNull()) {
bool isPrimaryKey = keyColumns.contains(column.GetName());
diff --git a/ydb/core/tx/schemeshard/schemeshard_utils.cpp b/ydb/core/tx/schemeshard/schemeshard_utils.cpp
index bd3f910d31..13642fc105 100644
--- a/ydb/core/tx/schemeshard/schemeshard_utils.cpp
+++ b/ydb/core/tx/schemeshard/schemeshard_utils.cpp
@@ -549,6 +549,13 @@ bool IsCompatibleKeyTypes(
Y_ABORT_UNLESS(baseTableColumnTypes.contains(keyName));
auto typeInfo = baseTableColumnTypes.at(keyName);
+ if (typeInfo.GetTypeId() == NScheme::NTypeIds::Uuid) {
+ if (!AppData()->FeatureFlags.GetEnableUuidAsPrimaryKey()) {
+ explain += TStringBuilder() << "Uuid as primary key is forbiden by configuration: " << keyName;
+ return false;
+ }
+ }
+
if (uniformTable) {
switch (typeInfo.GetTypeId()) {
case NScheme::NTypeIds::Uint32: