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

Precedence problem with operator IS [CORE5193] #5474

Closed
firebird-automations opened this issue Apr 11, 2016 · 10 comments
Closed

Precedence problem with operator IS [CORE5193] #5474

firebird-automations opened this issue Apr 11, 2016 · 10 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @pavel-zotov

1) select (not false = true) is not unknown from rdb$database; -- <true>

2) select not false = true is not unknown from rdb$database; -- <false>

Result of first query is obvious and expected.
But result of second is equal to:

NOT (false = true is not unknown)

It seems that results should be evaluated as: (NOT false) = true is not unknown

Commits: a08f7b8 8a9c5d3

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

assignee: Adriano dos Santos Fernandes [ asfernandes ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @sim1984

That's a moot point. According to the documentation of such operator precedence
1. Concatenation
2. Arithmetic operators
3. Comparison operators
4. Logical operators

However, the documentation does not say anything about the priority of the predicate IS [NOT] {TRUE | FALSE | UNKNOWN}

I think that the predicate IS should be calculated before the operator "=". Thus second expression should be equivalent to:
NOT (FALSE = (true IS NOT UNKNOWN)) i.e.
NOT (FALSE = TRUE) -> true

It would be reflected in the documentation what the priority of predicates IS [NOT] {TRUE | FALSE | UNKNOWN}

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

summary: Operator precedence problem when use: NOT <boolean literal> - in complex boolean expression => Precedence problem with operator IS

@firebird-automations
Copy link
Collaborator Author

Modified by: @asfernandes

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

resolution: Fixed [ 1 ]

Fix Version: 4.0 Alpha 1 [ 10731 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: @pavel-zotov

On WI-T4.0.0.132:

select ((not false) is true) is unknown from rdb$database; -- false; OK, expected
select (not false is true) is unknown from rdb$database; -- false; OK, expected

But:

select not false is true is unknown from rdb$database; -- true -- WHY ??

Evaluate from left to right:

1) NOT false ==> TRUE(a),
2) TRUE(a) is TRUE ==> TRUE(b)
3) TRUE(b) is UNKNOWN ==> FALSE

Evaluate from right to left:
1) TRUE is UNKNOWN ==> FALSE(a)
2) NOT FALSE is FALSE(a) ==> should be FALSE for any way of evaluation:
2a) NOT(false is false) ==> not (true) ==> false
or
2b) (not false) IS false ==> (true) IS false ==> false.

-----

PS. Fully agree with:

> Simonov Denis:
> It would be reflected in the documentation what the priority of predicates IS [NOT] {TRUE | FALSE | UNKNOWN}

@firebird-automations
Copy link
Collaborator Author

Commented by: @sim1984

Pavel Zotov,

see precedence for operator types above

Logical operators calculated after Comparison operators
IS - comparation operator
NOT - logical operator

not false is true is unknown => not ((false is true) is unknown)

>> "I think that the predicate IS should be calculated before the operator ="
I'm not sure it's right. What about the priorities of operators said standard?

Precedence in Postgresql
http://www.postgresql.org/docs/9.0/static/sql-syntax-lexical.html#SQL-PRECEDENCE-TABLE
but
http://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#SQL-PRECEDENCE-TABLE

@firebird-automations
Copy link
Collaborator Author

Commented by: @asfernandes

> select not false is true is unknown from rdb$database; -- true -- WHY ??

Result matches PgSQL too.

For the precedence documentation, we do not have a readme for that, so I believe a doc. ticket should be created pointing what doc. is outdated.

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

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

QA Status: No test => Done successfully

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

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

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Fix Version: 3.0.1 [ 10730 ]

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