# The Performance of Various To-Many Nesting Algorithms

DevFeed: [The Performance of Various To-Many Nesting Algorithms](<https://devfeed.tech/articles/the-performance-of-various-to-many-nesting-algorithms-28965.md>)

Original publisher: [Read original article](<https://blog.jooq.org/the-performance-of-various-to-many-nesting-algorithms/>)

Author: lukaseder

Published: 2022-06-09T10:15:50Z

Content type: article

Language: en

Sources: [jOOQ](<https://devfeed.tech/sources/jooq.md>)

Topics: [Benchmark](<https://devfeed.tech/topics/benchmark.md>), [SQL](<https://devfeed.tech/topics/sql.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Object-relational mapping](<https://devfeed.tech/topics/orm.md>)

Tags: [benchmark](<https://devfeed.tech/tags/benchmark.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [database](<https://devfeed.tech/tags/database.md>), [java](<https://devfeed.tech/tags/java.md>), [jooq](<https://devfeed.tech/tags/jooq.md>), [jooq-development](<https://devfeed.tech/tags/jooq-development.md>), [json-arrayagg](<https://devfeed.tech/tags/json-arrayagg.md>), [many-to-many](<https://devfeed.tech/tags/many-to-many.md>), [multiset](<https://devfeed.tech/tags/multiset.md>), [mysql](<https://devfeed.tech/tags/mysql.md>), [nested-collections](<https://devfeed.tech/tags/nested-collections.md>), [one-to-many](<https://devfeed.tech/tags/one-to-many.md>), [oracle](<https://devfeed.tech/tags/oracle.md>), [ordbms](<https://devfeed.tech/tags/ordbms.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>), [sql-json](<https://devfeed.tech/tags/sql-json.md>), [sql-server](<https://devfeed.tech/tags/sql-server.md>), [sql-xml](<https://devfeed.tech/tags/sql-xml.md>), [test-data](<https://devfeed.tech/tags/test-data.md>)

## AI overview

This article benchmarks several approaches to nesting to-many relationships with jOOQ, including MULTISET emulation, single joins with client-side deduplication, and multiple queries per nesting level. It reports that these approaches outperform the N+1 approach, with relative performance depending on data size and use case.

## Source excerpt

It's been a while since jOOQ 3.15 has been released with its revolutionary standard SQL MULTISET emulation feature. A thing that has been long overdue and which I promised on twitter a few times is to run a few benchmarks comparing the performance of various approaches to nesting to-many relationships with jOOQ. This article will ... Continue reading The Performance of Various To-Many Nesting Algorithms ->