Skip to content

Commit 00268e0

Browse files
authored
Merge branch 'master' into parquet_projection_push_down
2 parents 02ef3d9 + 2f74209 commit 00268e0

File tree

3 files changed

+2520
-2285
lines changed

3 files changed

+2520
-2285
lines changed

core/src/main/java/io/questdb/griffin/SqlOptimiser.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,19 +1217,35 @@ private boolean canPushToSampleBy(final QueryModel model, ObjList<CharSequence>
12171217
private boolean checkForChildAggregates(ExpressionNode node) {
12181218
sqlNodeStack.clear();
12191219
while (node != null) {
1220-
if (node.rhs != null) {
1221-
if (node.rhs.type == FUNCTION && functionParser.getFunctionFactoryCache().isGroupBy(node.rhs.token)) {
1222-
return true;
1220+
if (node.paramCount < 3) {
1221+
if (node.rhs != null) {
1222+
if (node.rhs.type == FUNCTION && functionParser.getFunctionFactoryCache().isGroupBy(node.rhs.token)) {
1223+
return true;
1224+
}
1225+
sqlNodeStack.push(node.rhs);
12231226
}
1224-
sqlNodeStack.push(node.rhs);
1225-
}
12261227

1227-
if (node.lhs != null) {
1228-
if (node.lhs.type == FUNCTION && functionParser.getFunctionFactoryCache().isGroupBy(node.lhs.token)) {
1229-
return true;
1228+
if (node.lhs != null) {
1229+
if (node.lhs.type == FUNCTION && functionParser.getFunctionFactoryCache().isGroupBy(node.lhs.token)) {
1230+
return true;
1231+
}
1232+
node = node.lhs;
1233+
} else if (!sqlNodeStack.isEmpty()) {
1234+
node = sqlNodeStack.poll();
1235+
} else {
1236+
node = null;
12301237
}
1231-
node = node.lhs;
12321238
} else {
1239+
// for nodes with paramCount >= 3, arguments are stored in args list (e.g., CASE expressions)
1240+
for (int i = 0, k = node.paramCount; i < k; i++) {
1241+
ExpressionNode arg = node.args.getQuick(i);
1242+
if (arg != null) {
1243+
if (arg.type == FUNCTION && functionParser.getFunctionFactoryCache().isGroupBy(arg.token)) {
1244+
return true;
1245+
}
1246+
sqlNodeStack.push(arg);
1247+
}
1248+
}
12331249
if (!sqlNodeStack.isEmpty()) {
12341250
node = sqlNodeStack.poll();
12351251
} else {

0 commit comments

Comments
 (0)