# many-to-many

Published articles for many-to-many.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## 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 ->

## All You Need To Know About Prefetching in Django

DevFeed: [All You Need To Know About Prefetching in Django](<https://devfeed.tech/articles/all-you-need-to-know-about-prefetching-in-django-33888.md>)

Original publisher: [Read original article](<https://hakibenita.com/all-you-need-to-know-about-prefetching-in-django>)

Author: Haki Benita

Published: 2017-04-28T21:00:00Z

Content type: tutorial

Language: en

Sources: [Haki Benita](<https://devfeed.tech/sources/haki-benita.md>)

Topics: [Django](<https://devfeed.tech/topics/django.md>), [Query (disambiguation)](<https://devfeed.tech/topics/query.md>), [JOIN](<https://devfeed.tech/topics/join.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [django](<https://devfeed.tech/tags/django.md>), [join](<https://devfeed.tech/tags/join.md>), [many-to-many](<https://devfeed.tech/tags/many-to-many.md>), [models](<https://devfeed.tech/tags/models.md>), [orm](<https://devfeed.tech/tags/orm.md>), [performance](<https://devfeed.tech/tags/performance.md>), [query](<https://devfeed.tech/tags/query.md>)

### AI overview

A tutorial on using Django prefetching to reduce database queries when retrieving related data, especially across many-to-many relationships. It explains the N+1 query problem, compares joins with prefetching, and describes how prefetched results are cached on objects.

### Source excerpt

A rundown of all the ways you can use Prefetch to speed up queries in Django.

## Using Postgres Arrays in Django

DevFeed: [Using Postgres Arrays in Django](<https://devfeed.tech/articles/using-postgres-arrays-in-django-41121.md>)

Original publisher: [Read original article](<https://www.craigkerstiens.com/2012/11/06/django-and-arrays/>)

Author: Map

Published: 2012-11-06T20:55:56Z

Content type: tutorial

Language: en

Sources: [Craig Kerstiens](<https://devfeed.tech/sources/craig-kerstiens.md>)

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

Tags: [arrays](<https://devfeed.tech/tags/arrays.md>), [create](<https://devfeed.tech/tags/create.md>), [development](<https://devfeed.tech/tags/development.md>), [django](<https://devfeed.tech/tags/django.md>), [many-to-many](<https://devfeed.tech/tags/many-to-many.md>), [orm](<https://devfeed.tech/tags/orm.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [query](<https://devfeed.tech/tags/query.md>), [save](<https://devfeed.tech/tags/save.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This tutorial shows how to use PostgreSQL array fields in Django with djorm-ext-pgarray and SQL expressions. It demonstrates defining array-backed tags, creating and querying posts, and contrasts this approach with Django many-to-many relationships.

### Source excerpt

A few weeks back I did a brief feature highlight on Postgres arrays. Since that time I've found myself using them with increasing regularity on small side projects. Much of this time I'm using Django and of course not opting to write raw SQL to be able to use arrays. Django actually makes it quite simple to work with Arrays in Postgres with a package by Andrey Antukh. Lets get started by installing two libraries: pip install djorm-ext-pgarray pip install djorm-ext-expressions The first library is for support for the array field type, the second allows us to more easily mix bits of SQL within the Django ORM. Now within our models.py we'll want import the library then we'll have an entirely new field type available to us: from djorm_pgarray.fields import ArrayField from djorm_expressions.models import ExpressionManager class Post(models.Model): subject = models.CharField(max_length=255) content = models.TextField() tags = ArrayField(dbtype="varchar(255)") Now we can begin using this. For example to create a simple blog post: Post(subject='foo', content='bar', tags=['hello','world']) post.save() In this example we're able to tag blog posts as one normally might, without requiring an extra model to join against. Taking advantage of the SQL Expressions library by Andrey as well we can query a blog post contains a certain tag: qs = Posts.objects.where( SqlExpression("tags", "@>", ['postgres', 'django']) ) Now to show some contrast lets take a look at how you would do the same thing without using the Array field: class Tag(models.Model): name = models.CharField(max_length=255) class Post(models.Model): subject = models.CharField(max_length=255) content = models.TextField() tags = models.ManyToManyField(Tag) Using the many-to-many relationship within Django requires you to save the Post, then add your tag is it requires having a primary key first: post = Post(subject='foo', content='bar') post.save() post.tags.add('hello','world') This means we have two calls to save it, an