テーマ: data-modelling
-
PostgreSQL で追記専用の時系列テーブルを設計する
測定値を時間範囲で分割したテーブルに保存し、timestamptz、系列と時刻の複合キー、問い合わせに合う索引を使う。系列別には B-tree、テーブル全体の時間走査には BRIN を選ぶ。保持期限は DELETE ではなくパーティションの切り離しと削除で実現する。時間順に行が到着し、時間区間単位で消える性質に基づく設計である。
-
緩やかに変化するディメンション:上書き、行追加、列追加
顧客の転居や商品の再分類などでディメンション属性が変わると、タイプ 1 は上書きして履歴を失い、タイプ 2 は新しい代理キーの下に有効開始日・終了日・現在行フラグを持つ行を追加し、タイプ 3 は追加列に以前の値を保持する。スナップショットツールは、実行ごとに更新時刻または列の集合を比較してタイプ 2 を実装する。
-
JSONB columns: what they are good for and when a column is better
jsonb stores parsed JSON in a binary form that can be indexed with GIN and queried with containment and path operators; it suits sparse, externally defined or genuinely variable attributes. Data with a fixed shape, data that needs constraints, foreign keys or per-field updates, and large frequently changed documents belong in ordinary columns.
-
同意と設定の記録をデータとして扱う:何を、いつ、どの画面で選んだか
個人の選択を追記のみのイベント(対象、目的、選択、時刻、出所、テキストの版)としてモデル化し、そこから導く現在状態のビューを各利用側が使用時点で読む。ユーザー行の真偽値だけでは、ある操作の時点で何に同意していたか、バナーの不具合がどのユーザーに影響したかに答えられない。
-
Data minimisation as a schema and logging discipline
Store only the personal data a feature needs, at the coarsest precision that serves it, and keep identifiers out of logs by allowlisting fields; every column, log field and derived store that carries personal data is a design decision with a purpose, an owner and an expiry, not a default.
-
Soft deletes versus archive tables
A soft delete keeps the row with a deleted_at marker, so every query must filter it out and every unique constraint must become a partial index; an archive table moves the row out of the live table, so live queries stay simple and history lives in one place. Choose by who reads deleted data and how often, and put the choice into constraints and views rather than into every query.
-
Normalising to third normal form and choosing when to denormalise
Normal forms remove repeating groups and facts stored in more than one place; third normal form means every non-key column depends on the key and nothing else. Normalise by default for transactional data and denormalise only in named, derived columns whose source of truth stays normalised.
-
PostgreSQLの宣言的制約:CHECK、UNIQUE、ON DELETE付き外部キー
制約はアプリケーションだけでなく、すべての書き込み主体に対して無効な状態をデータベースに拒否させます。行単位のルールには CHECK、必須値には NOT NULL、一意性には UNIQUE、外部キーには明示的な ON DELETE 動作を使います。参照動作の選択と参照元列の索引作成が、特に見落とされがちです。
-
Star schema basics: facts, dimensions and declaring the grain
A star schema stores measurements in fact tables and descriptive context in dimension tables linked by keys; the design starts by declaring the grain, what one fact row represents, because every measure and dimension must be consistent with it. Fully additive measures sum across any dimension, semi-additive ones not across time, and ratios must be stored as their components.
-
Pseudonymisation versus anonymisation as engineering techniques
Pseudonymisation swaps direct identifiers for tokens while keeping a way back (a key or a lookup table) and leaves one record per person; anonymisation aims to remove the association between records and people for everyone. Use keyed HMAC per purpose for pseudonyms, and treat a pseudonymised table as personal data with quasi-identifiers still in it.
-
IDENTITY列、シーケンス、生成IDに欠番が生じる理由
IDENTITY列は PostgreSQL で行に自動採番する標準的な方法です。値はトランザクション制御の外で払い出されるシーケンスから取得するため、ロールバック、クラッシュ、キャッシュ、ON CONFLICT付きの挿入で欠番が生じます。欠番は正常であり、欠番のない番号には別の直列化されたカウンターが必要です。
機械可読: JSON