From a788d0b124d9f20bc0e05e8a825920925f371460 Mon Sep 17 00:00:00 2001 From: ivan-klass Date: Thu, 4 May 2023 13:03:27 +0200 Subject: [PATCH] Note for multiple arrayJoin of same array expression --- docs/en/sql-reference/functions/array-join.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/en/sql-reference/functions/array-join.md b/docs/en/sql-reference/functions/array-join.md index 14968eb1092..98675f02f43 100644 --- a/docs/en/sql-reference/functions/array-join.md +++ b/docs/en/sql-reference/functions/array-join.md @@ -78,6 +78,22 @@ GROUP BY │ 1 │ Bobruisk │ Firefox │ └─────────────┴──────────┴─────────┘ ``` +### Important note! +Using multiple `arrayJoin` with same expression may not produce expected results due optimizations. +For that cases, consider changing array expression that is repeated with extra operations that do not affect join result - e.g. `arrayJoin(arraySort(arr))`, `arrayJoin(arrayConcat(arr, []))` + +Example: +```sql +SELECT + arrayJoin(dice) as first_throw, + /* arrayJoin(dice) as second_throw */ -- is technically correct, but will annihilate result set + arrayJoin(arrayConcat(dice, [])) as second_throw -- intentionally changed expression to force re-evaluation +FROM ( + SELECT [1, 2, 3, 4, 5, 6] as dice +); +``` + + Note the [ARRAY JOIN](../statements/select/array-join.md) syntax in the SELECT query, which provides broader possibilities. `ARRAY JOIN` allows you to convert multiple arrays with the same number of elements at a time.