Caideyipi commented on code in PR #19346:
URL: https://github.com/apache/iotdb/pull/19346#discussion_r4640864501
##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/subscription/columnfilter/ColumnFilterParser.java:
##########
@@ -208,11 +208,26 @@ public Expression visitLogicalNot(
@Override
public Expression visitLogicalBinary(
final SubscriptionColumnFilterParser.LogicalBinaryContext context) {
- final Expression left = visit(context.booleanExpression(0));
- final Expression right = visit(context.booleanExpression(1));
- return Objects.nonNull(context.AND())
- ? LogicalExpression.and(left, right)
- : LogicalExpression.or(left, right);
+ final LogicalExpression.Operator operator =
+ Objects.nonNull(context.AND())
+ ? LogicalExpression.Operator.AND
+ : LogicalExpression.Operator.OR;
+ final List<Expression> terms = new ArrayList<>();
+ appendLogicalTerms(terms, operator, visit(context.booleanExpression(0)));
+ appendLogicalTerms(terms, operator, visit(context.booleanExpression(1)));
+ return new LogicalExpression(operator, terms);
+ }
+
+ private static void appendLogicalTerms(
+ final List<Expression> terms,
+ final LogicalExpression.Operator operator,
+ final Expression expression) {
+ if (expression instanceof LogicalExpression
+ && ((LogicalExpression) expression).getOperator() == operator) {
+ terms.addAll(((LogicalExpression) expression).getTerms());
Review Comment:
[P2] Avoid quadratic copying when flattening a chain. The grammar is
left-recursive, so for `a OR b OR ...`, each parent reaches this branch with
all prior terms in the left child. `addAll` recopies those terms for every
predicate, and `LogicalExpression` copies the new list again. Parsing a
length-N flat column filter therefore allocates O(N^2) references. The
column-filter path has no size/depth cap, so a sufficiently large valid topic
filter can cause a large CPU/heap spike while refreshing its matcher. Please
collect same-operator terms in one pass or impose a limit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]