You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Nattavut Sutyanyong (JIRA)" <ji...@apache.org> on 2016/08/09 03:49:20 UTC

[jira] [Commented] (SPARK-16951) Alternative implementation of NOT IN to Anti-join

    [ https://issues.apache.org/jira/browse/SPARK-16951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15412878#comment-15412878 ] 

Nattavut Sutyanyong commented on SPARK-16951:
---------------------------------------------

The semantic of {{NOT IN}} is described in detail in "[Subqueries in Apache Spark 2.0|https://databricks-prod-cloudfront.cloud.databricks.com/public/4027ec902e239c93eaaa8714f173bcfc/2728434780191932/1483312212640900/6987336228780374/latest.html]". Concisely,

"{{x NOT IN (subquery y)}} translates into: {{x <> y1 AND x <> y2 ... AND x <> yn}}"

When {{x}} and {{subquery y}} cannot produce {{NULL}} value, {{NOT IN}} is equivalent to its {{NOT EXIST}} counterpart. That is,

{{SELECT .. FROM X WHERE X.C1 NOT IN (SELECT Y.C2 FROM Y)}}

is equivalent to

{{SELECT .. FROM X WHERE NOT EXISTS (SELECT 1 FROM Y WHERE X.C1=Y.C2)}}

however, there are 3 edge cases we need to pay attention to.

Case 1. When {{X.C1}} is {{NULL}}, the row is removed from the result set.
Case 2. When the {{subquery Y}} can produce {{NULL}} value to the output column {{Y.C2}}, the result is an empty set.
Case 3. When the {{subquery Y}} produce an empty set, SQL language defines that the subquery will return a row of {{NULL}} value, hence this is like case 2 which returns an empty set.

> Alternative implementation of NOT IN to Anti-join
> -------------------------------------------------
>
>                 Key: SPARK-16951
>                 URL: https://issues.apache.org/jira/browse/SPARK-16951
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 2.0.0
>            Reporter: Nattavut Sutyanyong
>
> A transformation currently used to process {{NOT IN}} subquery is to rewrite to a form of Anti-join with null-aware property in the Logical Plan and then translate to a form of {{OR}} predicate joining the parent side and the subquery side of the {{NOT IN}}. As a result, the presence of {{OR}} predicate is limited to the nested-loop join execution plan, which will have a major performance implication if both sides' results are large.
> This JIRA sketches an idea of changing the OR predicate to a form similar to the technique used in the implementation of the Existence join that addresses the problem of {{EXISTS (..) OR ..}} type of queries.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org