Django Query Optimization / select_related & prefetch_related / django-debug-toolbar / N+1 Problem

In this video, we learn about query optimization in Django, and solving the N+1 problem using the select_related() and prefetch_related() functions. We will look at how to use prefetch_related() to fetch all related objects in subsequent queries, as well as how to use select_related() to create a JOIN statement in SQL. Both methods can greatly cut down on the number of queries issued to the database, and therefore increase performance. We'll also see how to install and use django-debug-toolbar, and inspect and optimize the SQL queries via its feedback. Finally, we'll also look at Prefetch objects in Django, and how they can be used to customize the behaviour of the prefetch_related() function, as well as a quick look at the .only() function and .annotate() functions. ๐Ÿ“Œ ๐—–๐—ต๐—ฎ๐—ฝ๐˜๐—ฒ๐—ฟ๐˜€: 00:00 Intro 00:32 Using django-debug-toolbar for SQL analysis 08:47 Using prefetch_related to optimise querying and avoid N+1 problem 14:04 Using select_related with ForeignKey objects to avoid N+1 problem 17:23 Using only() function to fetch specific fields 19:22 Prefetch objects in Django โ˜•๏ธ ๐—•๐˜‚๐˜† ๐—บ๐—ฒ ๐—ฎ ๐—ฐ๐—ผ๐—ณ๐—ณ๐—ฒ๐—ฒ: To support the channel and encourage new videos, please consider buying me a coffee here: https://ko-fi.com/bugbytes โ–ถ๏ธ Full Playlist: ย ย ย โ€ขย Djangoย ORMย Deepย Diveย ย  ๐—ฆ๐—ผ๐—ฐ๐—ถ๐—ฎ๐—น ๐— ๐—ฒ๐—ฑ๐—ถ๐—ฎ: ๐Ÿ“– Blog: https://bugbytes.io/posts/ ๐Ÿ‘พ Github: https://github.com/bugbytes-io/django... ๐Ÿ“š ๐—™๐˜‚๐—ฟ๐˜๐—ต๐—ฒ๐—ฟ ๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ฎ๐—ป๐—ฑ ๐—ถ๐—ป๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป: Github: https://github.com/bugbytes-io/django... django-debug-toolbar: https://django-debug-toolbar.readthed... prefetch_related: https://docs.djangoproject.com/en/4.2... select_related: https://docs.djangoproject.com/en/4.2... QuerySet only() function: https://docs.djangoproject.com/en/4.2... Serving Static Files During Development: https://docs.djangoproject.com/en/4.2... #python #django #webdevelopment #database #sql

Django ManyToManyFields and Through-Models for many-to-many relationships
โ–ถ๏ธŽ

Django ManyToManyFields and Through-Models for many-to-many relationships

Django - COALESCE Function and Handling NULL Values in the Database
โ–ถ๏ธŽ

Django - COALESCE Function and Handling NULL Values in the Database

SQL Tutorial Part 2 .2 | Constraints in SQL
โ–ถ๏ธŽ

SQL Tutorial Part 2 .2 | Constraints in SQL

Django Media Files - Handling User Uploads in Django Forms & Models
โ–ถ๏ธŽ

Django Media Files - Handling User Uploads in Django Forms & Models

Django Database Transactions / atomic() function
โ–ถ๏ธŽ

Django Database Transactions / atomic() function

Microsoft Agent Framework | Storing Chat History in Azure
โ–ถ๏ธŽ

Microsoft Agent Framework | Storing Chat History in Azure

Django REST Framework - Serializers & Response objects | Browsable API
โ–ถ๏ธŽ

Django REST Framework - Serializers & Response objects | Browsable API

Django - Subquery, OuterRef and Exists objects for Database SQL Subqueries
โ–ถ๏ธŽ

Django - Subquery, OuterRef and Exists objects for Database SQL Subqueries

Beginner to T-SQL [Full Course]
โ–ถ๏ธŽ

Beginner to T-SQL [Full Course]

Django - F Expressions for database-level operations
โ–ถ๏ธŽ

Django - F Expressions for database-level operations

START YOUR TUESDAY WITH FAITH | TODAY GOD IS GIVING YOU UNEXPECTED OPPORTUNITIES | FATHER FREDDY ...
โ–ถ๏ธŽ

START YOUR TUESDAY WITH FAITH | TODAY GOD IS GIVING YOU UNEXPECTED OPPORTUNITIES | FATHER FREDDY ...

"We Ran Out Of Columns" - The Worst Codebase Ever
โ–ถ๏ธŽ

"We Ran Out Of Columns" - The Worst Codebase Ever

Django ORM - Querying and Creating Records / Working with Foreign Keys
โ–ถ๏ธŽ

Django ORM - Querying and Creating Records / Working with Foreign Keys

Django Aggregation & Annotation / values() and values_list() functions
โ–ถ๏ธŽ

Django Aggregation & Annotation / values() and values_list() functions

Something is jamming GPS over Europe. Here's what we found
โ–ถ๏ธŽ

Something is jamming GPS over Europe. Here's what we found

99% of Developers Don't Get PostgreSQL
โ–ถ๏ธŽ

99% of Developers Don't Get PostgreSQL

Django ORM - Updating and Deleting QuerySets / ForeignKey on_delete behaviour
โ–ถ๏ธŽ

Django ORM - Updating and Deleting QuerySets / ForeignKey on_delete behaviour

Django select_related Examples |Django select_related and prefetch_related |Django n+1 Query Problem
โ–ถ๏ธŽ

Django select_related Examples |Django select_related and prefetch_related |Django n+1 Query Problem

Django - Multiple Databases | inspectdb command | Database Routers
โ–ถ๏ธŽ

Django - Multiple Databases | inspectdb command | Database Routers

Django-Filter - Filtering Django Querysets, Class-Based Views and REST Framework Integration
โ–ถ๏ธŽ

Django-Filter - Filtering Django Querysets, Class-Based Views and REST Framework Integration