kuzudb / kuzu

Embeddable property graph database management system built for query speed and scalability. Implements Cypher.
https://kuzudb.com/
MIT License
1.07k stars 77 forks source link

```ExpressionVisitor::isConstant``` failed to check constant ```CASE_ELSE``` expression #3386

Open manh9203 opened 2 weeks ago

manh9203 commented 2 weeks ago

In ExpressionVisitor::isContant, we are using this code to check if an expression has children or not.

if (expression.getNumChildren() == 0) {
    return expression.expressionType == ExpressionType::LITERAL;
}

It failed to check for constant CASE_ELSE expressions, e.g: CASE WHEN True THEN True ELSE False END, since CASE_ELSE is treated as leaf expression and has no children vector. I tried to rewrite this part as following

auto children = ExpressionChildrenCollector::collectChildren(expression);
if (children.empty()) {
    return expression.expressionType == ExpressionType::LITERAL;
}

but it caused segfault on recursive join queries with filter, e.g:

MATCH (a:person)-[e:knows*1..2 (r,_ | WHERE list_contains(r.comments, 'rnme'))]->(b:person) WHERE a.fName='Alice' RETURN COUNT(*)

The current work around is to check specifically for CASE_ELSE, but ultimately, using collectChildren should work properly.