summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Cherednik <[email protected]>2023-11-17 20:57:03 +0300
committerdcherednik <[email protected]>2023-11-17 21:53:01 +0300
commit59b3011ab3bee99f38624f4600a60b3c3a2f2a8d (patch)
tree9d60cb6bb446016d30149a006f40b0929e540187
parent01606b399747b23ff3132f5c4b6a20f19a0b7ce7 (diff)
Do not lookup main table dict for each index column not present in the input.
Do not lookup main table dict for each index column not present in the input. Pull Request resolved: https://github.com/ydb-platform/ydb/pull/449
-rw-r--r--ydb/core/kqp/opt/physical/effects/kqp_opt_phy_upsert_index.cpp63
1 files changed, 41 insertions, 22 deletions
diff --git a/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_upsert_index.cpp b/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_upsert_index.cpp
index 92a8e66708f..30f7eb4ff1b 100644
--- a/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_upsert_index.cpp
+++ b/ydb/core/kqp/opt/physical/effects/kqp_opt_phy_upsert_index.cpp
@@ -219,7 +219,16 @@ TExprBase MakeUpsertIndexRows(TKqpPhyUpsertIndexMode mode, const TDqPhyPrecomput
.Build()
.Done();
- TVector<TExprBase> rowTuples;
+ // rows to be added into the index table in case if the given key hasn't been found in the main table
+ TVector<TExprBase> absentKeyRow;
+ absentKeyRow.reserve(indexColumns.size());
+
+ // rows to be updated in the index table in case if the given key has been found in the main table
+ TVector<TExprBase> presentKeyRow;
+ presentKeyRow.reserve(indexColumns.size());
+
+ auto payload = TCoArgument(ctx.NewArgument(pos, "payload"));
+
for (const auto& column : indexColumns) {
auto columnAtom = ctx.NewAtom(pos, column);
@@ -232,34 +241,44 @@ TExprBase MakeUpsertIndexRows(TKqpPhyUpsertIndexMode mode, const TDqPhyPrecomput
.Build()
.Done();
- rowTuples.emplace_back(tuple);
+ absentKeyRow.emplace_back(tuple);
+ presentKeyRow.emplace_back(tuple);
} else {
auto columnType = table.GetColumnType(TString(column));
-
- auto tuple = Build<TCoNameValueTuple>(ctx, pos)
- .Name(columnAtom)
- .Value<TCoIfPresent>()
- .Optional(lookup)
- .PresentHandler<TCoLambda>()
- .Args({"payload"})
- .Body<TCoMember>()
- .Struct("payload")
- .Name(columnAtom)
- .Build()
- .Build()
- .MissingValue<TCoNothing>()
+ absentKeyRow.emplace_back(
+ Build<TCoNameValueTuple>(ctx, pos)
+ .Name(columnAtom)
+ .Value<TCoNothing>()
.OptionalType(NCommon::BuildTypeExpr(pos, *columnType, ctx))
.Build()
- .Build()
- .Done();
-
- rowTuples.emplace_back(tuple);
+ .Done()
+ );
+ presentKeyRow.emplace_back(
+ Build<TCoNameValueTuple>(ctx, pos)
+ .Name(columnAtom)
+ .Value<TCoMember>()
+ .Struct(payload)
+ .Name(columnAtom)
+ .Build()
+ .Done()
+ );
}
}
- TExprBase flatmapBody = Build<TCoJust>(ctx, pos)
- .Input<TCoAsStruct>()
- .Add(rowTuples)
+ TExprBase flatmapBody = Build<TCoIfPresent>(ctx, pos)
+ .Optional(lookup)
+ .PresentHandler<TCoLambda>()
+ .Args(payload)
+ .Body<TCoJust>()
+ .Input<TCoAsStruct>()
+ .Add(presentKeyRow)
+ .Build()
+ .Build()
+ .Build()
+ .MissingValue<TCoJust>()
+ .Input<TCoAsStruct>()
+ .Add(absentKeyRow)
+ .Build()
.Build()
.Done();