# Haki Benita

The writings of Haki Benita

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

## How to Achieve Pruning When Querying by Non-Partitioned Columns in PostgreSQL

DevFeed: [How to Achieve Pruning When Querying by Non-Partitioned Columns in PostgreSQL](<https://devfeed.tech/articles/how-to-achieve-pruning-when-querying-by-non-partitioned-columns-in-postgresql-33924.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-partition-pruning>)

Author: Haki Benita

Published: 2026-07-08T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Databases](<https://devfeed.tech/topics/databases.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [index](<https://devfeed.tech/tags/index.md>), [partition](<https://devfeed.tech/tags/partition.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>)

### AI overview

This tutorial explains PostgreSQL partition pruning and shows how certain data patterns can enable pruning when queries filter on columns other than the partition key. It uses event data partitioned by year and examines queries by date range and session.

### Source excerpt

Under conventional wisdom, pruning can only be achieved when querying by the partition key. However, if your data follows certain patterns, using some clever tricks you can achieve pruning even when filtering by non-partition key columns.

## Row Locks With Joins Can Produce Surprising Results in PostgreSQL

DevFeed: [Row Locks With Joins Can Produce Surprising Results in PostgreSQL](<https://devfeed.tech/articles/row-locks-with-joins-can-produce-surprising-results-in-postgresql-33920.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgres-row-lock-with-join>)

Author: Haki Benita

Published: 2026-02-23T22:00:00Z

Content type: tutorial

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [Query (disambiguation)](<https://devfeed.tech/topics/query.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [database](<https://devfeed.tech/tags/database.md>), [locks](<https://devfeed.tech/tags/locks.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This article explains a PostgreSQL edge case in which row locks used with joins can produce surprising results, including a query returning no rows despite a valid, enforced foreign key. It uses a concurrent car-ownership update scenario and suggests ways to prevent the issue.

### Source excerpt

You execute a query that joins two tables with a valid an enforces foreign key and it returns no results. How is it possible? We thought it wasn't possible, but a recent incident revealed an edge case we never thought about. In this article I show how under some circumstances row locks with joins can produce surprising results, and suggest ways to prevent it.

## Unconventional PostgreSQL Optimizations

DevFeed: [Unconventional PostgreSQL Optimizations](<https://devfeed.tech/articles/unconventional-postgresql-optimizations-33925.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-unconventional-optimizations>)

Author: Haki Benita

Published: 2026-01-19T22:00:00Z

Content type: tutorial

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Optimization](<https://devfeed.tech/topics/optimization.md>), [Database](<https://devfeed.tech/topics/database.md>), [Query (disambiguation)](<https://devfeed.tech/topics/query.md>), [Inheritance](<https://devfeed.tech/topics/inheritance.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [database-optimization](<https://devfeed.tech/tags/database-optimization.md>), [optimization](<https://devfeed.tech/tags/optimization.md>), [partitioning](<https://devfeed.tech/tags/partitioning.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>), [vacuum](<https://devfeed.tech/tags/vacuum.md>)

### AI overview

This article presents unconventional PostgreSQL optimization techniques. It explains how constraint exclusion can use check constraints to avoid scanning a table for impossible conditions, while noting that enabling it broadly can add planning overhead; partition pruning is enabled by default for partitioned tables.

### Source excerpt

When it comes to database optimization, developers often reach for the same old tools: rewrite the query slightly differently, slap an index on a column, denormalize, analyze, vacuum, cluster, repeat. Conventional techniques are effective, but sometimes being creative can really pay off!

## Reliable Django Signals

DevFeed: [Reliable Django Signals](<https://devfeed.tech/articles/reliable-django-signals-33901.md>)

Original publisher: [Read original article](<https://hakibenita.com/django-reliable-signals>)

Author: Haki Benita

Published: 2025-10-29T22: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>), [implementation](<https://devfeed.tech/topics/implementation.md>), [modules](<https://devfeed.tech/topics/modules.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [decoupling](<https://devfeed.tech/tags/decoupling.md>), [django](<https://devfeed.tech/tags/django.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [modules](<https://devfeed.tech/tags/modules.md>)

### AI overview

This article explains that Django signals can be unreliable because of their underlying transport. It presents an alternative transport implementation using background tasks to make signals more reliable and safer for mission-critical workflows.

### Source excerpt

Django signals are extremely useful for decoupling modules and implementing complicated workflows. However, the underlying transport for signals makes them unreliable and subject to unexpected failures.In this article, I present an alternative transport implementation for Django signals using background tasks which makes them reliable and safer to use in mission critical workflows.

## Common Foreign Key Pitfalls and Optimizations in Django

DevFeed: [Common Foreign Key Pitfalls and Optimizations in Django](<https://devfeed.tech/articles/how-to-get-foreign-keys-horribly-wrong-33895.md>)

Original publisher: [Read original article](<https://hakibenita.com/django-foreign-keys>)

Author: Haki Benita

Published: 2025-07-14T21:00:00Z

Content type: article

Language: en

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

Topics: [Django](<https://devfeed.tech/topics/django.md>), [Code](<https://devfeed.tech/topics/code.md>), [implementation](<https://devfeed.tech/topics/implementation.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [deprecated](<https://devfeed.tech/tags/deprecated.md>), [django](<https://devfeed.tech/tags/django.md>), [documentation](<https://devfeed.tech/tags/documentation.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [orm](<https://devfeed.tech/tags/orm.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [review](<https://devfeed.tech/tags/review.md>)

### AI overview

An article about foreign keys in Django that demonstrates common pitfalls, potential optimizations, and implicit behavior. It uses a product catalog example and discusses constraints, auditing fields, ordering, and replacing deprecated unique_together usage with UniqueConstraint.

### Source excerpt

Constraints keep the integrity of your system and prevent you from shooting yourself in the foot. Foreign keys are a special type of constraint because, unlike unique, check, and primary keys, they span more than one relation. This makes foreign keys harder to enforce and harder to get right. In this article, I demonstrate common pitfalls, potential optimizations, and implicit behavior related to foreign keys.

## How to Get or Create in PostgreSQL

DevFeed: [How to Get or Create in PostgreSQL](<https://devfeed.tech/articles/how-to-get-or-create-in-postgresql-33922.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-get-or-create>)

Author: Haki Benita

Published: 2024-08-04T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Database](<https://devfeed.tech/topics/database.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [data](<https://devfeed.tech/tags/data.md>), [database](<https://devfeed.tech/tags/database.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This tutorial explains how to implement an idempotent "get or create" operation in PostgreSQL. It distinguishes the operation from UPSERT and examines unique constraints, existing-row checks, race conditions, concurrency issues, and possible table bloat.

### Source excerpt

"Get or create" is a very common operation for syncing data in the database, but implementing it correctly may be trickier than you may expect. If you ever had to implement it in a real system with real-life load, you may have overlooked potential race conditions, concurrency issues and even bloat!

## Fastest Way to Read Excel in Python

DevFeed: [Fastest Way to Read Excel in Python](<https://devfeed.tech/articles/fastest-way-to-read-excel-in-python-33903.md>)

Original publisher: [Read original article](<https://hakibenita.com/fast-excel-python>)

Author: Haki Benita

Published: 2024-01-02T22:00:00Z

Content type: article

Language: en

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

Topics: [Python](<https://devfeed.tech/topics/python.md>), [data](<https://devfeed.tech/topics/data.md>), [CSV](<https://devfeed.tech/topics/csv.md>), [parquet](<https://devfeed.tech/topics/parquet.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [compare](<https://devfeed.tech/tags/compare.md>), [csv](<https://devfeed.tech/tags/csv.md>), [excel](<https://devfeed.tech/tags/excel.md>), [generator](<https://devfeed.tech/tags/generator.md>), [import](<https://devfeed.tech/tags/import.md>), [memory](<https://devfeed.tech/tags/memory.md>), [parquet](<https://devfeed.tech/tags/parquet.md>), [performance](<https://devfeed.tech/tags/performance.md>), [python](<https://devfeed.tech/tags/python.md>), [reading](<https://devfeed.tech/tags/reading.md>)

### AI overview

This article compares several ways to read Excel files from Python. It benchmarks importing data from a 25 MB XLSX file containing 500,000 rows and considers timing, memory use, generators, and preservation of Excel data types.

### Source excerpt

I'm fairly sure that Excel is the most common way to store data, manipulate data, and yes(!), even pass data around. This is why it's not uncommon to find yourself reading Excel in Python. In this article I compare several ways to read Excel from Python.

## When High Correlation Makes PostgreSQL BRIN Indexes Slower

DevFeed: [When High Correlation Makes PostgreSQL BRIN Indexes Slower](<https://devfeed.tech/articles/when-good-correlation-is-not-enough-33921.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-correlation-brin-multi-minmax>)

Author: Haki Benita

Published: 2023-07-26T21:00:00Z

Content type: article

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [indexes](<https://devfeed.tech/tags/indexes.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This article explains how PostgreSQL block range indexes (BRIN) work and why high correlation can still produce significantly slower execution under certain reproducible conditions. It describes lossy index behavior and presents a recent PostgreSQL feature as a possible remedy.

### Source excerpt

Choosing to use a block range index (BRIN) to query a field with high correlation is a no-brainer for the optimizer. However, under some easily reproducible circumstances, a BRIN index can result in significantly slower execution even when the indexed field has very high correlation. In this article I describe how using a BRIN index in presumably "ideal circumstances" can result in degraded performance, and suggest a recent new feature of PostgreSQL as a remedy.

## Future Proofing SQL with Carefully Placed Errors

DevFeed: [Future Proofing SQL with Carefully Placed Errors](<https://devfeed.tech/articles/future-proofing-sql-with-carefully-placed-errors-33905.md>)

Original publisher: [Read original article](<https://hakibenita.com/future-proof-sql>)

Author: Haki Benita

Published: 2022-10-05T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [SQL](<https://devfeed.tech/topics/sql.md>), [schema-evolution](<https://devfeed.tech/topics/schema-evolution.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [best-practices](<https://devfeed.tech/tags/best-practices.md>), [compatibility](<https://devfeed.tech/tags/compatibility.md>), [errors](<https://devfeed.tech/tags/errors.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This article explains how to future-proof SQL by deliberately placing errors in queries so that unsupported changes, such as a newly added payment method, are detected instead of silently producing incorrect business results.

### Source excerpt

There are many best practices for maintaining backward and forward compatibility in application code, but it's not very commonly mentioned in relation to SQL. SQL is used to produce critical business information for applications and decision-making, so there's no reason it shouldn't benefit from similar practices. In this article, I present a simple way to future-proof SQL.

## Handling Concurrency Without Locks

DevFeed: [Handling Concurrency Without Locks](<https://devfeed.tech/articles/handling-concurrency-without-locks-33894.md>)

Original publisher: [Read original article](<https://hakibenita.com/django-concurrency>)

Author: Haki Benita

Published: 2022-06-08T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Concurrent Programming](<https://devfeed.tech/topics/concurrent-programming.md>), [Processes](<https://devfeed.tech/topics/processes.md>), [Django](<https://devfeed.tech/topics/django.md>), [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [code](<https://devfeed.tech/tags/code.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [django](<https://devfeed.tech/tags/django.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [locks](<https://devfeed.tech/tags/locks.md>), [orm](<https://devfeed.tech/tags/orm.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [processes](<https://devfeed.tech/tags/processes.md>), [python](<https://devfeed.tech/tags/python.md>)

### AI overview

A tutorial on recognizing and handling concurrency problems when multiple processes execute code at the same time. It uses a URL shortener built with Python, Django, and PostgreSQL to demonstrate common challenges and approaches that minimize locking.

### Source excerpt

Concurrency is not very intuitive - you need to train your brain to consider what happens when multiple processes execute a certain code block at the same time. In this article I present common concurrency challenges and how to overcome them with minimal locking.

## Lesser Known PostgreSQL Features

DevFeed: [Lesser Known PostgreSQL Features](<https://devfeed.tech/articles/lesser-known-postgresql-features-33926.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-unknown-features>)

Author: Haki Benita

Published: 2021-11-07T22:00:00Z

Content type: tutorial

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [etl](<https://devfeed.tech/topics/etl.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [etl](<https://devfeed.tech/tags/etl.md>), [features](<https://devfeed.tech/tags/features.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>)

### AI overview

This article presents lesser-known PostgreSQL features, including a command for synchronizing table data and a technique for distinguishing inserted rows from updated rows using a system column. It also discusses logging ETL processes.

### Source excerpt

A list of useful features you already have, but may not know about! In this article I share lesser known features of PostgreSQL.

## Nested Transactions and Django Signals Caused Incorrect Payout Notifications

DevFeed: [Nested Transactions and Django Signals Caused Incorrect Payout Notifications](<https://devfeed.tech/articles/one-database-transaction-too-many-33899.md>)

Original publisher: [Read original article](<https://hakibenita.com/django-nested-transaction>)

Author: Haki Benita

Published: 2021-06-06T21:00:00Z

Content type: article

Language: en

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

Topics: [Transactions](<https://devfeed.tech/topics/transactions.md>), [Django](<https://devfeed.tech/topics/django.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [database](<https://devfeed.tech/tags/database.md>), [django](<https://devfeed.tech/tags/django.md>), [messages](<https://devfeed.tech/tags/messages.md>), [orm](<https://devfeed.tech/tags/orm.md>), [transactions](<https://devfeed.tech/tags/transactions.md>), [users](<https://devfeed.tech/tags/users.md>)

### AI overview

This article examines how nested database transactions and Django signals caused users to receive payout notifications before their payments were reliably completed. It uses the incident to explain a lesson about coordinating transaction state and notifications.

### Source excerpt

A story about how I ended up sending hundreds of users messages saying they got paid when they didn't! In the process we've learned a valuable lesson about nested transactions and Django signals.

## Practical SQL for Data Analysis

DevFeed: [Practical SQL for Data Analysis](<https://devfeed.tech/articles/practical-sql-for-data-analysis-33937.md>)

Original publisher: [Read original article](<https://hakibenita.com/sql-for-data-analysis>)

Author: Haki Benita

Published: 2021-04-25T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [SQL](<https://devfeed.tech/topics/sql.md>), [Data analysis](<https://devfeed.tech/topics/data-analysis.md>), [pandas](<https://devfeed.tech/topics/pandas.md>), [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Python](<https://devfeed.tech/topics/python.md>)

Tags: [analysis](<https://devfeed.tech/tags/analysis.md>), [articles](<https://devfeed.tech/tags/articles.md>), [benchmark](<https://devfeed.tech/tags/benchmark.md>), [data-analysis](<https://devfeed.tech/tags/data-analysis.md>), [database](<https://devfeed.tech/tags/database.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [pandas](<https://devfeed.tech/tags/pandas.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [practical](<https://devfeed.tech/tags/practical.md>), [python](<https://devfeed.tech/tags/python.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This practical tutorial demonstrates how SQL can perform fast and efficient data analysis using a users table, comparing the approach with pandas and measuring memory usage. It reports that pandas alone uses about 37 MB and loading the data into memory adds about 300 MB, while the database table is 65 MB.

### Source excerpt

Pandas is by far the most popular tool for data analysis. It's packed with useful features, it's battle tested and widely accepted. However, pandas comes at a cost which is often overlooked. SQL databases has been around since the 1970s. They contain many features that most developers never heard of, and I want to bring some of them to light.

## Exciting New Features in Django 3.2

DevFeed: [Exciting New Features in Django 3.2](<https://devfeed.tech/articles/exciting-new-features-in-django-3-2-33892.md>)

Original publisher: [Read original article](<https://hakibenita.com/django-32-exciting-features>)

Author: Haki Benita

Published: 2021-03-02T22: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>), [Object-relational mapping](<https://devfeed.tech/topics/orm.md>), [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Databases](<https://devfeed.tech/topics/databases.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [django](<https://devfeed.tech/tags/django.md>), [django-admin](<https://devfeed.tech/tags/django-admin.md>), [features](<https://devfeed.tech/tags/features.md>), [new-features](<https://devfeed.tech/tags/new-features.md>), [orm](<https://devfeed.tech/tags/orm.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [version](<https://devfeed.tech/tags/version.md>)

### AI overview

An overview of selected new features in Django 3.2, especially ORM improvements. It includes setup instructions and explains PostgreSQL covering indexes and covering unique constraints, including how index-only scans can improve query performance.

### Source excerpt

Django 3.2 is just around the corner and it's packed with new features. Django versions are usually not that exciting (it's a good thing!), but this time many features were added to the ORM, so I find it especially interesting!

## Finding and Reclaiming Unused PostgreSQL Index Space

DevFeed: [Finding and Reclaiming Unused PostgreSQL Index Space](<https://devfeed.tech/articles/the-unexpected-find-that-freed-20gb-of-unused-index-space-33927.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-unused-index-size>)

Author: Haki Benita

Published: 2021-01-31T22:00:00Z

Content type: article

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [database monitoring](<https://devfeed.tech/topics/database-monitoring.md>), [Databases](<https://devfeed.tech/topics/databases.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [database-monitoring](<https://devfeed.tech/tags/database-monitoring.md>), [databases](<https://devfeed.tech/tags/databases.md>), [django](<https://devfeed.tech/tags/django.md>), [indexes](<https://devfeed.tech/tags/indexes.md>), [orm](<https://devfeed.tech/tags/orm.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [query](<https://devfeed.tech/tags/query.md>), [statistics](<https://devfeed.tech/tags/statistics.md>), [storage](<https://devfeed.tech/tags/storage.md>)

### AI overview

The article explains how to identify potentially unused PostgreSQL indexes, assess whether they can safely be removed, and reset statistics counters before rechecking usage. It reports freeing more than 70GB of space overall, including about 20GB from unused indexed values, without dropping indexes or deleting data.

### Source excerpt

In this article I describe the process we took to identify potential free space, and one surprising find that helped up clear up ~10GB of unused indexed values!

## Re-Introducing Hash Indexes in PostgreSQL

DevFeed: [Re-Introducing Hash Indexes in PostgreSQL](<https://devfeed.tech/articles/re-introducing-hash-indexes-in-postgresql-33923.md>)

Original publisher: [Read original article](<https://hakibenita.com/postgresql-hash-index>)

Author: Haki Benita

Published: 2021-01-10T22:00:00Z

Content type: tutorial

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [hash](<https://devfeed.tech/topics/hash.md>), [Data structures](<https://devfeed.tech/topics/data-structures.md>), [Databases](<https://devfeed.tech/topics/databases.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [data-structure](<https://devfeed.tech/tags/data-structure.md>), [database](<https://devfeed.tech/tags/database.md>), [hash](<https://devfeed.tech/tags/hash.md>), [index](<https://devfeed.tech/tags/index.md>), [indexes](<https://devfeed.tech/tags/indexes.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This tutorial explains how PostgreSQL hash indexes work, including hash functions, buckets, tuple pointers, and collisions. It presents hash indexes as an option that can outperform B-Tree indexes under some circumstances.

### Source excerpt

There is a type of index you are probably not using, and may have never even heard of. It is wildly unpopular, and until a few PostgreSQL versions ago it was highly discouraged and borderline unusable, but under some circumstances it can out-perform even a B-Tree index.

## Exhaustiveness Checking with Mypy

DevFeed: [Exhaustiveness Checking with Mypy](<https://devfeed.tech/articles/exhaustiveness-checking-with-mypy-33932.md>)

Original publisher: [Read original article](<https://hakibenita.com/python-mypy-exhaustive-checking>)

Author: Haki Benita

Published: 2020-12-07T22:00:00Z

Content type: tutorial

Language: en

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

Topics: [Python](<https://devfeed.tech/topics/python.md>), [enum](<https://devfeed.tech/topics/enum.md>), [ci](<https://devfeed.tech/topics/ci.md>), [Exception](<https://devfeed.tech/topics/exception.md>), [Visual Studio Code](<https://devfeed.tech/topics/visual-studio-code.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [ci](<https://devfeed.tech/tags/ci.md>), [django](<https://devfeed.tech/tags/django.md>), [enum](<https://devfeed.tech/tags/enum.md>), [exception](<https://devfeed.tech/tags/exception.md>), [python](<https://devfeed.tech/tags/python.md>), [runtime-errors](<https://devfeed.tech/tags/runtime-errors.md>), [vscode](<https://devfeed.tech/tags/vscode.md>)

### AI overview

This tutorial explains how to use mypy, an optional static type checker for Python, to detect unhandled values in enumerations before runtime. It presents a helper function that enables exhaustiveness checking, shows the resulting warning, and describes integrating mypy into CI.

### Source excerpt

What if mypy could warn you about possible problems at "compile time"? In this article I share a little trick to get mypy to fail when a value in an enumeration type is left unhandled.

## The Surprising Impact of Medium-Size Texts on PostgreSQL Performance

DevFeed: [The Surprising Impact of Medium-Size Texts on PostgreSQL Performance](<https://devfeed.tech/articles/the-surprising-impact-of-medium-size-texts-on-postgresql-performance-33939.md>)

Original publisher: [Read original article](<https://hakibenita.com/sql-medium-text-performance>)

Author: Haki Benita

Published: 2020-10-19T21:00:00Z

Content type: article

Language: en

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

Topics: [PostgreSQL](<https://devfeed.tech/topics/postgresql.md>), [Database](<https://devfeed.tech/topics/database.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [database](<https://devfeed.tech/tags/database.md>), [performance](<https://devfeed.tech/tags/performance.md>), [postgresql](<https://devfeed.tech/tags/postgresql.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

This article examines how medium-size text fields can affect query performance in PostgreSQL. It introduces PostgreSQL's TOAST mechanism, which compresses or stores large field values out of line when rows exceed configured size thresholds.

### Source excerpt

Any database schema is likely to have plenty of text fields. In this article I demonstrate the surprising impact of medium-size texts on query performance.

## Simple Anomaly Detection Using Plain SQL

DevFeed: [Simple Anomaly Detection Using Plain SQL](<https://devfeed.tech/articles/simple-anomaly-detection-using-plain-sql-33935.md>)

Original publisher: [Read original article](<https://hakibenita.com/sql-anomaly-detection>)

Author: Haki Benita

Published: 2020-09-20T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [SQL](<https://devfeed.tech/topics/sql.md>), [Statistics](<https://devfeed.tech/topics/statistics.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [anomaly-detection](<https://devfeed.tech/tags/anomaly-detection.md>), [articles](<https://devfeed.tech/tags/articles.md>), [query](<https://devfeed.tech/tags/query.md>), [sql](<https://devfeed.tech/tags/sql.md>), [statistics](<https://devfeed.tech/tags/statistics.md>)

### AI overview

A developer explains how to build a simple anomaly detection system using plain SQL and basic statistics. The tutorial defines anomalies using the mean, standard deviation, acceptable ranges, and z-scores, with SQL queries applied to example data.

### Source excerpt

Many developers think that having a critical bug in their code is the worse thing that can happen. Well, there is something much worst than that: Having a critical bug in your code and not knowing about it! Using some high school level statistics and a fair knowledge of SQL, I implemented a very simple anomaly detection system.

## SQL Tips for Application DBAs

DevFeed: [SQL Tips for Application DBAs](<https://devfeed.tech/articles/some-sql-tricks-of-an-application-dba-33940.md>)

Original publisher: [Read original article](<https://hakibenita.com/sql-tricks-application-dba>)

Author: Haki Benita

Published: 2020-07-26T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [SQL](<https://devfeed.tech/topics/sql.md>), [Development](<https://devfeed.tech/topics/development.md>), [Databases](<https://devfeed.tech/topics/databases.md>), [schema design](<https://devfeed.tech/topics/schema-design.md>), [data migrations](<https://devfeed.tech/topics/data-migrations.md>), [etl](<https://devfeed.tech/topics/etl.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [data-migrations](<https://devfeed.tech/tags/data-migrations.md>), [databases](<https://devfeed.tech/tags/databases.md>), [development](<https://devfeed.tech/tags/development.md>), [etl](<https://devfeed.tech/tags/etl.md>), [performance](<https://devfeed.tech/tags/performance.md>), [schema-design](<https://devfeed.tech/tags/schema-design.md>), [sql](<https://devfeed.tech/tags/sql.md>)

### AI overview

An application DBA shares practical SQL and database-development advice, including limiting updates to rows that need changes and considering constraint costs when loading or updating many rows.

### Source excerpt

Some tips and misconceptions about database development I gathered along the way.

## Using Dependency Injection in Python to Make Date-Dependent Code Deterministic and Testable

DevFeed: [Using Dependency Injection in Python to Make Date-Dependent Code Deterministic and Testable](<https://devfeed.tech/articles/stop-using-datetime-now-33928.md>)

Original publisher: [Read original article](<https://hakibenita.com/python-dependency-injection>)

Author: Haki Benita

Published: 2020-05-31T21:00:00Z

Content type: article

Language: en

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

Topics: [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Python](<https://devfeed.tech/topics/python.md>), [DateTime](<https://devfeed.tech/topics/datetime.md>), [Testing](<https://devfeed.tech/topics/testing.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [django](<https://devfeed.tech/tags/django.md>), [nondeterminism](<https://devfeed.tech/tags/nondeterminism.md>), [python](<https://devfeed.tech/tags/python.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>)

### AI overview

This article explains how dependency injection can make Python code that depends on the current date deterministic and easier to test. It uses a function returning tomorrow's date to show why hard-coded time references create fragile tests, and presents passing the reference date as an argument as an alternative to mocking or external libraries.

### Source excerpt

If you ever had a test that one day just started to fail, unprovoked, or a test that fails once every blue moon for no apparent reason, it's possible your code is relying on something that is not deterministic. In this article I describe a practical approach to dependency injection in Python that when used correctly, can eliminate nondeterminism and make your code easier to maintain and to test.

## How to Move a Django Model to Another App

DevFeed: [How to Move a Django Model to Another App](<https://devfeed.tech/articles/how-to-move-a-django-model-to-another-app-33918.md>)

Original publisher: [Read original article](<https://hakibenita.com/move-django-model>)

Author: Haki Benita

Published: 2020-05-05T21:00:00Z

Content type: article

Language: en

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

Topics: [Django](<https://devfeed.tech/topics/django.md>), [migration](<https://devfeed.tech/topics/migration.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>)

Tags: [article](<https://devfeed.tech/tags/article.md>), [articles](<https://devfeed.tech/tags/articles.md>), [cli](<https://devfeed.tech/tags/cli.md>), [commands](<https://devfeed.tech/tags/commands.md>), [concepts](<https://devfeed.tech/tags/concepts.md>), [django](<https://devfeed.tech/tags/django.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [migration](<https://devfeed.tech/tags/migration.md>), [migrations](<https://devfeed.tech/tags/migrations.md>), [moving](<https://devfeed.tech/tags/moving.md>), [orm](<https://devfeed.tech/tags/orm.md>), [python](<https://devfeed.tech/tags/python.md>)

### AI overview

The article presents three ways to move a Django model from one Django app to another. It covers migration operations, built-in migration CLI commands, reversible migrations, migration plans, and introspection.

### Source excerpt

In my latest article for RealPython I cover some exotic migration operations, many of the built-in migration CLI commands and demonstrate important migrations concepts such as reversible migrations, migration plans and introspection.

## Testing an Interactive Voice Response System With Python and Pytest

DevFeed: [Testing an Interactive Voice Response System With Python and Pytest](<https://devfeed.tech/articles/testing-an-interactive-voice-response-system-with-python-and-pytest-33930.md>)

Original publisher: [Read original article](<https://hakibenita.com/python-django-pytest-twilio-ivr>)

Author: Haki Benita

Published: 2020-04-30T21:00:00Z

Content type: tutorial

Language: en

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

Topics: [Pytest](<https://devfeed.tech/topics/pytest.md>), [Python](<https://devfeed.tech/topics/python.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>), [business logic](<https://devfeed.tech/topics/business-logic.md>), [Django](<https://devfeed.tech/topics/django.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [automated](<https://devfeed.tech/tags/automated.md>), [business-logic](<https://devfeed.tech/tags/business-logic.md>), [django](<https://devfeed.tech/tags/django.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [pytest](<https://devfeed.tech/tags/pytest.md>), [python](<https://devfeed.tech/tags/python.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>)

### AI overview

This tutorial explains how to write automated tests for a Twilio Interactive Voice Response system built with Python and Django. It focuses on isolating business logic from the third-party service so the logic can be tested separately, using Pytest fixtures and other testing patterns.

### Source excerpt

It can be very challenging to test a system that rely heavily on a third party service such as Twilio. In this article, I show how to organize your code in a way that would isolate your bushiness logic and make it easier for you to test it separately.

## How to Provide Test Fixtures for Django Models in Pytest

DevFeed: [How to Provide Test Fixtures for Django Models in Pytest](<https://devfeed.tech/articles/how-to-provide-test-fixtures-for-django-models-in-pytest-33900.md>)

Original publisher: [Read original article](<https://hakibenita.com/django-pytest-fixtures>)

Author: Haki Benita

Published: 2020-04-07T21: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>), [Pytest](<https://devfeed.tech/topics/pytest.md>), [test](<https://devfeed.tech/topics/test.md>)

Tags: [articles](<https://devfeed.tech/tags/articles.md>), [dependency](<https://devfeed.tech/tags/dependency.md>), [django](<https://devfeed.tech/tags/django.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [pytest](<https://devfeed.tech/tags/pytest.md>), [python](<https://devfeed.tech/tags/python.md>), [test](<https://devfeed.tech/tags/test.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

### AI overview

This tutorial explains how to maintain flexible, usable test fixtures for Django models with Pytest. It covers setting up Pytest in a Django project, creating fixtures, defining fixture dependencies, and applying a "factory as a service" pattern to simplify test data setup.

### Source excerpt

One of the most challenging aspects of writing good tests is maintaining test fixtures. Good test fixtures motivate developers to write better tests, and bad fixtures can cripple a system to a point where developers fear and avoid them all together. The article covers everything from setting up Pytest for a Django project, creating test fixtures and how to create dependency between fixtures.

[Next page](<https://devfeed.tech/sources/haki-benita.md?cursor=WyIyMDIwLTA0LTA3VDIxOjAwOjAwKzAwOjAwIiwgIjA0MTkwMWI5LWQzNTItNDNjYy1iZDgzLTJhMDBhMjZlNGM5OSJd>)