From 74c844ab6052b2e7a31b8e8d367c33437255d894 Mon Sep 17 00:00:00 2001 From: harrylowkey Date: Mon, 13 May 2024 08:35:45 +0700 Subject: [PATCH] note: json vs jsonb --- notes/databases/json_vs_jsonb_type.md | 33 ++++++++++++++++++++++ view_counts.txt | 40 +++++++++++++-------------- 2 files changed, 53 insertions(+), 20 deletions(-) create mode 100644 notes/databases/json_vs_jsonb_type.md diff --git a/notes/databases/json_vs_jsonb_type.md b/notes/databases/json_vs_jsonb_type.md new file mode 100644 index 0000000..0fb5b26 --- /dev/null +++ b/notes/databases/json_vs_jsonb_type.md @@ -0,0 +1,33 @@ +# JSON vs JSONB in PostgreSQL + + + + + +Ref: https://www.dbvis.com/thetable/json-vs-jsonb-in-postgresql-a-complete-comparison/ + +JSON: + - Does not support indexing + +JSONB: + - Supports indexing: GIN, GIST + +JSON > JSONB when: + - You have to perform a lot of INSERT operations + - You do not expect to perform complex queries on your JSON data + - You need to preserve the original JSON data indentation and format + +JSONB > JSON when: + - Storing user tracking data that needs to be updated over time + - Storing permission or configuration data + - Storing highly nested data whose structure may change over time + +JSON vs. JSONB: Main differences + +The main difference between json and jsonb lies in the way they store data behind the scene. This makes jsonb inherently more efficient than json. Specifically, the json data type stores an exact copy of the input text. So, each function and operation has to reparse the entire field at each execution. + +At the same time, this can also represent an advantage over jsonb. This is because json preserves the indentation of the input data. So, if you need to be careful about JSON formatting, the json PostgreSQL data type can be useful. + +On the other hand, jsonb stores data in a decomposed binary format. This makes the `INSERT` operation a bit slower compared to json due to conversion overhead. However, the jsonb binary format is significantly faster to process because it does not involve reparsing. Also, jsonb supports many more functions and operators than json. + +Moreover, jsonb supports indexing. This can lead to significant performance advantages when parsing and querying JSON data. diff --git a/view_counts.txt b/view_counts.txt index c940269..512cb5c 100644 --- a/view_counts.txt +++ b/view_counts.txt @@ -1,22 +1,22 @@ -index:170 -projects/climate:3 -notes:14 -projects/coders-tokyo-forum-backend:2 +index:176 +projects/climate:5 +notes:16 +projects/coders-tokyo-forum-backend:3 projects/code2image-package:3 projects/what-I-learn:2 notes/test-local-package:1 -projects/renyoo:4 -notes/setup-docker-on-ec2-server:2 -projects/usdol:3 +projects/renyoo:5 +notes/setup-docker-on-ec2-server:3 +projects/usdol:5 notes/sso:1 -projects:5 +projects:6 projects/iscale:3 projects/instagram-coding-easily:3 notes/locking:3 -projects/tornomy:1 -projects/materiality:2 +projects/tornomy:2 +projects/materiality:3 projects/coders-tokyo-forum-frontend:1 -projects/mcashpay:2 +projects/mcashpay:3 notes/5_cost_optimization:1 notes/reverse-proxy-vs-proxy-server:2 notes/transactions:3 @@ -26,15 +26,15 @@ notes/2_security:1 notes/microservice:1 notes/6_sustainability:1 notes/best-practices:1 -notes/1_operational_excellence:1 -notes/lambda:1 -notes/3_reliability:1 -notes/volumne_note:1 -notes/query-plan:1 -notes/useful-commands:1 -notes/oci-image:1 -notes/sargable-queries:1 -notes/instance-purchasing-option:1 +notes/1_operational_excellence:2 +notes/lambda:2 +notes/3_reliability:2 +notes/volumne_note:2 +notes/query-plan:2 +notes/useful-commands:2 +notes/oci-image:2 +notes/sargable-queries:2 +notes/instance-purchasing-option:2 notes/db-docker:1 notes/seucurity-context-note:1 notes/command:2