Note for multiple arrayJoin of same array expression

This commit is contained in:
ivan-klass 2023-05-04 13:03:27 +02:00 committed by GitHub
parent df9f00e87c
commit a788d0b124
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,6 +78,22 @@ GROUP BY
│ 1 │ Bobruisk │ Firefox │ │ 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. 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. `ARRAY JOIN` allows you to convert multiple arrays with the same number of elements at a time.