Skip to content

Revert some restriction on secondary index creation #7963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ydb/core/base/table_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ bool IsCompatibleIndex(NKikimrSchemeOp::EIndexType indexType, const TTableColumn
explain = "should be at least single index key column";
return false;
}
if (index.KeyColumns.size() <= table.Keys.size() &&
std::equal(index.KeyColumns.begin(), index.KeyColumns.end(), table.Keys.begin())) {
explain = "index keys are prefix of table keys";
if (index.KeyColumns == table.Keys) {
explain = "index keys shouldn't be table keys";
return false;
}
} else {
Expand Down
29 changes: 16 additions & 13 deletions ydb/core/base/ut/table_index_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,35 @@ Y_UNIT_TEST_SUITE (TableIndex) {
auto type = NKikimrSchemeOp::EIndexType::EIndexTypeGlobal;

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1", "DATA2"}, {}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"PK1", "PK2"}, {}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {"DATA3"}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

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

UNIT_ASSERT(IsCompatibleIndex(type, Table2, {{NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}, {}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

UNIT_ASSERT(IsCompatibleIndex(type, Table2, {{"DATA"}, {NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
}
{
const TTableColumns Table3{{"PK", "DATA", NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}, {NTableVectorKmeansTreeIndex::PostingTable_ParentIdColumn}};

UNIT_ASSERT(IsCompatibleIndex(type, Table3, {{"DATA"}, {}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
}

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"PK2"}, {}}, explain));
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
}

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

UNIT_ASSERT(!IsCompatibleIndex(type, Table, {{"PK2"}, {}}, explain));
UNIT_ASSERT_STRINGS_EQUAL(explain, "index keys are prefix of table keys");
UNIT_ASSERT(!IsCompatibleIndex(type, Table, {{"PK2", "PK1"}, {}}, explain));
UNIT_ASSERT_STRINGS_EQUAL(explain, "index keys shouldn't be table keys");
}

Y_UNIT_TEST (CompatibleVectorIndex) {
TString explain;
auto type = NKikimrSchemeOp::EIndexType::EIndexTypeGlobalVectorKmeansTree;

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {"DATA3"}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"PK1"}, {}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");

UNIT_ASSERT(IsCompatibleIndex(type, Table, {{"DATA1"}, {"DATA1"}}, explain));
UNIT_ASSERT(explain.empty());
UNIT_ASSERT_STRINGS_EQUAL(explain, "");
}

Y_UNIT_TEST (NotCompatibleVectorIndex) {
Expand Down
Loading