Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query with scalar subquery having mathematical function returns 0 rows #23660

Closed
pratyakshsharma opened this issue Sep 16, 2024 · 0 comments · Fixed by #23674
Closed

Query with scalar subquery having mathematical function returns 0 rows #23660

pratyakshsharma opened this issue Sep 16, 2024 · 0 comments · Fixed by #23674
Assignees

Comments

@pratyakshsharma
Copy link
Contributor

pratyakshsharma commented Sep 16, 2024

In case when a query involves scalar subquery with mathematical function and the subquery returns no rows, the entire query returns no rows. This only happens in cases with mathematical functions present in the subquery.

Your Environment

  • Presto version used: 0.290-SNAPSHOT (latest master)
  • Storage (HDFS/S3/GCS..):
  • Data source and connector used: hive connector
  • Deployment (Cloud or On-prem): local machine
  • Pastebin link to the complete debug logs:

Expected Behavior

The scalar subquery should return null and other selected columns should return proper values.

Current Behavior

When the scalar subquery returns no rows, the entire query returns 0 rows.

Possible Solution

The query plan in such cases is introducing an empty Values Node in case simplify_plan_with_empty_input is set to true (It is true by default). If it is false, PickTableLayoutForPredicate rule removes TableScan node for the columns not in the subquery. Also an additional FilterNode with false predicate gets introduced.

Steps to Reproduce

Run the below simple query -

select
  comment,
  (
    select
      name
    from
      tpch.tiny.nation
    where
      nationkey = 1
      and regionkey = 1
      and width_bucket(nationkey, 1, 100, 10) = 2
  )
from
  tpch.tiny.nation;

Screenshots (if appropriate)

Outputs
Screenshot 2024-09-16 at 10 15 32 PM

When simplify_plan_with_empty_input is true
Screenshot 2024-09-16 at 10 10 17 PM

When simplify_plan_with_empty_input is false
Screenshot 2024-09-16 at 10 10 02 PM

Context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant