Skip to content

Commit 8d7ee18

Browse files
committed
feat(kqp): add UseSequentialReads pragma
1 parent 55a88ca commit 8d7ee18

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
@@ -4235,7 +4235,46 @@ Y_UNIT_TEST_SUITE(KqpNewEngine) {
42354235
}
42364236
}
42374237

4238+
Y_UNIT_TEST_TWIN(SequentialReadsPragma, Enabled) {
4239+
TKikimrRunner kikimr;
4240+
auto db = kikimr.GetTableClient();
4241+
auto session = db.CreateSession().GetValueSync().GetSession();
4242+
4243+
NYdb::NTable::TExecDataQuerySettings querySettings;
4244+
querySettings.CollectQueryStats(ECollectQueryStatsMode::Profile);
4245+
4246+
TString query = R"(
4247+
SELECT Key, Data FROM `/Root/EightShard`
4248+
WHERE Text = "Value1"
4249+
ORDER BY Key
4250+
LIMIT 1;
4251+
)";
4252+
4253+
if (Enabled) {
4254+
TString pragma = TString(R"(
4255+
PRAGMA ydb.MaxSequentialReadsInFlight = "1";
4256+
)");
42384257

4258+
query = pragma + query;
4259+
}
4260+
4261+
auto result = session.ExecuteDataQuery(query, TTxControl::BeginTx().CommitTx(), querySettings).GetValueSync();
4262+
UNIT_ASSERT_C(result.IsSuccess(), result.GetIssues().ToString());
4263+
CompareYson(R"([[[101u];[1]]])", FormatResultSetYson(result.GetResultSet(0)));
4264+
4265+
auto stats = NYdb::TProtoAccessor::GetProto(*result.GetStats());
4266+
for (const auto& phase : stats.query_phases()) {
4267+
for (const auto& access : phase.table_access()) {
4268+
if (access.name() == "/Root/EightShard") {
4269+
if (Enabled) {
4270+
UNIT_ASSERT_LT(access.partitions_count(), 8);
4271+
} else {
4272+
UNIT_ASSERT_EQUAL(access.partitions_count(), 8);
4273+
}
4274+
}
4275+
}
4276+
}
4277+
}
42394278

42404279
}
42414280

0 commit comments

Comments
 (0)