Skip to content

Commit 92bb6c7

Browse files
feat(kqp): add pragma for sequential reads (#11715)
1 parent 563d9af commit 92bb6c7

File tree

4 files changed

+51
-0
lines changed

4 files changed

+51
-0
lines changed

ydb/core/kqp/opt/physical/kqp_opt_phy_source.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ TExprBase KqpRewriteReadTable(TExprBase node, TExprContext& ctx, const TKqpOptim
110110
matched->Settings = settings.BuildNode(ctx, matched->Settings.Pos());
111111
}
112112

113+
if (kqpCtx.Config->HasMaxSequentialReadsInFlight()) {
114+
settings.SequentialInFlight = *kqpCtx.Config->MaxSequentialReadsInFlight.Get();
115+
matched->Settings = settings.BuildNode(ctx, matched->Settings.Pos());
116+
}
117+
113118
TVector<TExprBase> inputs;
114119
TVector<TCoArgument> args;
115120
TNodeOnNodeOwnedMap argReplaces;

ydb/core/kqp/provider/yql_kikimr_settings.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ TKikimrConfiguration::TKikimrConfiguration() {
9595
REGISTER_SETTING(*this, MaxDPccpDPTableSize);
9696

9797
REGISTER_SETTING(*this, MaxTasksPerStage);
98+
REGISTER_SETTING(*this, MaxSequentialReadsInFlight);
9899

99100
/* Runtime */
100101
REGISTER_SETTING(*this, ScanQuery);
@@ -147,6 +148,10 @@ bool TKikimrSettings::HasOptUseFinalizeByKey() const {
147148
return GetFlagValue(OptUseFinalizeByKey.Get().GetOrElse(true)) != EOptionalFlag::Disabled;
148149
}
149150

151+
bool TKikimrSettings::HasMaxSequentialReadsInFlight() const {
152+
return !MaxSequentialReadsInFlight.Get().Empty();
153+
}
154+
150155
EOptionalFlag TKikimrSettings::GetOptPredicateExtract() const {
151156
return GetOptionalFlagValue(OptEnablePredicateExtract.Get());
152157
}

ydb/core/kqp/provider/yql_kikimr_settings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct TKikimrSettings {
7272

7373

7474
NCommon::TConfSetting<ui32, false> MaxTasksPerStage;
75+
NCommon::TConfSetting<ui32, false> MaxSequentialReadsInFlight;
7576

7677
/* Runtime */
7778
NCommon::TConfSetting<bool, true> ScanQuery;
@@ -88,6 +89,7 @@ struct TKikimrSettings {
8889
bool HasOptEnableOlapPushdown() const;
8990
bool HasOptEnableOlapProvideComputeSharding() const;
9091
bool HasOptUseFinalizeByKey() const;
92+
bool HasMaxSequentialReadsInFlight() const;
9193

9294
EOptionalFlag GetOptPredicateExtract() const;
9395
EOptionalFlag GetUseLlvm() const;

ydb/core/kqp/ut/opt/kqp_ne_ut.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4322,7 +4322,46 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
43224322
}
43234323
}
43244324

4325+
Y_UNIT_TEST_TWIN(SequentialReadsPragma, Enabled) {
4326+
TKikimrRunner kikimr;
4327+
auto db = kikimr.GetTableClient();
4328+
auto session = db.CreateSession().GetValueSync().GetSession();
4329+
4330+
NYdb::NTable::TExecDataQuerySettings querySettings;
4331+
querySettings.CollectQueryStats(ECollectQueryStatsMode::Profile);
4332+
4333+
TString query = R"(
4334+
SELECT Key, Data FROM `/Root/EightShard`
4335+
WHERE Text = "Value1"
4336+
ORDER BY Key
4337+
LIMIT 1;
4338+
)";
4339+
4340+
if (Enabled) {
4341+
TString pragma = TString(R"(
4342+
PRAGMA ydb.MaxSequentialReadsInFlight = "1";
4343+
)");
43254344

4345+
query = pragma + query;
4346+
}
4347+
4348+
auto result = session.ExecuteDataQuery(query, TTxControl::BeginTx().CommitTx(), querySettings).GetValueSync();
4349+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
4350+
CompareYson(R"([[[101u];[1]]])", FormatResultSetYson(result.GetResultSet(0)));
4351+
4352+
auto stats = NYdb::TProtoAccessor::GetProto(*result.GetStats());
4353+
for (const auto& phase : stats.query_phases()) {
4354+
for (const auto& access : phase.table_access()) {
4355+
if (access.name() == "/Root/EightShard") {
4356+
if (Enabled) {
4357+
UNIT_ASSERT_LT(access.partitions_count(), 8);
4358+
} else {
4359+
UNIT_ASSERT_EQUAL(access.partitions_count(), 8);
4360+
}
4361+
}
4362+
}
4363+
}
4364+
}
43264365

43274366
}
43284367

0 commit comments

Comments
 (0)