Skip to content

Commit 274bfdd

Browse files
authored
Revert some restriction on secondary index creation (#7963)
1 parent 2c0edd6 commit 274bfdd

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

ydb/core/base/table_index.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,8 @@ bool IsCompatibleIndex(NKikimrSchemeOp::EIndexType indexType, const TTableColumn
105105
explain = "should be at least single index key column";
106106
return false;
107107
}
108-
if (index.KeyColumns.size() <= table.Keys.size() &&
109-
std::equal(index.KeyColumns.begin(), index.KeyColumns.end(), table.Keys.begin())) {
110-
explain = "index keys are prefix of table keys";
108+
if (index.KeyColumns == table.Keys) {
109+
explain = "index keys shouldn't be table keys";
111110
return false;
112111
}
113112
} else {

ydb/core/base/ut/table_index_ut.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,35 @@ Y_UNIT_TEST_SUITE (TableIndex) {
1515
auto type = NKikimrSchemeOp::EIndexType::EIndexTypeGlobal;
1616

1717
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {}}, explain));
18-
UNIT_ASSERT(explain.empty());
18+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
1919

2020
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1", "DATA2"}, {}}, explain));
21-
UNIT_ASSERT(explain.empty());
21+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
2222

2323
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"PK1", "PK2"}, {}}, explain));
24-
UNIT_ASSERT(explain.empty());
24+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
2525

2626
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {"DATA3"}}, explain));
27-
UNIT_ASSERT(explain.empty());
27+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
2828

2929
{
3030
const TTableColumns Table2{{"PK", "DATA", NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}, {"PK"}};
3131

3232
UNIT_ASSERT(IsCompatibleIndex(type, Table2, {{NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}, {}}, explain));
33-
UNIT_ASSERT(explain.empty());
33+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
3434

3535
UNIT_ASSERT(IsCompatibleIndex(type, Table2, {{"DATA"}, {NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}}, explain));
36-
UNIT_ASSERT(explain.empty());
36+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
3737
}
3838
{
3939
const TTableColumns Table3{{"PK", "DATA", NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}, {NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}};
4040

4141
UNIT_ASSERT(IsCompatibleIndex(type, Table3, {{"DATA"}, {}}, explain));
42-
UNIT_ASSERT(explain.empty());
42+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
4343
}
44+
45+
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"PK2"}, {}}, explain));
46+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
4447
}
4548

4649
Y_UNIT_TEST (NotCompatibleSecondaryIndex) {
@@ -71,25 +74,25 @@ Y_UNIT_TEST_SUITE (TableIndex) {
7174
UNIT_ASSERT(!IsCompatibleIndex(type, Table, {{}, {}}, explain));
7275
UNIT_ASSERT_STRINGS_EQUAL(explain, "should be at least single index key column");
7376

74-
UNIT_ASSERT(!IsCompatibleIndex(type, Table, {{"PK2"}, {}}, explain));
75-
UNIT_ASSERT_STRINGS_EQUAL(explain, "index keys are prefix of table keys");
77+
UNIT_ASSERT(!IsCompatibleIndex(type, Table, {{"PK2", "PK1"}, {}}, explain));
78+
UNIT_ASSERT_STRINGS_EQUAL(explain, "index keys shouldn't be table keys");
7679
}
7780

7881
Y_UNIT_TEST (CompatibleVectorIndex) {
7982
TString explain;
8083
auto type = NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree;
8184

8285
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {}}, explain));
83-
UNIT_ASSERT(explain.empty());
86+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
8487

8588
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {"DATA3"}}, explain));
86-
UNIT_ASSERT(explain.empty());
89+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
8790

8891
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"PK1"}, {}}, explain));
89-
UNIT_ASSERT(explain.empty());
92+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
9093

9194
UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {"DATA1"}}, explain));
92-
UNIT_ASSERT(explain.empty());
95+
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
9396
}
9497

9598
Y_UNIT_TEST (NotCompatibleVectorIndex) {

0 commit comments

Comments
 (0)