Skip to content

Unexpected result when CREATE VIEW with WHERE NULL #7450

Closed

Description

@suyZhong

Describe the bug
Consider the test cases below. It is unexpected that the query return true, since there should be no row in VIEW with NULL as the WHERE predicate. If we remove the GROUP BY clause for the VIEW, the query returns empty result as expected.

To Reproduce

DROP TABLE t0 CASCADE;
DROP VIEW v0 CASCADE;

CREATE TABLE t0(c0 INT);
INSERT INTO t0 ( c0) VALUES (false);
CREATE VIEW v0(c0) AS SELECT true FROM t0 WHERE NULL GROUP BY t0.c0, true;

SELECT * FROM v0;
-- Expected: Empty 
-- Actual: true


-- Or consider this one: 
SELECT * FROM v0 WHERE true; -- true (if the true is expected)
SELECT * FROM v0 WHERE true UNION ALL SELECT * FROM v0 WHERE (NOT true); -- empty (unexpected)

Expected behavior
As mentioned above

Screenshots
N/A

Software versions
Build from source:

> docker exec monetdb-test mserver5 --version --dbname=monetdb
MonetDB 5 server 11.50.0 (hg id: 1a6a23b) (64-bit, 128-bit integers)
This is an unreleased version
Copyright (c) 1993 - July 2008 CWI
Copyright (c) August 2008 - 2023 MonetDB B.V., all rights reserved
Visit https://www.monetdb.org/ for further information
Found 503.5GiB available memory, 128 available cpu cores
Libraries:
Compiled by: @fdb2b8a5a74e (x86_64-pc-linux-gnu)
Compilation: /usr/bin/cc 
Linking    : /usr/bin/ld

Issue labeling
Bug

Additional context
Add any other context about the problem here.

Activity

  1. self-assigned this
    on Feb 8, 2024
  2. added
    bugSomething isn't working
    on Feb 8, 2024
  3. added this to the NEXTRELEASE milestone on Feb 9, 2024
  4. njnes commented on Feb 9, 2024

    @njnes
    Contributor

    fixed in dec2023, optimizer correctly removed all output of the groupby (no columns are used), execution plan incorrectly generated a output (allways), now the output (single values) is projected with the group result again (given the correct empty result).

  5. added a commit that references this issue on Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions