Skip to content

Commit 0032bb2

Browse files
committed
TPC-H docs: Update correlated subqueries
1 parent d9ba13b commit 0032bb2

File tree

1 file changed

+12
-131
lines changed
  • docs/getting-started/example-datasets

1 file changed

+12
-131
lines changed

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

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

236236
```sql
237+
SET allow_experimental_correlated_subqueries = 1;
238+
237239
SELECT
238240
s_acctbal,
239241
s_name,
@@ -279,62 +281,6 @@ ORDER BY
279281
p_partkey;
280282
```
281283

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

340286
```sql
@@ -365,6 +311,8 @@ ORDER BY
365311
**Q4**
366312

367313
```sql
314+
SET allow_experimental_correlated_subqueries = 1;
315+
368316
SELECT
369317
o_orderpriority,
370318
count(*) AS order_count
@@ -388,39 +336,6 @@ ORDER BY
388336
o_orderpriority;
389337
```
390338

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

426341
```sql
@@ -823,6 +738,8 @@ ORDER BY
823738
**Q17**
824739

825740
```sql
741+
SET allow_experimental_correlated_subqueries = 1;
742+
826743
SELECT
827744
sum(l_extendedprice) / 7.0 AS avg_yearly
828745
FROM
@@ -842,37 +759,6 @@ WHERE
842759
);
843760
```
844761

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

878764
```sql
@@ -954,6 +840,8 @@ WHERE
954840
**Q20**
955841

956842
```sql
843+
SET allow_experimental_correlated_subqueries = 1;
844+
957845
SELECT
958846
s_name,
959847
s_address
@@ -993,13 +881,11 @@ ORDER BY
993881
s_name;
994882
```
995883

996-
::::note
997-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
998-
::::
999-
1000884
**Q21**
1001885

1002886
```sql
887+
SET allow_experimental_correlated_subqueries = 1;
888+
1003889
SELECT
1004890
s_name,
1005891
count(*) AS numwait
@@ -1040,13 +926,12 @@ ORDER BY
1040926
numwait DESC,
1041927
s_name;
1042928
```
1043-
::::note
1044-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1045-
::::
1046929

1047930
**Q22**
1048931

1049932
```sql
933+
SET allow_experimental_correlated_subqueries = 1;
934+
1050935
SELECT
1051936
cntrycode,
1052937
count(*) AS numcust,
@@ -1084,7 +969,3 @@ GROUP BY
1084969
ORDER BY
1085970
cntrycode;
1086971
```
1087-
1088-
::::note
1089-
As of February 2025, the query does not work out-of-the box due to correlated subqueries. Corresponding issue: https://github.com/ClickHouse/ClickHouse/issues/6697
1090-
::::

0 commit comments

Comments
 (0)