Skip to content

Commit e7e8ad0

Browse files
committed
Incorporate feedback
1 parent 0032bb2 commit e7e8ad0

File tree

1 file changed

+137
-6
lines changed
  • docs/getting-started/example-datasets

1 file changed

+137
-6
lines changed

docs/getting-started/example-datasets/tpch.md

Lines changed: 137 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ ORDER BY
234234
**Q2**
235235

236236
```sql
237-
SET allow_experimental_correlated_subqueries = 1;
237+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
238238
239239
SELECT
240240
s_acctbal,
@@ -281,6 +281,62 @@ ORDER BY
281281
p_partkey;
282282
```
283283

284+
::::note
285+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
286+
287+
This alternative formulation works and was verified to return the reference results.
288+
289+
```sql
290+
WITH MinSupplyCost AS (
291+
SELECT
292+
ps_partkey,
293+
MIN(ps_supplycost) AS min_supplycost
294+
FROM
295+
partsupp ps
296+
JOIN
297+
supplier s ON ps.ps_suppkey = s.s_suppkey
298+
JOIN
299+
nation n ON s.s_nationkey = n.n_nationkey
300+
JOIN
301+
region r ON n.n_regionkey = r.r_regionkey
302+
WHERE
303+
r.r_name = 'EUROPE'
304+
GROUP BY
305+
ps_partkey
306+
)
307+
SELECT
308+
s.s_acctbal,
309+
s.s_name,
310+
n.n_name,
311+
p.p_partkey,
312+
p.p_mfgr,
313+
s.s_address,
314+
s.s_phone,
315+
s.s_comment
316+
FROM
317+
part p
318+
JOIN
319+
partsupp ps ON p.p_partkey = ps.ps_partkey
320+
JOIN
321+
supplier s ON s.s_suppkey = ps.ps_suppkey
322+
JOIN
323+
nation n ON s.s_nationkey = n.n_nationkey
324+
JOIN
325+
region r ON n.n_regionkey = r.r_regionkey
326+
JOIN
327+
MinSupplyCost msc ON ps.ps_partkey = msc.ps_partkey AND ps.ps_supplycost = msc.min_supplycost
328+
WHERE
329+
p.p_size = 15
330+
AND p.p_type LIKE '%BRASS'
331+
AND r.r_name = 'EUROPE'
332+
ORDER BY
333+
s.s_acctbal DESC,
334+
n.n_name,
335+
s.s_name,
336+
p.p_partkey;
337+
```
338+
::::
339+
284340
**Q3**
285341

286342
```sql
@@ -311,7 +367,7 @@ ORDER BY
311367
**Q4**
312368

313369
```sql
314-
SET allow_experimental_correlated_subqueries = 1;
370+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
315371
316372
SELECT
317373
o_orderpriority,
@@ -336,6 +392,39 @@ ORDER BY
336392
o_orderpriority;
337393
```
338394

395+
::::note
396+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
397+
398+
This alternative formulation works and was verified to return the reference results.
399+
400+
```sql
401+
WITH ValidLineItems AS (
402+
SELECT
403+
l_orderkey
404+
FROM
405+
lineitem
406+
WHERE
407+
l_commitdate < l_receiptdate
408+
GROUP BY
409+
l_orderkey
410+
)
411+
SELECT
412+
o.o_orderpriority,
413+
COUNT(*) AS order_count
414+
FROM
415+
orders o
416+
JOIN
417+
ValidLineItems vli ON o.o_orderkey = vli.l_orderkey
418+
WHERE
419+
o.o_orderdate >= DATE '1993-07-01'
420+
AND o.o_orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH
421+
GROUP BY
422+
o.o_orderpriority
423+
ORDER BY
424+
o.o_orderpriority;
425+
```
426+
::::
427+
339428
**Q5**
340429

341430
```sql
@@ -738,7 +827,7 @@ ORDER BY
738827
**Q17**
739828

740829
```sql
741-
SET allow_experimental_correlated_subqueries = 1;
830+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
742831
743832
SELECT
744833
sum(l_extendedprice) / 7.0 AS avg_yearly
@@ -759,6 +848,37 @@ WHERE
759848
);
760849
```
761850

851+
::::note
852+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
853+
854+
This alternative formulation works and was verified to return the reference results.
855+
856+
```sql
857+
WITH AvgQuantity AS (
858+
SELECT
859+
l_partkey,
860+
AVG(l_quantity) * 0.2 AS avg_quantity
861+
FROM
862+
lineitem
863+
GROUP BY
864+
l_partkey
865+
)
866+
SELECT
867+
SUM(l.l_extendedprice) / 7.0 AS avg_yearly
868+
FROM
869+
lineitem l
870+
JOIN
871+
part p ON p.p_partkey = l.l_partkey
872+
JOIN
873+
AvgQuantity aq ON l.l_partkey = aq.l_partkey
874+
WHERE
875+
p.p_brand = 'Brand#23'
876+
AND p.p_container = 'MED BOX'
877+
AND l.l_quantity < aq.avg_quantity;
878+
879+
```
880+
::::
881+
762882
**Q18**
763883

764884
```sql
@@ -840,7 +960,7 @@ WHERE
840960
**Q20**
841961

842962
```sql
843-
SET allow_experimental_correlated_subqueries = 1;
963+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
844964
845965
SELECT
846966
s_name,
@@ -881,10 +1001,14 @@ ORDER BY
8811001
s_name;
8821002
```
8831003

1004+
::::note
1005+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1006+
::::
1007+
8841008
**Q21**
8851009

8861010
```sql
887-
SET allow_experimental_correlated_subqueries = 1;
1011+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
8881012
8891013
SELECT
8901014
s_name,
@@ -926,11 +1050,14 @@ ORDER BY
9261050
numwait DESC,
9271051
s_name;
9281052
```
1053+
::::note
1054+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1055+
::::
9291056

9301057
**Q22**
9311058

9321059
```sql
933-
SET allow_experimental_correlated_subqueries = 1;
1060+
SET allow_experimental_correlated_subqueries = 1; -- since v25.5
9341061
9351062
SELECT
9361063
cntrycode,
@@ -969,3 +1096,7 @@ GROUP BY
9691096
ORDER BY
9701097
cntrycode;
9711098
```
1099+
1100+
::::note
1101+
Until v25.5, the query did not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1102+
::::

0 commit comments

Comments
 (0)