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 result returned by INTERSECT #3581

Closed
YuanchengJiang opened this issue Jul 19, 2023 · 0 comments · Fixed by #3768
Closed

Incorrect result returned by INTERSECT #3581

YuanchengJiang opened this issue Jul 19, 2023 · 0 comments · Fixed by #3768
Assignees
Labels
Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution

Comments

@YuanchengJiang
Copy link

Describe the bug

Buggy query:

(SELECT count(1) FROM telemetry as T1 CROSS JOIN telemetry as T2 WHERE T2.created=NOW() AND T2.created='2023-04-14 19:11:51+00' ) INTERSECT (SELECT count(1) FROM telemetry as T1 JOIN telemetry as T2 on T1.created=T2.created JOIN telemetry as T3 ON T2.created=T3.created WHERE T3.created<NOW() )

The buggy query is a bit complex (I have tried to simplify it but it does not happen in simple cases):
The first half is SELECT count(1) FROM telemetry as T1 CROSS JOIN telemetry as T2 WHERE T2.created=NOW() AND T2.created='2023-04-14 19:11:51+00' where the predicate is always False, so the subquery result is 0.
The second half is SELECT count(1) FROM telemetry as T1 JOIN telemetry as T2 on T1.created=T2.created JOIN telemetry as T3 ON T2.created=T3.created WHERE T3.created<NOW() where the predicate is always True, so the subquery result is greater than 0.
The INTERSECT should return an empty result: [], however, it returns [(0,)]
Replacing the first half with (SELECT 0) or the second half with (SELCT 100) does not have this issue.

To reproduce

(SELECT count(1) FROM telemetry as T1 CROSS JOIN telemetry as T2 WHERE T2.created=NOW() AND T2.created='2023-04-14 19:11:51+00' ) INTERSECT (SELECT count(1) FROM telemetry as T1 JOIN telemetry as T2 on T1.created=T2.created JOIN telemetry as T3 ON T2.created=T3.created WHERE T3.created<NOW() )

Expected Behavior

The INTERSECT should return an empty result: [], however, it returns [(0,)]

Environment

- **QuestDB version**: v7.2.1
- **OS**: ubuntu 20.04

Additional context

No response

@puzpuzpuz puzpuzpuz added Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution labels Aug 11, 2023
@puzpuzpuz puzpuzpuz self-assigned this Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants