aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVitalii Gridnev <gridnevvvit@gmail.com>2024-11-30 09:13:12 +0300
committerGitHub <noreply@github.com>2024-11-30 06:13:12 +0000
commitc8c54d4ccc29794728ddc31cea68ddb667e87d0b (patch)
tree0245d3a108ef3eceb4e77dbfcc8970b4df7fd159
parentbe007951ea7a65f582fa68c85ee02017a6fb2e22 (diff)
downloadydb-c8c54d4ccc29794728ddc31cea68ddb667e87d0b.tar.gz
add test with build in progress index & chooser (#12148)
-rw-r--r--ydb/core/kqp/ut/scheme/kqp_constraints_ut.cpp112
1 files changed, 112 insertions, 0 deletions
diff --git a/ydb/core/kqp/ut/scheme/kqp_constraints_ut.cpp b/ydb/core/kqp/ut/scheme/kqp_constraints_ut.cpp
index 1a9a9b46f9..92d6ea0c18 100644
--- a/ydb/core/kqp/ut/scheme/kqp_constraints_ut.cpp
+++ b/ydb/core/kqp/ut/scheme/kqp_constraints_ut.cpp
@@ -850,6 +850,118 @@ Y_UNIT_TEST_SUITE(KqpConstraints) {
}
+ Y_UNIT_TEST(IndexAutoChooseAndNonReadyIndex) {
+ NKikimrConfig::TAppConfig appConfig;
+ appConfig.MutableTableServiceConfig()->SetIndexAutoChooseMode(NKikimrConfig::TTableServiceConfig_EIndexAutoChooseMode_MAX_USED_PREFIX);
+ TKikimrRunner kikimr(TKikimrSettings().SetUseRealThreads(false).SetPQConfig(DefaultPQConfig()).SetAppConfig(appConfig));
+ auto db = kikimr.RunCall([&] { return kikimr.GetTableClient(); } );
+ auto session = kikimr.RunCall([&] { return db.CreateSession().GetValueSync().GetSession(); } );
+ auto querySession = kikimr.RunCall([&] { return db.CreateSession().GetValueSync().GetSession(); } );
+
+ auto& runtime = *kikimr.GetTestServer().GetRuntime();
+
+ {
+ auto query = R"(
+ --!syntax_v1
+ CREATE TABLE `/Root/IndexChooseAndNonReadyIndex` (
+ Key Uint32 NOT NULL,
+ Value String NOT NULL,
+ PRIMARY KEY (Key)
+ );
+ )";
+
+ auto result = kikimr.RunCall([&]{ return session.ExecuteSchemeQuery(query).GetValueSync(); });
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS,
+ result.GetIssues().ToString());
+ }
+
+ auto fQuery = [&](TString query) -> TString {
+ NYdb::NTable::TExecDataQuerySettings execSettings;
+ execSettings.KeepInQueryCache(true);
+ execSettings.CollectQueryStats(ECollectQueryStatsMode::Basic);
+
+ auto result = kikimr.RunCall([&] {
+ return querySession
+ .ExecuteDataQuery(query, TTxControl::BeginTx().CommitTx(),
+ execSettings)
+ .ExtractValueSync(); } );
+
+ if (result.GetStatus() == EStatus::SUCCESS) {
+ UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS,
+ result.GetIssues().ToString());
+ if (result.GetResultSets().size() > 0)
+ return NYdb::FormatResultSetYson(result.GetResultSet(0));
+ return "";
+ } else {
+ return TStringBuilder() << result.GetStatus() << ": " << result.GetIssues().ToString();
+ }
+ };
+
+ fQuery(R"(
+ UPSERT INTO `/Root/IndexChooseAndNonReadyIndex` (Key, Value) VALUES (1, "Old");
+ )");
+
+ auto fCompareTable = [&](TString expected) {
+ TString query = R"(
+ SELECT * FROM `/Root/IndexChooseAndNonReadyIndex` WHERE Value = "Old";
+ )";
+ CompareYson(expected, fQuery(query));
+ };
+
+ fCompareTable(R"(
+ [
+ [1u;"Old"]
+ ]
+ )");
+
+ auto alterQuery = R"(
+ --!syntax_v1
+ ALTER TABLE `/Root/IndexChooseAndNonReadyIndex` ADD INDEX Index GLOBAL ON (Value);
+ )";
+
+ bool enabledCapture = true;
+ TVector<TAutoPtr<IEventHandle>> delayedUpsertRows;
+ auto grab = [&delayedUpsertRows, &enabledCapture](TAutoPtr<IEventHandle>& ev) -> auto {
+ if (enabledCapture && ev->GetTypeRewrite() == NKikimr::TEvDataShard::TEvUploadRowsRequest::EventType) {
+ delayedUpsertRows.emplace_back(ev.Release());
+ return TTestActorRuntime::EEventAction::DROP;
+ }
+
+ return TTestActorRuntime::EEventAction::PROCESS;
+ };
+
+ TDispatchOptions opts;
+ opts.FinalEvents.emplace_back([&delayedUpsertRows](IEventHandle&) {
+ return delayedUpsertRows.size() > 0;
+ });
+
+ runtime.SetObserverFunc(grab);
+
+ auto alterFuture = kikimr.RunInThreadPool([&] { return session.ExecuteSchemeQuery(alterQuery).GetValueSync(); });
+
+ runtime.DispatchEvents(opts);
+ Y_VERIFY_S(delayedUpsertRows.size() > 0, "no upload rows requests");
+
+ fCompareTable(R"(
+ [
+ [1u;"Old"]
+ ]
+ )");
+
+ enabledCapture = false;
+ for (const auto& ev: delayedUpsertRows) {
+ runtime.Send(ev);
+ }
+
+ auto result = runtime.WaitFuture(alterFuture);
+ fCompareTable(R"(
+ [
+ [1u;"Old"]
+ ]
+ )");
+
+ }
+
Y_UNIT_TEST(AddNonColumnDoesnotReturnInternalError) {
NKikimrConfig::TAppConfig appConfig;