Skip to content

Commit 2cd297a

Browse files
authored
Merge pull request #4432 from ClickHouse/tpch-no-decorrelated
2 parents 85bbe9c + 744d571 commit 2cd297a

File tree

1 file changed

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

1 file changed

+12
-138
lines changed

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

Lines changed: 12 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,18 @@ INSERT INTO lineitem SELECT * FROM s3('https://clickhouse-datasets.s3.amazonaws.
197197
Setting [`join_use_nulls`](../../operations/settings/settings.md#join_use_nulls) should be enabled to produce correct results according to SQL standard.
198198
:::
199199

200-
The queries are generated by `./qgen -s <scaling_factor>`. Example queries for `s = 100`:
200+
:::note
201+
Some TPC-H queries query use correlated subqueries which are available since v25.8.
202+
Please use at least this ClickHouse version to run the queries.
203+
204+
In ClickHouse versions 25.5, 25.6, 25.7, it is necessary to set additionally:
205+
206+
```sql
207+
SET allow_experimental_correlated_subqueries = 1;
208+
```
209+
:::
210+
211+
The queries are generated by `./qgen -s <scaling_factor>`. Example queries for `s = 100` below:
201212

202213
**Correctness**
203214

@@ -278,63 +289,6 @@ ORDER BY
278289
p_partkey;
279290
```
280291

281-
::::note
282-
Until v25.5, the query did not work out-of-the box because scalar correlated subqueries were unsupported.
283-
Until v25.8, the query requires enabling the `allow_experimental_correlated_subqueries` setting.
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-
338292
**Q3**
339293

340294
```sql
@@ -388,40 +342,6 @@ ORDER BY
388342
o_orderpriority;
389343
```
390344

391-
::::note
392-
Until v25.4, the query did not work out-of-the box because correlated subqueries were unsupported.
393-
Until v25.8, the query requires enabling allow_experimental_correlated_subqueries setting.
394-
395-
This alternative formulation works and was verified to return the reference results.
396-
397-
```sql
398-
WITH ValidLineItems AS (
399-
SELECT
400-
l_orderkey
401-
FROM
402-
lineitem
403-
WHERE
404-
l_commitdate < l_receiptdate
405-
GROUP BY
406-
l_orderkey
407-
)
408-
SELECT
409-
o.o_orderpriority,
410-
COUNT(*) AS order_count
411-
FROM
412-
orders o
413-
JOIN
414-
ValidLineItems vli ON o.o_orderkey = vli.l_orderkey
415-
WHERE
416-
o.o_orderdate >= DATE '1993-07-01'
417-
AND o.o_orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH
418-
GROUP BY
419-
o.o_orderpriority
420-
ORDER BY
421-
o.o_orderpriority;
422-
```
423-
::::
424-
425345
**Q5**
426346

427347
```sql
@@ -843,38 +763,6 @@ WHERE
843763
);
844764
```
845765

846-
::::note
847-
Until v25.5, the query did not work out-of-the box because scalar correlated subqueries were unsupported.
848-
Until v25.8, the query requires enabling allow_experimental_correlated_subqueries setting.
849-
850-
This alternative formulation works and was verified to return the reference results.
851-
852-
```sql
853-
WITH AvgQuantity AS (
854-
SELECT
855-
l_partkey,
856-
AVG(l_quantity) * 0.2 AS avg_quantity
857-
FROM
858-
lineitem
859-
GROUP BY
860-
l_partkey
861-
)
862-
SELECT
863-
SUM(l.l_extendedprice) / 7.0 AS avg_yearly
864-
FROM
865-
lineitem l
866-
JOIN
867-
part p ON p.p_partkey = l.l_partkey
868-
JOIN
869-
AvgQuantity aq ON l.l_partkey = aq.l_partkey
870-
WHERE
871-
p.p_brand = 'Brand#23'
872-
AND p.p_container = 'MED BOX'
873-
AND l.l_quantity < aq.avg_quantity;
874-
875-
```
876-
::::
877-
878766
**Q18**
879767

880768
```sql
@@ -995,11 +883,6 @@ ORDER BY
995883
s_name;
996884
```
997885

998-
::::note
999-
Until v25.5, the query did not work out-of-the box because scalar correlated subqueries were unsupported.
1000-
Until v25.8, the query requires enabling allow_experimental_correlated_subqueries setting.
1001-
::::
1002-
1003886
**Q21**
1004887

1005888
```sql
@@ -1043,10 +926,6 @@ ORDER BY
1043926
numwait DESC,
1044927
s_name;
1045928
```
1046-
::::note
1047-
Until v25.4, the query did not work out-of-the box because correlated subqueries were unsupported.
1048-
Until v25.8, the query requires enabling allow_experimental_correlated_subqueries setting.
1049-
::::
1050929

1051930
**Q22**
1052931

@@ -1088,8 +967,3 @@ GROUP BY
1088967
ORDER BY
1089968
cntrycode;
1090969
```
1091-
1092-
::::note
1093-
Until v25.4, the query did not work out-of-the box because correlated subqueries were unsupported.
1094-
Until v25.8, the query requires enabling allow_experimental_correlated_subqueries setting.
1095-
::::

0 commit comments

Comments
 (0)