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

Incorrect LEFT JOIN when FROM clause contains nested subqueries #3981

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Closed

Incorrect LEFT JOIN when FROM clause contains nested subqueries #3981

monetdb-team opened this issue Nov 30, 2020 · 0 comments

Comments

@monetdb-team
Copy link

@monetdb-team monetdb-team commented Nov 30, 2020

Date: 2016-04-14 14:58:44 +0200
From: Martin van Dinther <<martin.van.dinther>>
To: SQL devs <>
Version: 11.21.19 (Jul2015-SP4)
CC: @njnes

Last updated: 2016-06-23 10:24:20 +0200

Comment 22040

Date: 2016-04-14 14:58:44 +0200
From: Martin van Dinther <<martin.van.dinther>>

User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0
Build Identifier:

In a LEFT JOIN not all rows of the lhs of the join are included in the output

Reproducible: Always

Steps to Reproduce:

  1. start mserver5
  2. start mclient
  3. issue SQL qery:
    SELECT *
    FROM (
    SELECT 'apple' as fruit
    UNION ALL SELECT 'banana'
    ) a
    JOIN (
    SELECT 'apple' as fruit
    UNION ALL SELECT 'banana'
    ) b ON a.fruit=b.fruit
    LEFT JOIN (
    SELECT 1 as isyellow
    ) c ON b.fruit='banana';

should return two rows instead of one.

Actual Results:

Welcome to mclient, the MonetDB/SQL interactive terminal (unreleased)
Database: MonetDB v11.23.0 (unreleased), 'demo'
Type \q to quit, ? for a list of available commands
auto commit mode: on
sql>SELECT *
more>FROM (
more> SELECT 'apple' as fruit
more> UNION ALL SELECT 'banana'
more>) a
more>JOIN (
more> SELECT 'apple' as fruit
more> UNION ALL SELECT 'banana'
more>) b ON a.fruit=b.fruit
more>LEFT JOIN (
more> SELECT 1 as isyellow
more>) c ON b.fruit='banana';
+--------+--------+----------+
| fruit | fruit | isyellow |
+========+========+==========+
| banana | banana | 1 |
+--------+--------+----------+
1 tuple (4.786ms)
sql>
sql>SELECT *
more>FROM (
more> SELECT 'apple' as fruit
more> UNION ALL SELECT 'banana'
more>) a
more>JOIN (
more> SELECT 'apple' as fruit
more> UNION ALL SELECT 'banana'
more>) b ON a.fruit=b.fruit;
+--------+--------+
| fruit | fruit |
+========+========+
| apple | apple |
| banana | banana |
+--------+--------+
2 tuples (3.457ms)
sql>
sql>SELECT *
more>FROM (
more> SELECT 'apple' as fruit
more> UNION ALL SELECT 'banana'
more>) a
more>LEFT JOIN (
more> SELECT 1 as isyellow
more>) c ON a.fruit='banana';
+--------+----------+
| fruit | isyellow |
+========+==========+
| banana | 1 |
| apple | null |
+--------+----------+
2 tuples (3.467ms)
sql>

Expected Results:

Two (instead of one) rows:
+--------+----------+
| fruit | isyellow |
+========+==========+
| banana | 1 |
| apple | null |
+--------+----------+

Copied issue from https://www.sqlite.org/src/info/c2a19d81652f40568c

Comment 22045

Date: 2016-04-16 10:08:17 +0200
From: MonetDB Mercurial Repository <>

Changeset 0481a6a7831d made by Niels Nes niels@cwi.nl in the MonetDB repo, refers to this bug.

For complete details, see http//devmonetdborg/hg/MonetDB?cmd=changeset;node=0481a6a7831d

Changeset description:

fixed bug #3981, ie only rewrite joins with constants into selects (ie not outerjoins). Added a test for Bug #3981.

Comment 22046

Date: 2016-04-16 10:18:27 +0200
From: @njnes

Fixed relational optimizer, which incorrectly rewrote the left join with constant into a select.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant