ANY() equi-join condition
View as Markdown
Overview
The “field = ANY(...)” equality condition returns true if the equality
comparison is true for any of the values in the ANY() expression.
For equi-join whose ON expression includes an ANY operator
expression,
Materialize provides an idiomatic SQL as an alternative to the ANY()
expression.
Materialize and equi-join ON fieldX = ANY(<array|list|map>)
When evaluating an equi-join whose ON expression includes the ANY operator
expression
(i.e., ON fieldX = ANY(<array|list|map>)), Materialize performs a cross join,
which can lead to a significant increase in memory usage. If possible, rewrite
the query to perform an equi-join on the unnested values.
Idiomatic Materialize SQL
Idiomatic Materialize SQL: For equi-join whose ON expression includes
the ANY operator expression (ON fieldX = ANY(<array|list|map>)), use UNNEST() in a
Common Table Expression (CTE) to
unnest the values and perform the equi-join on the unnested values. If the
array/list/map contains duplicates, include DISTINCT to remove duplicates.
|
If no duplicates exist in the unnested field: Use a Common Table
Expression (CTE) to Duplicates may exist in the unnested field: Use a Common Table
Expression (CTE) to |
|
|
|
Examples
Find orders with any sales items
Using idiomatic Materialize SQL, the following example finds orders that contain
any of the sales items for the week of the order. That is, the example uses a
CTE to UNNEST() (or
DISTINCTUNNEST())
the items field from the sales_items table, and then performs an equi-join
with the orders table on the unnested values.
|
If no duplicates in the unnested field To omit duplicates that may exist in the unnested field |
|
|
|