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

SINGULAR buggy when nulls present [CORE1073] #1495

Closed
firebird-automations opened this issue Dec 29, 2006 · 14 comments
Closed

SINGULAR buggy when nulls present [CORE1073] #1495

firebird-automations opened this issue Dec 29, 2006 · 14 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @paulvink

Is related to QA68

When the SINGULAR search condition evolves to NULL for certain records, the behaviour is inconsistent. Sometimes the result is plain wrong. Sometimes the result even depends on the natural ordering of records in the table.

Additionally, in versions up to 1.5.3, NOT SINGULAR may return a different result than NOT (SINGULAR). This is fixed in 2.0, although I didn't find an mention of it in the Release Notes.

Example cases:

(all use the same table, with a single nullable int field a.
the search is always "a=1")

1)
with table contents {2, null}, both SINGULAR and NOT SINGULAR return UNKNOWN.

2)
with {1, null}, SINGULAR returns True. NOT SINGULAR: False in 2.0, UNKNOWN in earlier versions.
This is inconsistent with case 1: if a null led to uncertainty there, it should do the same here.

3)
{1, null, 1} => both SINGULAR and NOT SINGULAR return UNKNOWN.
This is plain wrong: with two 1's, it ain't singular for sure.

4)
{1, 1, null} => SINGULAR: False. NOT SINGULAR: True.
This is correct, but note that this is the same set as the previous case, only with different insertion order!

Commits: 5320dae

@firebird-automations
Copy link
Collaborator Author

Commented by: @paulvink

Several solutions are possible, but I'd like to suggest that SINGULAR's behaviour be modeled along the same lines as EXISTS:

- TRUE if the search condition is met exactly once;
- FALSE in all other cases;
- NULL is never returned;
- NOT SINGULAR always returns the opposite of SINGULAR.

IOW: SINGULAR( <query> ) <=> The result set of <query> contains exactly one row.

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

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

resolution: Fixed [ 1 ]

Fix Version: 2.1 [ 10041 ]

assignee: Dmitry Yemanov [ dimitr ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @pcisar

Maybe I'm just tired today, but I can't figure out any reproducible test case for this issue. Can someone help me out? A simple SQL script would be great.

@firebird-automations
Copy link
Collaborator Author

Commented by: @paulvink

Hi Pavel, the trick I used was to test on singular, not(singular), not singular and not(not singular). Otherwise you don't know if an empty set means false or null. So:

set autoddl on;
create database "test.fdb" user "sysdba" password "masterke";
create table t (a int);

// first testcase:
insert into t values (2);
insert into t values (null);
commit;
select 1 from rdb$database where singular( select * from t where a = 1);
select 1 from rdb$database where not (singular( select * from t where a = 1));
select 1 from rdb$database where not singular( select * from t where a = 1);
select 1 from rdb$database where not (not singular( select * from t where a = 1));
// the above queries return 4 empty sets, so both SING and NOT SING were null

// second testcase:
delete from t;
insert into t values (1);
insert into t values (null);
commit;
select 1 from rdb$database where singular( select * from t where a = 1);
// returns 1, so SING was true. No need for not(singular) here.
select 1 from rdb$database where not singular( select * from t where a = 1);
select 1 from rdb$database where not (not singular( select * from t where a = 1));
// 1.5.3: two empty sets, so NOT SING was null
// 2.0: first an empty set, then 1, so NOT SING was false

// likewise for 3rd and 4th testcases.

// note that all this has already been fixed for 2.1; don't know about 2.0.1 and 1.5.4

@firebird-automations
Copy link
Collaborator Author

Commented by: @pcisar

Fix confirmed for 2.1 Alpha 1. Test added.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

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

@firebird-automations
Copy link
Collaborator Author

Commented by: @pcisar

Reopened to update ticket information.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Closed [ 6 ] => Reopened [ 4 ]

resolution: Fixed [ 1 ] =>

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Fix Version: 2.1 Alpha 1 [ 10150 ]

Fix Version: 2.1.0 [ 10041 ] =>

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

status: Reopened [ 4 ] => Closed [ 6 ]

resolution: Fixed [ 1 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Link: This issue is related to QA68 [ QA68 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pcisar

Workflow: jira [ 11444 ] => Firebird [ 15480 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

QA Status: No test

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

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

QA Status: No test => Done successfully

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

2 participants