Skip to content

CompilationException on count(*) in co-related join since Trino 378 #24012

Open
@takezoe

Description

@takezoe

SQL:

-- Table c1000 has 1000 columns
-- Table c10 has 10 columns
SELECT * FROM c1000 t1 WHERE (SELECT COUNT(*) FROM c10 t2 WHERE t1.col0 = t2.col0) > 2;

Stacktrace:

com.google.common.util.concurrent.UncheckedExecutionException: io.airlift.bytecode.CompilationException: Error compiling class: io/trino/$gen/PagesHashStrategy_20241103_105832_49
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2085)
	at com.google.common.cache.LocalCache.get(LocalCache.java:4017)
	at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:4040)
	at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4989)
	at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4996)
	at com.google.common.cache.ForwardingLoadingCache.getUnchecked(ForwardingLoadingCache.java:54)
	at io.trino.sql.gen.JoinCompiler.compilePagesHashStrategyFactory(JoinCompiler.java:170)
	at io.trino.operator.StreamingAggregationOperator$StreamingAggregation.<init>(StreamingAggregationOperator.java:198)
	at io.trino.operator.StreamingAggregationOperator.<init>(StreamingAggregationOperator.java:147)
	at io.trino.operator.StreamingAggregationOperator$Factory.create(StreamingAggregationOperator.java:120)
	at io.trino.operator.WorkProcessorOperatorAdapter.<init>(WorkProcessorOperatorAdapter.java:108)
	at io.trino.operator.WorkProcessorOperatorAdapter$Factory.createOperator(WorkProcessorOperatorAdapter.java:64)
	at io.trino.operator.DriverFactory.createDriver(DriverFactory.java:107)
	at io.trino.execution.SqlTaskExecution$DriverSplitRunnerFactory.createDriver(SqlTaskExecution.java:667)
	at io.trino.execution.SqlTaskExecution$DriverSplitRunner.processFor(SqlTaskExecution.java:879)
	at io.trino.execution.executor.dedicated.SplitProcessor.run(SplitProcessor.java:77)
	at io.trino.execution.executor.dedicated.TaskEntry$VersionEmbedderBridge.lambda$run$0(TaskEntry.java:201)
	at io.trino.$gen.Trino_dev____20241103_105232_2.run(Unknown Source)
	at io.trino.execution.executor.dedicated.TaskEntry$VersionEmbedderBridge.run(TaskEntry.java:202)
	at io.trino.execution.executor.scheduler.FairScheduler.runTask(FairScheduler.java:172)
	at io.trino.execution.executor.scheduler.FairScheduler.lambda$submit$0(FairScheduler.java:159)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:572)
	at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
	at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:76)
	at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
	at java.base/java.lang.Thread.run(Thread.java:1575)
Caused by: io.airlift.bytecode.CompilationException: Error compiling class: io/trino/$gen/PagesHashStrategy_20241103_105832_49
	at io.airlift.bytecode.ByteCodeGenerator.generateByteCode(ByteCodeGenerator.java:106)
	at io.airlift.bytecode.ClassGenerator.defineClasses(ClassGenerator.java:100)
	at io.airlift.bytecode.ClassGenerator.defineClass(ClassGenerator.java:90)
	at io.trino.util.CompilerUtils.defineClass(CompilerUtils.java:81)
	at io.trino.util.CompilerUtils.defineClass(CompilerUtils.java:75)
	at io.trino.sql.gen.JoinCompiler.internalCompileHashStrategy(JoinCompiler.java:260)
	at io.trino.sql.gen.JoinCompiler.lambda$new$1(JoinCompiler.java:121)
	at com.google.common.cache.CacheLoader$FunctionToCacheLoader.load(CacheLoader.java:169)
	at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3574)
	at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2316)
	at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2189)
	at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2079)
	... 27 more
Caused by: org.objectweb.asm.MethodTooLargeException: Method too large: io/trino/$gen/PagesHashStrategy_20241103_105832_49.rowEqualsRow (ILio/trino/spi/Page;ILio/trino/spi/Page;)Z
	at org.objectweb.asm.MethodWriter.computeMethodInfoSize(MethodWriter.java:2088)
	at org.objectweb.asm.ClassWriter.toByteArray(ClassWriter.java:506)
	at io.airlift.bytecode.ByteCodeGenerator.generateByteCode(ByteCodeGenerator.java:103)
	... 38 more

The root cause of the compilation error is too many grouping keys came from c1000 on decorelated count(*).

Image

This query had worked until Trino 377 thanks to PushAggregationThroughOuterJoin which pushes aggregation below Left Join and reduced the number of grouping keys. However, PushFilterThroughCountAggregation was added in Trino 378 (#12047). It blocks PushAggregationThroughOuterJoin when applied.

I came up with some ideas to avoid this error but not sure if they are any good.

  • Shorten auto generated byte-code for rowEqualsRow (split to multiple methods?)
  • Skip PushFilterThroughCountAggregation if grouping keys are too many which has no chance to work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions