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

select with 'not in' clause sometimer returns incorrect results [CORE1293] #1714

Closed
firebird-automations opened this issue Jun 1, 2007 · 5 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: Jure Erznoznik (velis)

Attachments:
bugdb.zip

a simple select like:
SELECT * FROM table1 WHERE table1.varcharfield = 'const' AND table1.floatfield NOT IN (SELECT table2.floatfield FROM table2)

This select will *sometimes* return zero records if table2 contains values in the floatfield that do not exist in table1.floatfield.

I cannot reproduce the problem on custom created tables, but I have prepared the database that exhibits this bug at http://www.jantar.si/bugdb.zip

It is a very small download and contains only the offending tables. The database has been packed / backed up / restored / whatever, so we're pretty sure it's not corrupt.
The actual select that does not perform is:
SELECT * FROM USERS WHERE DEPARTMENT = 'visitor' AND CODE NOT IN (SELECT CODE FROM ACTVISITORS)

Changing the select to:
SELECT * FROM USERS WHERE DEPARTMENT = 'visitor' AND CODE IN (SELECT CODE FROM ACTVISITORS)
Notice that here 'NOT' is removed. This select returns results as expected, but just the other way around so it's not the solution.

workaround1 (join-ed select):
select users.* from users
left outer join actvisitors on users.code = actvisitors.code
where upper(users.department) = 'VISITOR'
and actvisitors.code is null

workaround2 (remove the offending records first):
delete FROM ACTVISITORS where CODE NOT IN (SELECT code FROM USERS WHERE UPPER(DEPARTMENT) = 'VISITOR')
After removal the original select will return a correct result set.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Attachment: bugdb.zip [ 10400 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @dyemanov

The result is actually correct. Accordingly to the SQL specification, NOT IN (..., NULL, ...) will always evaluate to FALSE.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Won't Fix [ 2 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 12250 ] => Firebird [ 15595 ]

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

No branches or pull requests

1 participant