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

Unexpected result when using BETWEEN and CAST #7451

Closed
suyZhong opened this issue Jan 31, 2024 · 1 comment
Closed

Unexpected result when using BETWEEN and CAST #7451

suyZhong opened this issue Jan 31, 2024 · 1 comment
Assignees
Labels
bug Something isn't working SQL
Milestone

Comments

@suyZhong
Copy link

Describe the bug
Consider the test cases below. It is unexpected that the third query return 0 null, since the second query returns true, true, which means that the WHERE clause in the third query should be evaluated to true, true and thus return two rows in the table. Besides, if change the columns to wildcard (*), the query returns two rows as expected.

To Reproduce

DROP TABLE t0 CASCADE;
DROP TABLE t1 CASCADE;

CREATE TABLE t0(c0 VARCHAR, PRIMARY KEY(c0)); -- PK is needed
CREATE TABLE t1(c1 INTEGER, c2 VARCHAR(500));
INSERT INTO t0 ( c0) VALUES ('a');
INSERT INTO t0 (c0) VALUES (false);
INSERT INTO t1 ( c1) VALUES ( 0);

SELECT t1.c1, t1.c2 FROM t1, t0; -- 0 null, 0 null
SELECT (NOT CAST((true BETWEEN t1.c2 AND t0.c0) AS VARCHAR)) FROM t1, t0; -- true, true
SELECT t1.c1, t1.c2 FROM t1, t0 WHERE (NOT CAST((true BETWEEN t1.c2 AND t0.c0) AS VARCHAR));
-- Expected: 0 null, 0 null (2 rows)
-- Actual: 0 null (1 rows)

-- This query could return expected result
SELECT * FROM t1, t0 WHERE (NOT CAST((true BETWEEN t1.c2 AND t0.c0) AS VARCHAR)); -- 2 rows

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.

@njnes njnes added the bug Something isn't working label Feb 8, 2024
@njnes njnes self-assigned this Feb 8, 2024
@njnes njnes added this to the NEXTRELEASE milestone Feb 9, 2024
@njnes
Copy link
Contributor

njnes commented Feb 9, 2024

fixed in dec2023, query got incorrectly rewritten into semijoin

@njnes njnes closed this as completed Feb 9, 2024
monetdb-team pushed a commit that referenced this issue Feb 9, 2024
make sure group by results are used
don't rewrite into semijoin when for the join expression the uniqueness cannot be concluded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working SQL
Projects
None yet
Development

No branches or pull requests

3 participants