StarRocks / starrocks

The world's fastest open query engine for sub-second analytics both on and off the data lakehouse. With the flexibility to support nearly any scenario, StarRocks provides best-in-class performance for multi-dimensional analytics, real-time analytics, and ad-hoc queries. A Linux Foundation project.
https://starrocks.io
Apache License 2.0
8.92k stars 1.79k forks source link

java.lang.NullPointerException in SQL Optimizer #52167

Open maver1ck opened 2 weeks ago

maver1ck commented 2 weeks ago

Hi, I'm getting NPE in real world example. Following code is minimal reproduction of this error.

Steps to reproduce the behavior (Required)

CREATE TABLE test (
 id STRING,
 col1 DECIMAL(38,9),
 col2 DECIMAL(38,9),
 col3 DECIMAL(38,9),
 col4 DECIMAL(38,9),
 col5 DECIMAL(38,9)

) DISTRIBUTED BY HASH(id) 
PROPERTIES (
    "replication_num" = "1"
);

INSERT INTO test VALUES ("1", 10000.0, NULL, 10001.0, 10013.0, 10001.0);

SELECT SUM(col5) FROM test
WHERE 10013.0 IN (col1, col2, col3, col4);

Expected behavior (Required)

Query should run successfully.

Real behavior (Required)

I'm getting SQL Error [1064] [42000]: Unknown error in DBeaver.

fe.log shows following exception:

2024-10-21 18:03:12.031Z WARN (starrocks-mysql-nio-pool-181|71159) [StmtExecutor.execute():752] execute Exception, sql /* ApplicationName=DBeaver Enterprise 24.2.0 - SQLEditor <Script-25.
sql> */ SELECT SUM(col5) FROM test.test
WHERE 10013.0 IN (col1, col2, col3, col4)
java.lang.NullPointerException: null
        at com.starrocks.sql.optimizer.rewrite.scalar.NormalizePredicateRule.getOptimizedCompoundTree(NormalizePredicateRule.java:189) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rewrite.scalar.NormalizePredicateRule.visitCompoundPredicate(NormalizePredicateRule.java:139) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rewrite.scalar.NormalizePredicateRule.visitInPredicate(NormalizePredicateRule.java:260) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rewrite.scalar.NormalizePredicateRule.visitInPredicate(NormalizePredicateRule.java:49) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.operator.scalar.InPredicateOperator.accept(InPredicateOperator.java:89) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rewrite.scalar.BaseScalarOperatorRewriteRule.apply(BaseScalarOperatorRewriteRule.java:41) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rewrite.ScalarOperatorRewriter.applyRuleBottomUp(ScalarOperatorRewriter.java:139) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rewrite.ScalarOperatorRewriter.rewriteByRule(ScalarOperatorRewriter.java:120) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.rewrite.ScalarOperatorRewriter.rewrite(ScalarOperatorRewriter.java:102) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.transformer.SqlToScalarOperatorTranslator.translate(SqlToScalarOperatorTranslator.java:192) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.transformer.QueryTransformer.filter(QueryTransformer.java:298) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.transformer.QueryTransformer.plan(QueryTransformer.java:101) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.transformer.RelationTransformer.visitSelect(RelationTransformer.java:275) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.transformer.RelationTransformer.visitSelect(RelationTransformer.java:154) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.ast.SelectRelation.accept(SelectRelation.java:232) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.ast.AstVisitor.visit(AstVisitor.java:71) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.ast.AstVisitor.visit(AstVisitor.java:67) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.transformer.RelationTransformer.transform(RelationTransformer.java:223) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.optimizer.transformer.RelationTransformer.transformWithSelectLimit(RelationTransformer.java:191) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.StatementPlanner.createQueryPlanWithReTry(StatementPlanner.java:304) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.StatementPlanner.plan(StatementPlanner.java:133) ~[starrocks-fe.jar:?]
        at com.starrocks.sql.StatementPlanner.plan(StatementPlanner.java:92) ~[starrocks-fe.jar:?]
        at com.starrocks.qe.StmtExecutor.execute(StmtExecutor.java:548) ~[starrocks-fe.jar:?]
        at com.starrocks.qe.ConnectProcessor.handleQuery(ConnectProcessor.java:353) ~[starrocks-fe.jar:?]
        at com.starrocks.qe.ConnectProcessor.dispatch(ConnectProcessor.java:548) ~[starrocks-fe.jar:?]
        at com.starrocks.qe.ConnectProcessor.processOnce(ConnectProcessor.java:882) ~[starrocks-fe.jar:?]
        at com.starrocks.mysql.nio.ReadListener.lambda$handleEvent$0(ReadListener.java:69) ~[starrocks-fe.jar:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?]
        at java.lang.Thread.run(Thread.java:829) ~[?:?]

StarRocks version (Required)

3.3.4-56bcf6f

ikishore commented 2 weeks ago

looks like issue happening with changes done in https://github.com/StarRocks/starrocks/pull/49137. Can I look in to it and submit fix?

before-Sunrise commented 2 weeks ago

looks like issue happening with changes done in #49137. Can I look in to it and submit fix?

of course. go ahead