SQL join performance versus PPL

Hello,

When working on the issue I describe in topic PPL: how to transform array of objects into single object , I tried to use the SQL alternative instead of PPL to do a join query.

Here’s a very simple SQL query that I tried:

SELECT /*! JOIN_TIME_OUT(30) */ parent_span.tags, child_span.tags
FROM jaeger-span-2026-10-09 AS child_span
JOIN jaeger-span-2026-10-09 AS parent_span
  ON parent_span.spanID = child_span.parentSpanID
WHERE child_span.operationName = 'Check API Key'
LIMIT 10;

This is basically the equivalent of the following PPL if I’m not mistaken:

search source = jaeger-span-2026-10-10
| where match(operationName, 'Child operation')
| inner join left = childSpan right = parentSpan on parentSpan.spanID = childSpan.parentSpanID jaeger-span-2026-10-10
| fields parentSpan.tags, childSpan.tags
| head 10

Yet the behaviour/performance of the SQL query was totally different: I didn’t even get a result as the query seemed to timeout! :thinking:

All I saw in the logs of the OpenSearch process were numerous entries like:

[INFO ][o.o.s.l.q.p.p.n.p.PointInTime] [node-0] Loading next batch of response using Point In Time.

What does explain this difference? Do SQL queries need some additional tweaking?
Is the SQL engine capable of doing join queries for large amounts of documents, just like PPL seems to be able to?

Thanks!

@damiano.albani Your two examples query two different indices. Also, the WHERE condition differs between the SQL and PPL.

Did you try testing against the same data/index?

Regarding large datasets, the OpenSearch documentation states that JOIN is an expensive operation. How big is the dataset?

Hi Pablo,

Your two examples query two different indices. Also, the WHERE condition differs between the SQL and PPL.

Oh, my bad. I tested many (slightly) different changes, and I missed that difference in the message I posted.

In practice, all jaeger-span-* indices are equal for all intents and purposes, as they just contain traces for the day.
And when you mean a difference, do you refer to where match(operationName, 'Child operation') vs WHERE child_span.operationName = 'Check API Key'?

From the tests that I made, it didn’t change the effectivity of the SQL query, whether I use the one or the other.

Could it be that the difference is that the PPL plugin filters child spans first (i.e. based on operationName), whereas the SQL plugin would do this filtering after the join?
So I’m wondering if there’s a better way to write my SQL query.

Regarding large datasets, the OpenSearch documentation states that JOIN is an expensive operation. How big is the dataset?

Oh, yes, the index is big. We’re talking 50-100 millions documents!
But while SQL chokes on that amount, PPL is able results with a reasonable performance (a couple of seconds).

@damiano.albani I think the PPL performance could be related to the fact that, by default, plugins.ppl.join.subsearch_maxout is set to 50 000. SQL has no default cap and scans the entire parent side for each child block.

Could you test your PPL query with plugins.ppl.join.subsearch_maxout set to 0? This will remove the parent limit.

Hi Pablo,

Setting plugins.ppl.join.subsearch_maxout to 0 did have an effect on the how OpenSearch behaved when running the PPL query.
A pretty bold effect actually: OpenSearch didn’t succeed in returning a response anymore.
Here’s what I see in the logs:

[2026-10-20T21:40:49,999][INFO ][o.o.c.s.ClusterSettings  ] [node-0] updating [plugins.ppl.join.subsearch_maxout] from [50000] to [0]
[2026-10-20T21:40:53,916][INFO ][o.o.s.p.PPLService       ] [node-0] [5a2ca53b-d22f-4488-b240-7979655893df] Incoming request [ source=table | where match(identifier,***) ] as identifier | inner join max=*** left = identifier right = identifier on identifier = identifier table as identifier | eval identifier=identifier identifier=mvappend(identifier,identifier) | expand identifier | eval identifier=cast(identifier as string) identifier=cast(identifier as string) | where identifier in (***) | eval identifier=replace(json_object(replace(identifier,***,***),identifier),***,***) | stats values(identifier) by identifier | eval identifier=concat(***,mvjoin(identifier,***),***) | spath input=identifier output=identifier path=identifier | spath input=identifier output=identifier path=identifier | spath input=identifier output=identifier path=identifier | spath input=identifier output=identifier path=identifier | fields + identifier,identifier,identifier,identifier
[2026-10-20T21:40:54,004][INFO ][o.o.s.o.r.IndexPruner    ] [node-0] Index pruning skipped: wildcard=false, alias=n/a, dataStream=n/a
[2026-10-20T21:40:54,004][INFO ][o.o.s.o.r.OpenSearchRequestBuilder] [node-0] Index expression has 1 names after pruning
[2026-10-20T21:40:54,250][INFO ][o.o.s.o.r.IndexPruner    ] [node-0] Index pruning skipped: wildcard=false, alias=n/a, dataStream=n/a
[2026-10-20T21:40:54,251][INFO ][o.o.s.o.r.OpenSearchRequestBuilder] [node-0] Index expression has 1 names after pruning
[2026-10-20T21:41:13,490][INFO ][o.o.s.s.c.FlintStreamingJobHouseKeeperTask] [node-0] Starting housekeeping task for auto refresh streaming jobs.
[2026-10-20T21:41:13,492][INFO ][o.o.s.s.c.FlintStreamingJobHouseKeeperTask] [node-0] Finished housekeeping task for auto refresh streaming jobs.
[2026-10-20T21:41:13,529][INFO ][o.o.j.s.JobSweeper       ] [node-0] Running full sweep
[2026-10-20T21:41:23,915][INFO ][o.o.s.p.PPLService       ] [node-0] [d0b70ecf-6284-49ed-bd64-1517ab5ad22f] Incoming request [ source=table | where match(identifier,***) ] as identifier | inner join max=*** left = identifier right = identifier on identifier = identifier table as identifier | eval identifier=identifier identifier=mvappend(identifier,identifier) | expand identifier | eval identifier=cast(identifier as string) identifier=cast(identifier as string) | where identifier in (***) | eval identifier=replace(json_object(replace(identifier,***,***),identifier),***,***) | stats values(identifier) by identifier | eval identifier=concat(***,mvjoin(identifier,***),***) | spath input=identifier output=identifier path=identifier | spath input=identifier output=identifier path=identifier | spath input=identifier output=identifier path=identifier | spath input=identifier output=identifier path=identifier | fields + identifier,identifier,identifier,identifier
[2026-10-20T21:41:23,950][ERROR][o.o.s.o.e.ThreadPoolExecutionDispatcher] [node-0] Exception during task execution on complex pool
java.lang.RuntimeException: java.sql.SQLException: exception while executing query: The task is cancelled.
	at org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine.lambda$execute$1(OpenSearchExecutionEngine.java:355)
	at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.schedule(OpenSearchNodeClient.java:258)
	at org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine.execute(OpenSearchExecutionEngine.java:330)
	at org.opensearch.sql.opensearch.executor.ThreadPoolExecutionDispatcher.lambda$dispatch$0(ThreadPoolExecutionDispatcher.java:54)
	at org.opensearch.sql.opensearch.executor.ThreadPoolExecutionDispatcher.lambda$dispatchInternal$0(ThreadPoolExecutionDispatcher.java:109)
	at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:952)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
	at java.base/java.lang.Thread.run(Thread.java:1474)
Caused by: java.sql.SQLException: exception while executing query: The task is cancelled.
	at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
	at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
	at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:579)
	at org.apache.calcite.avatica.AvaticaPreparedStatement.executeQuery(AvaticaPreparedStatement.java:137)
	at org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine.lambda$execute$1(OpenSearchExecutionEngine.java:335)
	... 8 more
Caused by: TaskCancelledException[The task is cancelled.]
	at org.opensearch.sql.opensearch.storage.scan.BackgroundSearchScanner.getCurrentResponse(BackgroundSearchScanner.java:124)
	at org.opensearch.sql.opensearch.storage.scan.BackgroundSearchScanner.fetchNextBatch(BackgroundSearchScanner.java:158)
	at org.opensearch.sql.opensearch.storage.scan.OpenSearchIndexEnumerator.fetchNextBatch(OpenSearchIndexEnumerator.java:92)
	at org.opensearch.sql.opensearch.storage.scan.OpenSearchIndexEnumerator.moveNext(OpenSearchIndexEnumerator.java:140)
	at org.apache.calcite.linq4j.EnumerableDefaults$MergeJoinEnumerator.advance(EnumerableDefaults.java:4954)
	at org.apache.calcite.linq4j.EnumerableDefaults$MergeJoinEnumerator.moveNext(EnumerableDefaults.java:5093)
	at Baz$5$1.moveNext(Unknown Source)
	at org.apache.calcite.linq4j.EnumerableDefaults$12$1.moveNext(EnumerableDefaults.java:2088)
	at Baz$8$1.moveNext(Unknown Source)
	at org.apache.calcite.linq4j.EnumerableDefaults.groupBy_(EnumerableDefaults.java:1166)
	at org.apache.calcite.linq4j.EnumerableDefaults.groupBy(EnumerableDefaults.java:782)
	at org.apache.calcite.linq4j.DefaultEnumerable.groupBy(DefaultEnumerable.java:312)
	at Baz.bind(Unknown Source)
	at org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:367)
	at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:335)
	at org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:609)
	at org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:600)
	at org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:184)
	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
	at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:575)
	... 10 more
	Suppressed: java.lang.RuntimeException: Error occurred while deleting PIT for internal plugin operation
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.deletePit(OpenSearchNodeClient.java:298)
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.lambda$forceCleanup$1(OpenSearchNodeClient.java:229)
		at org.opensearch.sql.opensearch.request.OpenSearchQueryRequest.forceClean(OpenSearchQueryRequest.java:318)
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.forceCleanup(OpenSearchNodeClient.java:226)
		at org.opensearch.sql.opensearch.storage.scan.OpenSearchIndexEnumerator.close(OpenSearchIndexEnumerator.java:164)
		at org.apache.calcite.linq4j.EnumerableDefaults$MergeJoinEnumerator.close(EnumerableDefaults.java:5115)
		at Baz$5$1.close(Unknown Source)
		at org.apache.calcite.linq4j.EnumerableDefaults$12$1.close(EnumerableDefaults.java:2151)
		at Baz$8$1.close(Unknown Source)
		at org.apache.calcite.linq4j.EnumerableDefaults.groupBy_(EnumerableDefaults.java:1183)
		... 21 more
	Caused by: java.lang.InterruptedException
		at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1140)
		at org.opensearch.common.util.concurrent.BaseFuture$Sync.get(BaseFuture.java:272)
		at org.opensearch.common.util.concurrent.BaseFuture.get(BaseFuture.java:104)
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.deletePit(OpenSearchNodeClient.java:290)
		... 30 more
[2026-10-20T21:41:23,950][ERROR][o.o.s.p.r.RestPPLQueryAction] [node-0] Error happened during query handling (status INTERNAL_SERVER_ERROR)
java.lang.RuntimeException: java.sql.SQLException: exception while executing query: The task is cancelled.
	at org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine.lambda$execute$1(OpenSearchExecutionEngine.java:355)
	at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.schedule(OpenSearchNodeClient.java:258)
	at org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine.execute(OpenSearchExecutionEngine.java:330)
	at org.opensearch.sql.opensearch.executor.ThreadPoolExecutionDispatcher.lambda$dispatch$0(ThreadPoolExecutionDispatcher.java:54)
	at org.opensearch.sql.opensearch.executor.ThreadPoolExecutionDispatcher.lambda$dispatchInternal$0(ThreadPoolExecutionDispatcher.java:109)
	at org.opensearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:952)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
	at java.base/java.lang.Thread.run(Thread.java:1474)
Caused by: java.sql.SQLException: exception while executing query: The task is cancelled.
	at org.apache.calcite.avatica.Helper.createException(Helper.java:56)
	at org.apache.calcite.avatica.Helper.createException(Helper.java:41)
	at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:579)
	at org.apache.calcite.avatica.AvaticaPreparedStatement.executeQuery(AvaticaPreparedStatement.java:137)
	at org.opensearch.sql.opensearch.executor.OpenSearchExecutionEngine.lambda$execute$1(OpenSearchExecutionEngine.java:335)
	... 8 more
Caused by: TaskCancelledException[The task is cancelled.]
	at org.opensearch.sql.opensearch.storage.scan.BackgroundSearchScanner.getCurrentResponse(BackgroundSearchScanner.java:124)
	at org.opensearch.sql.opensearch.storage.scan.BackgroundSearchScanner.fetchNextBatch(BackgroundSearchScanner.java:158)
	at org.opensearch.sql.opensearch.storage.scan.OpenSearchIndexEnumerator.fetchNextBatch(OpenSearchIndexEnumerator.java:92)
	at org.opensearch.sql.opensearch.storage.scan.OpenSearchIndexEnumerator.moveNext(OpenSearchIndexEnumerator.java:140)
	at org.apache.calcite.linq4j.EnumerableDefaults$MergeJoinEnumerator.advance(EnumerableDefaults.java:4954)
	at org.apache.calcite.linq4j.EnumerableDefaults$MergeJoinEnumerator.moveNext(EnumerableDefaults.java:5093)
	at Baz$5$1.moveNext(Unknown Source)
	at org.apache.calcite.linq4j.EnumerableDefaults$12$1.moveNext(EnumerableDefaults.java:2088)
	at Baz$8$1.moveNext(Unknown Source)
	at org.apache.calcite.linq4j.EnumerableDefaults.groupBy_(EnumerableDefaults.java:1166)
	at org.apache.calcite.linq4j.EnumerableDefaults.groupBy(EnumerableDefaults.java:782)
	at org.apache.calcite.linq4j.DefaultEnumerable.groupBy(DefaultEnumerable.java:312)
	at Baz.bind(Unknown Source)
	at org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:367)
	at org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:335)
	at org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:609)
	at org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:600)
	at org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:184)
	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
	at org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
	at org.apache.calcite.avatica.AvaticaConnection.executeQueryInternal(AvaticaConnection.java:575)
	... 10 more
	Suppressed: java.lang.RuntimeException: Error occurred while deleting PIT for internal plugin operation
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.deletePit(OpenSearchNodeClient.java:298)
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.lambda$forceCleanup$1(OpenSearchNodeClient.java:229)
		at org.opensearch.sql.opensearch.request.OpenSearchQueryRequest.forceClean(OpenSearchQueryRequest.java:318)
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.forceCleanup(OpenSearchNodeClient.java:226)
		at org.opensearch.sql.opensearch.storage.scan.OpenSearchIndexEnumerator.close(OpenSearchIndexEnumerator.java:164)
		at org.apache.calcite.linq4j.EnumerableDefaults$MergeJoinEnumerator.close(EnumerableDefaults.java:5115)
		at Baz$5$1.close(Unknown Source)
		at org.apache.calcite.linq4j.EnumerableDefaults$12$1.close(EnumerableDefaults.java:2151)
		at Baz$8$1.close(Unknown Source)
		at org.apache.calcite.linq4j.EnumerableDefaults.groupBy_(EnumerableDefaults.java:1183)
		... 21 more
	Caused by: java.lang.InterruptedException
		at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1140)
		at org.opensearch.common.util.concurrent.BaseFuture$Sync.get(BaseFuture.java:272)
		at org.opensearch.common.util.concurrent.BaseFuture.get(BaseFuture.java:104)
		at org.opensearch.sql.opensearch.client.OpenSearchNodeClient.deletePit(OpenSearchNodeClient.java:290)
		... 30 more

Something appears to happen 30 seconds after the query has started: task is cancelled.
And then it goes downhill, with OpenSearch not being able to recover.

Are there other settings that I can tweak that ensure that OpenSearch “takes it time” to process the query, even if that means a (very) long response time?

@damiano.albani As you might be aware, these are documented settings for PPL

Did you consider a smaller subsets and then increasing the query range?
Did you notice Java heap increase during the search? If yes, did it reach the maximum space?

even if that means a (very) long response time?