Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions ydb/core/kqp/opt/physical/kqp_opt_phy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,6 @@ class TKqpPhysicalOptTransformer : public TOptimizeTransformerBase {
AddHandler(0, &TCoTake::Match, HNDL(PropagatePrecomuteTake<false>));
AddHandler(0, &TCoFlatMap::Match, HNDL(PropagatePrecomuteFlatmap<false>));

AddHandler(0, &TDqCnHashShuffle::Match, HNDL(BuildHashShuffleByKeyStage));

AddHandler(0, &TCoAggregateCombine::Match, HNDL(ExpandAggregatePhase));
AddHandler(0, &TCoAggregateCombineState::Match, HNDL(ExpandAggregatePhase));
AddHandler(0, &TCoAggregateMergeState::Match, HNDL(ExpandAggregatePhase));
Expand Down Expand Up @@ -253,13 +251,6 @@ class TKqpPhysicalOptTransformer : public TOptimizeTransformerBase {
return output;
}

TMaybeNode<TExprBase> BuildHashShuffleByKeyStage(TExprBase node, TExprContext& ctx) {
auto output = DqBuildHashShuffleByKeyStage(node, ctx, {});
DumpAppliedRule("BuildHashShuffleByKeyStage", node.Ptr(), output.Ptr(), ctx);
return TExprBase(output);
}


TMaybeNode<TExprBase> ExpandAggregatePhase(TExprBase node, TExprContext& ctx) {
auto output = ExpandAggregatePeepholeImpl(node.Ptr(), ctx, TypesCtx, KqpCtx.Config->HasOptUseFinalizeByKey(), false);
DumpAppliedRule("ExpandAggregatePhase", node.Ptr(), output, ctx);
Expand Down
42 changes: 42 additions & 0 deletions ydb/core/kqp/ut/join/data/queries/tpcds87.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
PRAGMA TablePathPrefix='/Root/test/ds';

-- NB: Subquerys
$bla1 = (select distinct
COALESCE(c_last_name,'') as c_last_name,
COALESCE(c_first_name,'') as c_first_name,
COALESCE(cast(d_date as date), cast(0 as Date)) as d_date
from store_sales as store_sales
cross join date_dim as date_dim
cross join customer as customer
where store_sales.ss_sold_date_sk = date_dim.d_date_sk
and store_sales.ss_customer_sk = customer.c_customer_sk
and d_month_seq between 1221 and 1221+11);

$bla2 = ((select distinct
COALESCE(c_last_name,'') as c_last_name,
COALESCE(c_first_name,'') as c_first_name,
COALESCE(cast(d_date as date), cast(0 as Date)) as d_date
from catalog_sales as catalog_sales
cross join date_dim as date_dim
cross join customer as customer
where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk
and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk
and d_month_seq between 1221 and 1221+11)
union all
(select distinct
COALESCE(c_last_name,'') as c_last_name,
COALESCE(c_first_name,'') as c_first_name,
COALESCE(cast(d_date as date), cast(0 as Date)) as d_date
from web_sales as web_sales
cross join date_dim as date_dim
cross join customer as customer
where web_sales.ws_sold_date_sk = date_dim.d_date_sk
and web_sales.ws_bill_customer_sk = customer.c_customer_sk
and d_month_seq between 1221 and 1221+11));

-- start query 1 in stream 0 using template query87.tpl and seed 1819994127
select count(*)
from $bla1 bla1 left only join $bla2 bla2 using (c_last_name, c_first_name, d_date)
;

-- end query 1 in stream 0 using template query87.tpl
25 changes: 23 additions & 2 deletions ydb/core/kqp/ut/join/kqp_join_order_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,27 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
ExplainJoinOrderTestDataQuery("queries/tpcds61.sql", StreamLookupJoin);
}

void ExecuteJoinOrderTestDataQueryWithStats(const TString& queryPath, const TString& statsPath, bool useStreamLookupJoin) {
auto kikimr = GetKikimrWithJoinSettings(useStreamLookupJoin, GetStatic(statsPath));
auto db = kikimr.GetTableClient();
auto session = db.CreateSession().GetValueSync().GetSession();

CreateSampleTable(session);

/* join with parameters */
{
const TString query = GetStatic(queryPath);

auto result = session.ExecuteDataQuery(query,TTxControl::BeginTx().CommitTx()).ExtractValueSync();

UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SUCCESS);
}
}

Y_UNIT_TEST_TWIN(TPCDS87, StreamLookupJoin) {
ExecuteJoinOrderTestDataQueryWithStats("queries/tpcds87.sql", "stats/tpcds1000s.json", StreamLookupJoin);
}

Y_UNIT_TEST_TWIN(TPCDS88, StreamLookupJoin) {
ExplainJoinOrderTestDataQuery("queries/tpcds88.sql", StreamLookupJoin);
}
Expand Down Expand Up @@ -314,13 +335,13 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
);
}

/*
/*
Y_UNIT_TEST_TWIN(OverrideStatsTPCDS64, StreamLookupJoin) {
JoinOrderTestWithOverridenStats(
"queries/tpcds64.sql", "stats/tpcds1000s.json", "join_order/tpcds64_1000s.json", StreamLookupJoin
);
}
*/
*/

Y_UNIT_TEST_TWIN(OverrideStatsTPCDS78, StreamLookupJoin) {
JoinOrderTestWithOverridenStats(
Expand Down
44 changes: 0 additions & 44 deletions ydb/library/yql/dq/opt/dq_opt_phy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,50 +1190,6 @@ TExprBase DqBuildShuffleStage(TExprBase node, TExprContext& ctx, IOptimizationCo
.Done();
}

NNodes::TExprBase DqBuildHashShuffleByKeyStage(NNodes::TExprBase node, TExprContext& ctx, const TParentsMap& /*parentsMap*/) {
if (!node.Maybe<TDqCnHashShuffle>()) {
return node;
}
auto cnHash = node.Cast<TDqCnHashShuffle>();
auto stage = cnHash.Output().Stage();
if (!stage.Program().Body().Maybe<TCoExtend>()) {
return node;
}
auto extend = stage.Program().Body().Cast<TCoExtend>();
TNodeSet nodes;
for (auto&& i : stage.Program().Args()) {
nodes.emplace(i.Raw());
}
for (auto&& i : extend) {
if (nodes.erase(i.Raw()) != 1) {
return node;
}
}
if (!nodes.empty()) {
return node;
}
TExprNode::TListType nodesTuple;
for (auto&& i : stage.Inputs()) {
if (!i.Maybe<TDqCnUnionAll>()) {
return node;
}
auto uAll = i.Cast<TDqCnUnionAll>();
nodesTuple.emplace_back(ctx.ChangeChild(node.Ref(), 0, uAll.Output().Ptr()));
}
auto stageCopy = ctx.ChangeChild(stage.Ref(), 0, ctx.NewList(node.Pos(), std::move(nodesTuple)));
auto output =
Build<TDqOutput>(ctx, node.Pos())
.Stage(stageCopy)
.Index().Build("0")
.Done();
auto outputCnMap =
Build<TDqCnMap>(ctx, node.Pos())
.Output(output)
.Done();

return TExprBase(outputCnMap);
}

TExprBase DqBuildFinalizeByKeyStage(TExprBase node, TExprContext& ctx,
const TParentsMap& parentsMap, bool allowStageMultiUsage)
{
Expand Down
1 change: 0 additions & 1 deletion ydb/library/yql/dq/opt/dq_opt_phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ NNodes::TExprBase DqBuildShuffleStage(NNodes::TExprBase node, TExprContext& ctx,

NNodes::TExprBase DqBuildFinalizeByKeyStage(NNodes::TExprBase node, TExprContext& ctx,
const TParentsMap& parentsMap, bool allowStageMultiUsage = true);
NNodes::TExprBase DqBuildHashShuffleByKeyStage(NNodes::TExprBase node, TExprContext& ctx, const TParentsMap& parentsMap);

NNodes::TExprBase DqBuildAggregationResultStage(NNodes::TExprBase node, TExprContext& ctx,
IOptimizationContext& optCtx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
"PlanNodeId": 8,
"Plans": [
{
"Node Type": "Map",
"KeyColumns": [
"SearchPhrase"
],
"Node Type": "HashShuffle",
"PlanNodeId": 7,
"PlanNodeType": "Connection",
"Plans": [
Expand All @@ -73,10 +76,7 @@
"PlanNodeId": 6,
"Plans": [
{
"KeyColumns": [
"SearchPhrase"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 5,
"PlanNodeType": "Connection",
"Plans": [
Expand Down Expand Up @@ -279,10 +279,7 @@
]
},
{
"KeyColumns": [
"SearchPhrase"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 3,
"PlanNodeType": "Connection",
"Plans": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
"PlanNodeId": 8,
"Plans": [
{
"Node Type": "Map",
"KeyColumns": [
"RegionID"
],
"Node Type": "HashShuffle",
"PlanNodeId": 7,
"PlanNodeType": "Connection",
"Plans": [
Expand All @@ -73,10 +76,7 @@
"PlanNodeId": 6,
"Plans": [
{
"KeyColumns": [
"RegionID"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 5,
"PlanNodeType": "Connection",
"Plans": [
Expand Down Expand Up @@ -136,10 +136,7 @@
]
},
{
"KeyColumns": [
"RegionID"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 3,
"PlanNodeType": "Connection",
"Plans": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
"PlanNodeId": 8,
"Plans": [
{
"Node Type": "Map",
"KeyColumns": [
"SearchPhrase"
],
"Node Type": "HashShuffle",
"PlanNodeId": 7,
"PlanNodeType": "Connection",
"Plans": [
Expand All @@ -73,10 +76,7 @@
"PlanNodeId": 6,
"Plans": [
{
"KeyColumns": [
"SearchPhrase"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 5,
"PlanNodeType": "Connection",
"Plans": [
Expand Down Expand Up @@ -122,10 +122,7 @@
]
},
{
"KeyColumns": [
"SearchPhrase"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 3,
"PlanNodeType": "Connection",
"Plans": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
"PlanNodeId": 8,
"Plans": [
{
"Node Type": "Map",
"KeyColumns": [
"RegionID"
],
"Node Type": "HashShuffle",
"PlanNodeId": 7,
"PlanNodeType": "Connection",
"Plans": [
Expand All @@ -73,10 +76,7 @@
"PlanNodeId": 6,
"Plans": [
{
"KeyColumns": [
"RegionID"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 5,
"PlanNodeType": "Connection",
"Plans": [
Expand Down Expand Up @@ -113,10 +113,7 @@
]
},
{
"KeyColumns": [
"RegionID"
],
"Node Type": "HashShuffle",
"Node Type": "UnionAll",
"PlanNodeId": 3,
"PlanNodeType": "Connection",
"Plans": [
Expand Down