Skip to content

Commit 26b8ef3

Browse files
fix indexes usage, option for exclusive pk case (#3731)
1 parent dec300e commit 26b8ef3

File tree

12 files changed

+54
-6
lines changed

12 files changed

+54
-6
lines changed

ydb/core/kqp/gateway/behaviour/tablestore/operations/upsert_opt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@ TConclusionStatus TUpsertOptionsOperation::DoDeserialize(NYql::TObjectSettingsIm
1010
TConclusionStatus::Fail("Incorrect value for SCHEME_NEED_ACTUALIZATION: cannot parse as boolean");
1111
}
1212
SchemeNeedActualization = *value;
13+
ExternalGuaranteeExclusivePK = features.Extract<bool>("EXTERNAL_GUARANTEE_EXCLUSIVE_PK");
1314
return TConclusionStatus::Success();
1415
}
1516

1617
void TUpsertOptionsOperation::DoSerializeScheme(NKikimrSchemeOp::TAlterColumnTableSchema& schemaData) const {
1718
schemaData.MutableOptions()->SetSchemeNeedActualization(SchemeNeedActualization);
19+
if (ExternalGuaranteeExclusivePK) {
20+
schemaData.MutableOptions()->SetExternalGuaranteeExclusivePK(*ExternalGuaranteeExclusivePK);
21+
}
22+
1823
}
1924

2025
}

ydb/core/kqp/gateway/behaviour/tablestore/operations/upsert_opt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class TUpsertOptionsOperation : public ITableStoreOperation {
1212
static inline const auto Registrator = TFactory::TRegistrator<TUpsertOptionsOperation>(GetTypeName());
1313
private:
1414
bool SchemeNeedActualization = false;
15+
std::optional<bool> ExternalGuaranteeExclusivePK;
1516
public:
1617
TConclusionStatus DoDeserialize(NYql::TObjectSettingsImpl::TFeaturesExtractor& features) override;
1718

ydb/core/kqp/ut/olap/indexes_ut.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Y_UNIT_TEST_SUITE(KqpOlapIndexes) {
1919
auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NYDBTest::NColumnShard::TController>();
2020
csController->SetPeriodicWakeupActivationPeriod(TDuration::Seconds(1));
2121
csController->SetLagForCompactionBeforeTierings(TDuration::Seconds(1));
22+
csController->SetOverrideReduceMemoryIntervalLimit(1LLU << 30);
2223

2324
TLocalHelper(kikimr).CreateTestOlapTable();
2425
auto tableClient = kikimr.GetTableClient();
@@ -77,7 +78,7 @@ Y_UNIT_TEST_SUITE(KqpOlapIndexes) {
7778

7879
{
7980
auto alterQuery = TStringBuilder() <<
80-
"ALTER OBJECT `/Root/olapStore` (TYPE TABLESTORE) SET (ACTION=UPSERT_OPTIONS, SCHEME_NEED_ACTUALIZATION=`true`);";
81+
"ALTER OBJECT `/Root/olapStore` (TYPE TABLESTORE) SET (ACTION=UPSERT_OPTIONS, SCHEME_NEED_ACTUALIZATION=`true`, EXTERNAL_GUARANTEE_EXCLUSIVE_PK=`true`);";
8182
auto session = tableClient.CreateSession().GetValueSync().GetSession();
8283
auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync();
8384
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), NYdb::EStatus::SUCCESS, alterResult.GetIssues().ToString());
@@ -104,7 +105,7 @@ Y_UNIT_TEST_SUITE(KqpOlapIndexes) {
104105
}
105106
}
106107

107-
Y_UNIT_TEST(IndexesActualizationRebuildScheme) {
108+
Y_UNIT_TEST(SchemeActualizationOnceOnStart) {
108109
auto settings = TKikimrSettings()
109110
.SetWithSampleTables(false);
110111
TKikimrRunner kikimr(settings);
@@ -179,6 +180,7 @@ Y_UNIT_TEST_SUITE(KqpOlapIndexes) {
179180
// Tests::NCommon::TLoggerInit(kikimr).Initialize();
180181

181182
auto csController = NYDBTest::TControllers::RegisterCSControllerGuard<NYDBTest::NColumnShard::TController>();
183+
csController->SetOverrideReduceMemoryIntervalLimit(1LLU << 30);
182184

183185
{
184186
auto alterQuery = TStringBuilder() <<
@@ -198,6 +200,13 @@ Y_UNIT_TEST_SUITE(KqpOlapIndexes) {
198200
auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync();
199201
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), NYdb::EStatus::SUCCESS, alterResult.GetIssues().ToString());
200202
}
203+
{
204+
auto alterQuery = TStringBuilder() <<
205+
"ALTER OBJECT `/Root/olapStore` (TYPE TABLESTORE) SET (ACTION=UPSERT_OPTIONS, EXTERNAL_GUARANTEE_EXCLUSIVE_PK=`true`);";
206+
auto session = tableClient.CreateSession().GetValueSync().GetSession();
207+
auto alterResult = session.ExecuteSchemeQuery(alterQuery).GetValueSync();
208+
UNIT_ASSERT_VALUES_EQUAL_C(alterResult.GetStatus(), NYdb::EStatus::SUCCESS, alterResult.GetIssues().ToString());
209+
}
201210

202211
std::vector<TString> uids;
203212
std::vector<TString> resourceIds;

ydb/core/protos/flat_scheme_op.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ message TStorageTierConfig {
495495

496496
message TColumnTableSchemeOptions {
497497
optional bool SchemeNeedActualization = 1 [default = false];
498+
optional bool ExternalGuaranteeExclusivePK = 2 [default = false];
498499
}
499500

500501
message TColumnTableSchema {
@@ -523,6 +524,7 @@ message TColumnTableSchema {
523524

524525
message TColumnTableRequestedOptions {
525526
optional bool SchemeNeedActualization = 1 [default = false];
527+
optional bool ExternalGuaranteeExclusivePK = 2;
526528
}
527529

528530
message TAlterColumnTableSchema {

ydb/core/tx/columnshard/engines/reader/abstract/read_metadata.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ struct TReadMetadataBase {
6262
return ResultIndexSchema;
6363
}
6464

65+
bool HasGuaranteeExclusivePK() const {
66+
return GetIndexInfo().GetExternalGuaranteeExclusivePK();
67+
}
68+
6569
ISnapshotSchema::TPtr GetLoadSchemaVerified(const TPortionInfo& porition) const;
6670

6771
std::shared_ptr<arrow::Schema> GetBlobSchema(const ui64 version) const {

ydb/core/tx/columnshard/engines/reader/plain_reader/iterator/context.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ std::shared_ptr<TFetchingScript> TSpecialReadContext::GetColumnsFetchingPlan(con
3434
const bool needSnapshots = !source->GetExclusiveIntervalOnly() || ReadMetadata->GetRequestSnapshot() < source->GetRecordSnapshotMax() || !source->IsSourceInMemory();
3535
const bool partialUsageByPK = ReadMetadata->GetPKRangesFilter().IsPortionInPartialUsage(source->GetStartReplaceKey(), source->GetFinishReplaceKey(), ReadMetadata->GetIndexInfo());
3636
const bool useIndexes = (IndexChecker ? source->HasIndexes(IndexChecker->GetIndexIds()) : false);
37-
if (auto result = CacheFetchingScripts[needSnapshots ? 1 : 0][(source->GetExclusiveIntervalOnly() && source->IsSourceInMemory()) ? 1 : 0][partialUsageByPK ? 1 : 0][useIndexes ? 1 : 0]) {
37+
const bool isWholeExclusiveSource = source->GetExclusiveIntervalOnly() && source->IsSourceInMemory();
38+
if (auto result = CacheFetchingScripts[needSnapshots ? 1 : 0][isWholeExclusiveSource ? 1 : 0][partialUsageByPK ? 1 : 0][useIndexes ? 1 : 0]) {
39+
// AFL_WARN(NKikimrServices::TX_COLUMNSHARD_SCAN)("SS", needSnapshots)("PK", partialUsageByPK)("IDX", useIndexes)("EXCL", source->GetExclusiveIntervalOnly())("MEM", source->IsSourceInMemory())("result", result->DebugString());
3840
return result;
3941
}
4042
{
@@ -49,7 +51,7 @@ std::shared_ptr<TFetchingScript> TSpecialReadContext::BuildColumnsFetchingPlan(c
4951
const bool partialUsageByPredicateExt, const bool useIndexes) const {
5052
std::shared_ptr<TFetchingScript> result = std::make_shared<TFetchingScript>();
5153
const bool partialUsageByPredicate = partialUsageByPredicateExt && PredicateColumns->GetColumnsCount();
52-
if (!!IndexChecker && useIndexes) {
54+
if (!!IndexChecker && useIndexes && exclusiveSource) {
5355
result->AddStep(std::make_shared<TIndexBlobsFetchingStep>(std::make_shared<TIndexesSet>(IndexChecker->GetIndexIds())));
5456
result->AddStep(std::make_shared<TApplyIndexStep>(IndexChecker));
5557
}

ydb/core/tx/columnshard/engines/reader/plain_reader/iterator/scanner.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ void TScanHead::OnIntervalResult(const std::optional<NArrow::TShardedRecordBatch
5656
}
5757

5858
TConclusionStatus TScanHead::Start() {
59+
const bool guaranteeExclusivePK = Context->GetCommonContext()->GetReadMetadata()->HasGuaranteeExclusivePK();
5960
TScanContext context;
6061
for (auto itPoint = BorderPoints.begin(); itPoint != BorderPoints.end(); ++itPoint) {
6162
auto& point = itPoint->second;
6263
context.OnStartPoint(point);
6364
if (context.GetIsSpecialPoint()) {
64-
auto detectorResult = DetectSourcesFeatureInContextIntervalScan(context.GetCurrentSources(), false);
65+
auto detectorResult = DetectSourcesFeatureInContextIntervalScan(context.GetCurrentSources(), guaranteeExclusivePK);
6566
for (auto&& i : context.GetCurrentSources()) {
6667
i.second->IncIntervalsCount();
6768
}
@@ -82,7 +83,7 @@ TConclusionStatus TScanHead::Start() {
8283
for (auto&& i : context.GetCurrentSources()) {
8384
i.second->IncIntervalsCount();
8485
}
85-
auto detectorResult = DetectSourcesFeatureInContextIntervalScan(context.GetCurrentSources(), context.GetIsExclusiveInterval());
86+
auto detectorResult = DetectSourcesFeatureInContextIntervalScan(context.GetCurrentSources(), guaranteeExclusivePK || context.GetIsExclusiveInterval());
8687
if (!detectorResult) {
8788
AFL_ERROR(NKikimrServices::TX_COLUMNSHARD_SCAN)("event", "scanner_initializer_aborted")("reason", detectorResult.GetErrorMessage());
8889
Abort();

ydb/core/tx/columnshard/engines/scheme/index_info.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ bool TIndexInfo::DeserializeFromProto(const NKikimrSchemeOp::TColumnTableSchema&
320320

321321
{
322322
SchemeNeedActualization = schema.GetOptions().GetSchemeNeedActualization();
323+
ExternalGuaranteeExclusivePK = schema.GetOptions().GetExternalGuaranteeExclusivePK();
323324
}
324325

325326
if (schema.HasDefaultCompression()) {

ydb/core/tx/columnshard/engines/scheme/index_info.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ struct TIndexInfo : public NTable::TScheme::TTableSchema, public IIndexInfo {
4242
std::map<TString, NStatistics::TOperatorContainer> StatisticsByName;
4343
TIndexInfo(const TString& name);
4444
bool SchemeNeedActualization = false;
45+
bool ExternalGuaranteeExclusivePK = false;
4546
bool DeserializeFromProto(const NKikimrSchemeOp::TColumnTableSchema& schema, const std::shared_ptr<IStoragesManager>& operators);
4647
TColumnFeatures& GetOrCreateColumnFeatures(const ui32 columnId) const;
4748
void BuildSchemaWithSpecials();
4849
void BuildArrowSchema();
4950
void InitializeCaches(const std::shared_ptr<IStoragesManager>& operators);
5051
public:
52+
bool GetExternalGuaranteeExclusivePK() const {
53+
return ExternalGuaranteeExclusivePK;
54+
}
55+
5156
const TColumnFeatures& GetColumnFeaturesVerified(const ui32 columnId) const {
5257
auto it = ColumnFeatures.find(columnId);
5358
AFL_VERIFY(it != ColumnFeatures.end());

ydb/core/tx/schemeshard/olap/options/schema.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,24 @@ namespace NKikimr::NSchemeShard {
44

55
bool TOlapOptionsDescription::ApplyUpdate(const TOlapOptionsUpdate& schemaUpdate, IErrorCollector& /*errors*/) {
66
SchemeNeedActualization = schemaUpdate.GetSchemeNeedActualization();
7+
if (!!schemaUpdate.GetExternalGuaranteeExclusivePK()) {
8+
ExternalGuaranteeExclusivePK = *schemaUpdate.GetExternalGuaranteeExclusivePK();
9+
}
710
return true;
811
}
912

1013
void TOlapOptionsDescription::Parse(const NKikimrSchemeOp::TColumnTableSchema& tableSchema) {
1114
SchemeNeedActualization = tableSchema.GetOptions().GetSchemeNeedActualization();
15+
if (tableSchema.GetOptions().HasExternalGuaranteeExclusivePK()) {
16+
ExternalGuaranteeExclusivePK = tableSchema.GetOptions().GetExternalGuaranteeExclusivePK();
17+
}
1218
}
1319

1420
void TOlapOptionsDescription::Serialize(NKikimrSchemeOp::TColumnTableSchema& tableSchema) const {
1521
tableSchema.MutableOptions()->SetSchemeNeedActualization(SchemeNeedActualization);
22+
if (ExternalGuaranteeExclusivePK) {
23+
tableSchema.MutableOptions()->SetExternalGuaranteeExclusivePK(ExternalGuaranteeExclusivePK);
24+
}
1625
}
1726

1827
bool TOlapOptionsDescription::Validate(const NKikimrSchemeOp::TColumnTableSchema& /*opSchema*/, IErrorCollector& /*errors*/) const {

ydb/core/tx/schemeshard/olap/options/schema.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class TOlapSchema;
88
class TOlapOptionsDescription {
99
private:
1010
YDB_READONLY(bool, SchemeNeedActualization, false);
11+
YDB_READONLY(bool, ExternalGuaranteeExclusivePK, false);
1112
public:
1213
bool ApplyUpdate(const TOlapOptionsUpdate& schemaUpdate, IErrorCollector& errors);
1314

ydb/core/tx/schemeshard/olap/options/update.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,21 @@ namespace NKikimr::NSchemeShard {
1010
class TOlapOptionsUpdate {
1111
private:
1212
YDB_ACCESSOR(bool, SchemeNeedActualization, false);
13+
YDB_ACCESSOR_DEF(std::optional<bool>, ExternalGuaranteeExclusivePK);
1314
public:
1415
bool Parse(const NKikimrSchemeOp::TAlterColumnTableSchema& alterRequest, IErrorCollector& /*errors*/) {
1516
SchemeNeedActualization = alterRequest.GetOptions().GetSchemeNeedActualization();
17+
if (alterRequest.GetOptions().HasExternalGuaranteeExclusivePK()) {
18+
ExternalGuaranteeExclusivePK = alterRequest.GetOptions().GetExternalGuaranteeExclusivePK();
19+
}
1620
return true;
1721
}
1822
void SerializeToProto(NKikimrSchemeOp::TAlterColumnTableSchema& alterRequest) const {
1923
alterRequest.MutableOptions()->SetSchemeNeedActualization(SchemeNeedActualization);
24+
if (ExternalGuaranteeExclusivePK) {
25+
alterRequest.MutableOptions()->SetExternalGuaranteeExclusivePK(*ExternalGuaranteeExclusivePK);
26+
}
27+
2028
}
2129
};
2230
}

0 commit comments

Comments
 (0)