[ https://issues.apache.org/jira/browse/FLINK-31848?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17715415#comment-17715415 ]
Shuiqiang Chen commented on FLINK-31848: ---------------------------------------- Hi [~zju_zsx] take a table MyTable(a INT, b INT) for instance, there are three rows: (1, 1), (null, 1), (3, 3) and for the query select * from MyTable where a < 2 and b < 2 the value of left.nullTerm and left.resultTerm would be: false, true // a is not null, then evaluate the reuslt of a < 2 to be true, need to evaluate right code true, false // a is null, means the result of a < 2 is UNKNOWN, no need to evaluate a < 2 but to evalute b < 2 as right.code false, false // a is not null, then evaluate the result of a < 2 to be false, no need to evaluate right code with if(!left.resultTerm), we assume null < 2 to be false, it would become: left&&right TRUE && 1 < 2 -> TRUE FALSE && skipped -> FALSE FALSE && skipped -> FALSE the final result of the and operation is: nullTerm resultTerm false false false false false true but with if(!left.nullTerm && !left.resultTerm), it should be: left&&right TRUE && 1 < 2 -> TRUE UNKNOWN && 1 < 2 -> UNKNWON FALSE && skipped -> FALSE the final result of the and operation is: nullTerm resultTerm false false true false false true Seems after the simplification, the result is not consistent. > And Operator has side effect when operands have udf > --------------------------------------------------- > > Key: FLINK-31848 > URL: https://issues.apache.org/jira/browse/FLINK-31848 > Project: Flink > Issue Type: Bug > Components: Table SQL / Planner > Affects Versions: 1.13.2 > Reporter: zju_zsx > Priority: Major > Attachments: image-2023-04-19-14-54-46-458.png > > > > {code:java} > CREATE TABLE kafka_source ( > `content` varchar, > `testid` bigint, > `extra` int > ); > CREATE TABLE console_sink ( > `content` varchar, > `testid` bigint > ) > with ( > 'connector' = 'print' > ); > insert into console_sink > select > content,testid+1 > from kafka_source where testid is not null and testid > 0 and my_udf(testid) > != 0; {code} > my_udf has a constraint that the testid should not be null, but the testid is > not null and testid > 0 does not take effect. > > Im ScalarOperatorGens.generateAnd > !image-2023-04-19-14-54-46-458.png! > if left.nullTerm is true, right code will be execute 。 > it seems that > {code:java} > if (!${left.nullTerm} && !${left.resultTerm}) {code} > can be safely replaced with > {code:java} > if (!${left.resultTerm}){code} > ? -- This message was sent by Atlassian Jira (v8.20.10#820010)