Skip to content

Commit d2dc022

Browse files
authored
Merge 414afca into ea324a3
2 parents ea324a3 + 414afca commit d2dc022

File tree

2 files changed

+178
-22
lines changed

2 files changed

+178
-22
lines changed
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
pragma TablePathPrefix = "/Root/test/ds/";
2+
3+
-- NB: Subquerys
4+
5+
$blabla = (
6+
7+
select substring(cast(item.i_item_desc as string),0,30) itemdesc,item.i_item_sk item_sk,date_dim.d_date solddate
8+
9+
from store_sales as store_sales
10+
11+
cross join date_dim as date_dim
12+
13+
cross join item as item
14+
15+
where ss_sold_date_sk = d_date_sk
16+
17+
and ss_item_sk = i_item_sk
18+
19+
and d_year in (2000,2000+1,2000+2,2000+3)
20+
21+
);
22+
23+
$frequent_ss_items =
24+
25+
(select itemdesc, item_sk, solddate,count(*) cnt
26+
27+
from $blabla
28+
29+
group by itemdesc,item_sk,solddate
30+
31+
having count(*) >4);
32+
33+
34+
35+
$max_store_sales =
36+
37+
(select max(csales) tpcds_cmax
38+
39+
from (select customer.c_customer_sk c_customer_sk,sum(ss_quantity*ss_sales_price) csales
40+
41+
from store_sales as store_sales
42+
43+
cross join customer as customer
44+
45+
cross join date_dim as date_dim
46+
47+
where ss_customer_sk = c_customer_sk
48+
49+
and ss_sold_date_sk = d_date_sk
50+
51+
and d_year in (2000,2000+1,2000+2,2000+3)
52+
53+
group by customer.c_customer_sk) x);
54+
55+
56+
57+
$best_ss_customer =
58+
59+
(select customer.c_customer_sk c_customer_sk,sum(ss_quantity*ss_sales_price) ssales
60+
61+
from store_sales as store_sales
62+
63+
cross join customer as customer
64+
65+
where ss_customer_sk = c_customer_sk
66+
67+
group by customer.c_customer_sk
68+
69+
having sum(ss_quantity*ss_sales_price) > (95/100.0) * $max_store_sales);
70+
71+
72+
73+
-- start query 1 in stream 0 using template query23.tpl and seed 2031708268
74+
75+
select sum(sales)
76+
77+
from (select cs_quantity*cs_list_price sales
78+
79+
from catalog_sales as catalog_sales
80+
81+
cross join date_dim as date_dim
82+
83+
where d_year = 2000
84+
85+
and d_moy = 3
86+
87+
and cs_sold_date_sk = d_date_sk
88+
89+
and cs_item_sk in (select item_sk from $frequent_ss_items)
90+
91+
and cs_bill_customer_sk in (select c_customer_sk from $best_ss_customer)
92+
93+
union all
94+
95+
select ws_quantity*ws_list_price sales
96+
97+
from web_sales as web_sales
98+
99+
cross join date_dim as date_dim
100+
101+
where d_year = 2000
102+
103+
and d_moy = 3
104+
105+
and ws_sold_date_sk = d_date_sk
106+
107+
and ws_item_sk in (select item_sk from $frequent_ss_items)
108+
109+
and ws_bill_customer_sk in (select c_customer_sk from $best_ss_customer)) y
110+
111+
limit 100;
112+
113+
114+
115+
select c_last_name,c_first_name,sales
116+
117+
from (select customer.c_last_name c_last_name,customer.c_first_name c_first_name,sum(cs_quantity*cs_list_price) sales
118+
119+
from catalog_sales as catalog_sales
120+
121+
cross join customer as customer
122+
123+
cross join date_dim as date_dim
124+
125+
where d_year = 2000
126+
127+
and d_moy = 3
128+
129+
and cs_sold_date_sk = d_date_sk
130+
131+
and cs_item_sk in (select item_sk from $frequent_ss_items)
132+
133+
and cs_bill_customer_sk in (select c_customer_sk from $best_ss_customer)
134+
135+
and cs_bill_customer_sk = c_customer_sk
136+
137+
group by customer.c_last_name,customer.c_first_name
138+
139+
union all
140+
141+
select customer.c_last_name c_last_name,customer.c_first_name c_first_name,sum(ws_quantity*ws_list_price) sales
142+
143+
from web_sales as web_sales
144+
145+
cross join customer as customer
146+
147+
cross join date_dim as date_dim
148+
149+
where d_year = 2000
150+
151+
and d_moy = 3
152+
153+
and ws_sold_date_sk = d_date_sk
154+
155+
and ws_item_sk in (select item_sk from $frequent_ss_items)
156+
157+
and ws_bill_customer_sk in (select c_customer_sk from $best_ss_customer)
158+
159+
and ws_bill_customer_sk = c_customer_sk
160+
161+
group by customer.c_last_name,customer.c_first_name) y
162+
163+
order by c_last_name,c_first_name,sales
164+
165+
limit 100;
166+
167+
168+
169+
-- end query 1 in stream 0 using template query23.tpl

ydb/core/kqp/ut/join/kqp_join_order_ut.cpp

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ class TChainTester {
173173
size_t ChainSize;
174174
};
175175

176-
void ExplainJoinOrderTestDataQuery(const TString& queryPath, bool useStreamLookupJoin, bool useColumnStore) {
177-
auto kikimr = GetKikimrWithJoinSettings(useStreamLookupJoin);
176+
void ExplainJoinOrderTestDataQueryWithStats(const TString& queryPath, const TString& statsPath, bool useStreamLookupJoin, bool useColumnStore) {
177+
auto kikimr = GetKikimrWithJoinSettings(useStreamLookupJoin, GetStatic(statsPath));
178178
auto db = kikimr.GetTableClient();
179179
auto session = db.CreateSession().GetValueSync().GetSession();
180180

@@ -191,24 +191,6 @@ void ExplainJoinOrderTestDataQuery(const TString& queryPath, bool useStreamLooku
191191
}
192192
}
193193

194-
void ExecuteJoinOrderTestDataQuery(const TString& queryPath, bool useStreamLookupJoin, bool useColumnStore) {
195-
auto kikimr = GetKikimrWithJoinSettings(useStreamLookupJoin);
196-
auto db = kikimr.GetTableClient();
197-
auto session = db.CreateSession().GetValueSync().GetSession();
198-
199-
CreateSampleTable(session, useColumnStore);
200-
201-
/* join with parameters */
202-
{
203-
const TString query = GetStatic(queryPath);
204-
205-
auto result = session.ExecuteDataQuery(query, TTxControl::BeginTx().CommitTx()).ExtractValueSync();
206-
result.GetIssues().PrintTo(Cerr);
207-
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SUCCESS);
208-
PrintPlan(result.GetQueryPlan());
209-
}
210-
}
211-
212194
void TestOlapEstimationRowsCorrectness(const TString& queryPath, const TString& statsPath) {
213195
auto kikimr = GetKikimrWithJoinSettings(false, GetStatic(statsPath));
214196
auto db = kikimr.GetTableClient();
@@ -373,6 +355,13 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
373355
}
374356
}
375357

358+
/* tpcds23 has > 1 result sets */
359+
Y_UNIT_TEST_XOR_OR_BOTH_FALSE(TPCDS23, StreamLookupJoin, ColumnStore) {
360+
ExplainJoinOrderTestDataQueryWithStats(
361+
"queries/tpcds23.sql", "stats/tpcds1000s.json", StreamLookupJoin, ColumnStore
362+
);
363+
}
364+
376365
Y_UNIT_TEST_XOR_OR_BOTH_FALSE(FiveWayJoin, StreamLookupJoin, ColumnStore) {
377366
ExecuteJoinOrderTestDataQueryWithStats(
378367
"queries/five_way_join.sql", "stats/basic.json", StreamLookupJoin, ColumnStore
@@ -541,8 +530,6 @@ Y_UNIT_TEST_SUITE(KqpJoinOrder) {
541530
PrintPlan(result.GetPlan());
542531
UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::SUCCESS);
543532

544-
NYdb::NConsoleClient::TQueryPlanPrinter queryPlanPrinter(NYdb::NConsoleClient::EDataFormat::PrettyTable, true, Cout, 0);
545-
queryPlanPrinter.Print(result.GetPlan());
546533
if (useStreamLookupJoin) {
547534
return;
548535
}

0 commit comments

Comments
 (0)