Uploaded image for project: 'IMPALA'
  1. IMPALA
  2. IMPALA-7782

discrepancy in results with a subquery containing an agg that produces an empty set

    XMLWordPrintableJSON

Details

    Description

      A discrepancy exists between Impala and Postgres when a subquery contains an agg and results in an empty set, yet the WHERE clause looking at the subquery should produce a "True" condition.

      Example queries include:

      USE functional;
      SELECT id
      FROM alltypestiny
      WHERE -1 NOT IN (SELECT COUNT(id) FROM alltypestiny HAVING false);
      SELECT id
      FROM alltypestiny
      WHERE NULL NOT IN (SELECT COUNT(id) FROM alltypestiny HAVING false);
      SELECT id
      FROM alltypestiny
      WHERE (SELECT COUNT(id) FROM alltypestiny HAVING false) IS NULL;
      

      These queries do not produce any rows in Impala. In Postgres, the queries produce all 8 rows for the functional.alltypestiny id column.

      Thinking maybe there were Impala and Postgres differences with NOT IN behavior, I also tried this:

      USE functional;
      SELECT id
      FROM alltypestiny
      WHERE -1 NOT IN (SELECT 1 FROM alltypestiny WHERE bool_col IS NULL);
      

      This subquery also produces an empty set just like the subquery in the problematic queries at the top, but unlike those queries, this full query returns the same results in Impala and Postgres (all 8 rows for the functional.alltypestiny id column).

      For anyone interested in this bug, you can migrate data into postgres in a dev environment using

      tests/comparison/data_generator.py --use-postgresql --migrate-table-names alltypestiny --db-name functional migrate
      

      This is in 2.12 at least, so it's not a 3.1 regression.

      Attachments

        Issue Links

          Activity

            People

              tarmstrong Tim Armstrong
              mikeb Michael Brown
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: