Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Window Functions : Improve performance by comparing Strings in frame bytes without converting them (#17091) #17311

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ public int getNumMergeBuffers()
{
return 3;
}

@Override
public int intermediateComputeSizeBytes()
{
return 200_000_000;
}
};

@Setup(Level.Trial)
Expand Down Expand Up @@ -334,7 +340,8 @@ public void tearDown() throws Exception
public void querySql(String sql, Blackhole blackhole)
{
final Map<String, Object> context = ImmutableMap.of(
QueryContexts.MAX_SUBQUERY_BYTES_KEY, "auto"
QueryContexts.MAX_SUBQUERY_BYTES_KEY, "disabled",
QueryContexts.MAX_SUBQUERY_ROWS_KEY, -1
);
try (final DruidPlanner planner = plannerFactory.createPlannerForTesting(engine, sql, context)) {
final PlannerResult plannerResult = planner.plan();
Expand Down Expand Up @@ -418,4 +425,15 @@ public void windowWithoutSorter(Blackhole blackhole)
+ "GROUP BY dimUniform, dimSequential";
querySql(sql, blackhole);
}

@Benchmark
public void windowWithGroupbyTime(Blackhole blackhole)
{
String sql = "SELECT "
+ "SUM(dimSequentialHalfNull) + SUM(dimHyperUnique), "
+ "LAG(SUM(dimSequentialHalfNull + dimHyperUnique)) OVER (PARTITION BY dimUniform ORDER BY dimSequential) "
+ "FROM foo "
+ "GROUP BY __time, dimUniform, dimSequential";
querySql(sql, blackhole);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package org.apache.druid.frame.read.columnar;

import com.google.common.primitives.Ints;
import org.apache.commons.lang.ObjectUtils;
import org.apache.datasketches.memory.Memory;
import org.apache.druid.common.config.NullHandling;
import org.apache.druid.error.DruidException;
Expand Down Expand Up @@ -507,6 +508,12 @@ protected Comparator<Object> getComparator()
return Comparator.nullsFirst(Comparator.comparing(o -> ((String) o)));
}

@Override
public int compareRows(int rowNum1, int rowNum2)
{
return ObjectUtils.compare(getStringUtf8(rowNum1), getStringUtf8(rowNum2));
}

/**
* Returns a ByteBuffer containing UTF-8 encoded string number {@code index}. The ByteBuffer is always newly
* created, so it is OK to change its position, limit, etc. However, it may point to shared memory, so it is
Expand Down
Loading