PostgreSQL: in-table blobs are fetched as hex text, 9–13× slower than MySQL
Les mainteneurs répondent en général sous 5 jours
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
Piste de recherche
Start by reading the PostgreSQL adapter and its fetch path for bytea columns; the issue names no source files or tests. Compare the current psycopg2 result handling with psycopg 3 binary results and the binary COPY measurements given here. Done means establishing whether binary fetching can be supported and, if so, confirming large blob fetches preserve their values and improve performance; documenting the storage trade-off is the stated interim option.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
On PostgreSQL, fetching a large in-table blob (bytes, i.e. bytea) costs about 1.2–2 ms per MB, against 0.15–0.25 ms per MB on MySQL. Almost all of it goes to transferring the value as hex text, which is twice its size:
- psycopg2 receives results in text format;
- the server encodes every
byteaas hex (bytea_output = hex), and the client decodes it again.
Fetching the same bytes in binary format is about 4× faster.
Measurements
These come from the MySQL/PostgreSQL benchmark in datajoint/datajoint-docs#315: DataJoint master at eefe74b4 with #1671, Docker on an Apple M5 Max, warm cache.
(Recording & key).fetch1() with a 4 MB in-table blob, median of 300 calls:
| MySQL 8.0 | MySQL 8.4 | PostgreSQL 16 | PostgreSQL 17 | |
|---|---|---|---|---|
DataJoint fetch1() |
0.64 ms | 0.65 ms | 8.35 ms | 5.63 ms |
| the same SQL as a bare driver call | 0.60 ms | 0.59 ms | 8.28 ms | 5.47 ms |
Thirty rows of 100 KB ((Unit & session).to_dicts()) take 0.68 ms on MySQL and 3.7–5.4 ms on PostgreSQL.
Where one 4 MB value's time goes on PostgreSQL:
| Step | PostgreSQL 16 | PostgreSQL 17 |
|---|---|---|
read the value from TOAST storage (get_byte(lfp, 0)) |
0.25 ms | 0.24 ms |
hex-encode it on the server, without sending it (length(encode(lfp, 'hex'))) |
7.1 ms | 7.0 ms |
| fetch it with psycopg2 (hex text) | 8.0 ms | 5.3 ms |
fetch the same bytes in binary format (COPY (SELECT lfp …) TO STDOUT (FORMAT binary)) |
2.1 ms | 0.76 ms |
Reading the value is cheap. The hex round trip is the cost, and it is the same whether or not DataJoint is involved: DataJoint's own overhead is about 0.05–0.15 ms per call.
With blobs in a file store (<blob@store>), all four engines take the same time (about 6 ms for 4 MB, spent on the client reading and checksumming the file).
Options
- Binary result format for blob columns.
- psycopg 3 supports binary results per cursor or per query (
cursor(binary=True),execute(..., binary=True)). - psycopg2 does not support binary results.
- Moving the PostgreSQL adapter to psycopg 3, at least for fetches that return
byteacolumns, would remove most of the gap: the binaryCOPYabove suggests about 0.8–2 ms for 4 MB instead of 5–8 ms.
- psycopg 3 supports binary results per cursor or per query (
- Document the trade-off. Until then, recommend
<blob@store>over in-table<blob>/bytesfor large arrays that are fetched often on PostgreSQL.
bytea_output = escape is not an alternative: escape format is larger than hex for binary data.
- Langage dominant
- Python
- Étoiles
- 198
- Forks
- 107
- Merge moyen
- 4 j 7 h
- PR mergées (30 j)
- 12
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de datajoint/datajoint-python
-
bug triage
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
datajoint/datajoint-python#1775 ·
Les mainteneurs répondent en général sous 5 jours
-
MySQL: with use_tls=False, 2.3.6 needs the cryptography package to log in to MySQL 8Peut-être pris @dimitri-yatsenko l’a pris il y a 5 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
datajoint/datajoint-python#1750 ·
Les mainteneurs répondent en général sous 5 jours
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
datajoint/datajoint-python#1747 ·
Les mainteneurs répondent en général sous 5 jours
-
Reject constant defaults on primary-key attributesPeut-être pris @godara-alt l’a pris il y a 4 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
datajoint/datajoint-python#1712 ·
Les mainteneurs répondent en général sous 5 jours
-
Decoding a <blob> value in an unknown format returns None instead of raising an errorPeut-être pris @godara-alt l’a pris il y a 9 jours. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
datajoint/datajoint-python#1703 ·
Les mainteneurs répondent en général sous 5 jours
Toutes les issues de datajoint/datajoint-python
Issues similaires
-
[Bug]: test_remote_realpath_uses_argument_vector fails on Windows with Python 3.13+ (ntpath.isabs)Peut-être pris @gouyu-hou l’a pris aujourd’hui. Ouvertetriage/confirmed
Difficulté 1/5 Moins d'une heure Accessibilité débutants 90/100
agentscope-ai/agentscope#4397 ·
Les mainteneurs répondent en général sous 2 jours
-
area/profiles area/sessions comp/desktop desktop/chat desktop/sessions P2 type/bug
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
NousResearch/hermes-agent#161712 ·
Les mainteneurs répondent en général sous 1 jour
-
[New Check]: postgresql_flexible_server_public_network_access_disabledPeut-être pris @pouria-l l’a pris aujourd’hui. Ouvertefeature-request status/needs-triage
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
prowler-cloud/prowler#13615 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
SACGF/variantgrid#2941 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
linkedin/Liger-Kernel#1730 ·
Les mainteneurs répondent en général sous 3 jours