Query and persist data
Data & storage
Explore queries, indexes, transactions and storage operations using synthetic records.
- concept
SQL primary keys and unique constraints
A primary key requires unique, non-null key values. A unique constraint follows its declared duplicate rule; PostgreSQL 18 default UNIQUE constraints allow multiple NULLs.
Explore the idea - concept
Database indexes and query plans
An index can let a query locate candidate rows without scanning every table row. That can reduce retrieval work, but a planner may still choose a sequential scan when its estimated cost is lower.
Explore the idea - concept
SQL joins explained
INNER JOIN returns one row for every matching left–right pair. LEFT JOIN returns those same pairs and also preserves each unmatched left row with NULLs in the right-side fields. Later filters can still remove rows from that joined result.
Explore the idea - concept
Database transactions and ACID
A transaction groups transactional changes into commit or rollback. ACID names distinct guarantees whose behavior depends on the database, isolation level and persistence configuration.
Explore the idea - comparison
Object, block and file storage
Object storage addresses named objects by key through an API; block storage exposes addressable logical blocks; file storage presents files and directories through paths and filesystem operations.
Explore the idea - comparison
Database backups, snapshots and consistency
A snapshot can be part of a backup, but its existence proves neither consistency nor recovery. The base copy must meet engine requirements, and required change logs must cover the recovery target.
Explore the idea - concept
Database connection pooling
A database connection pool reuses connections and caps how many callers can borrow them at once. When all usable connections are borrowed, additional callers must wait or fail according to the pool's policy.
Explore the idea - concept
MVCC snapshot visibility across concurrent transactions
In PostgreSQL Repeatable Read, a later commit by another transaction does not change an established snapshot. The reader can still see its own earlier writes.
Explore the idea - concept
Write skew and snapshot isolation anomalies
Two doctors can each see the other on call, update different rows, and leave the roster empty. Write skew is about the rule their decisions share, not a collision between their writes.
Explore the idea - concept
WAL commit durability and crash recovery
A changed page can still be unwritten when a transaction commits. What matters for crash recovery is whether the durable log records both the change and its commit—not just whether the client received a reply.
Explore the idea - concept
B-tree page splits and index amplification
One index insert can change two leaves and their parent. Compare a key that fills the last slot with one that forces a B-tree split, and distinguish changed pages from disk writes.
Explore the idea - comparison
Hash join versus merge join under skew
Compare the same rows two ways: a hash join pays for a build or partition that outgrows memory; a merge join pays for missing input order. See which cost changes without treating either score as runtime.
Explore the idea - troubleshooting
Cardinality-estimation errors and optimizer choices
A lookup can be cheap once and costly when repeated. Compare the plan favored by an estimated row count with the plan favored by the actual count, and see when an estimate error matters.
Explore the idea - concept
Database deadlocks and wait-for graphs
Follow the arrows from waiting transactions to their blockers. A path that loops back explains a lock deadlock; a path that ends can still leave transactions waiting.
Explore the idea - concept
LSM-tree compaction and write amplification
Compaction can shrink a set of sorted runs while increasing total bytes written. Follow a four-run merge to separate the cost of rewriting entries from the benefit of having fewer places to look.
Explore the idea - troubleshooting
Hot partitions and shard-key skew
Two shards can own two keys each yet receive 100 requests on one and 20 on the other. Follow one popular key to see why moving it changes the busy shard without dividing its demand.
Explore the idea - procedure
Change-data-capture offsets and replays
A CDC checkpoint tells a consumer where to resume, not which effects survived. Compare it with durable effects and retained history to distinguish a harmless reread from a repeated effect, skipped work, or a gap.
Explore the idea - comparison
File checksums: corruption detection versus authenticity
A checksum can show that a file’s digest agrees with a reference value. It cannot identify the supplier: trust in the reference must come from separate evidence, such as a signature verified with a trusted publisher key.
Explore the idea - comparison
Replication versus erasure coding for stored data
Three complete replicas use 3× the logical capacity and need one intact copy. An ideal 3+2 erasure code uses 5/3 as much space as the logical data and needs three intact shards. Placement determines which members survive a domain loss.
Explore the idea - concept
Block deduplication and shared-data references
Deduplication saves data space when multiple file positions refer to one stored copy of identical bytes. Deleting a file makes only blocks that lose their last reference reclaimable, which may mean none at all.
Explore the idea - concept
Storage compression and effective capacity
Raw disk size sets a space limit, not a compression ratio. Effective capacity depends on how much of each kind of data you store, the ratio each achieves, and the space needed for metadata.
Explore the idea - concept
Thin provisioning and storage-pool exhaustion
Thin volumes can advertise more blocks than their shared pool contains. Even when a volume has free logical addresses, a write that needs a new backing block can run into a full pool.
Explore the idea - concept
Sparse files: logical size versus allocated blocks
A sparse file’s holes read as zeros without requiring data blocks. A copy that stores those zeros in allocated blocks can use more disk space than the original while keeping the same bytes and logical length.
Explore the idea - comparison
Full, incremental and differential backups
To restore a full point, you need its full set. A differential needs its full base plus the chosen differential. An incremental needs the chosen increment and its predecessor chain back to the full base.
Explore the idea - comparison
Logical database dumps versus physical backups
A logical dump can preserve one database’s objects and rows without its cluster-wide roles. A complete physical backup preserves the cluster as files, but direct use depends on a compatible PostgreSQL version and environment.
Explore the idea - concept
Backup retention and restore dependencies
An old base can supply blocks a newer recovery point still needs through an intermediate backup. Keep the whole dependency chain, even when the base predates the retention window.
Explore the idea - concept
Object versioning and delete markers
With Amazon S3 versioning enabled, a simple delete hides the object behind a current delete marker. Earlier data versions remain stored and can still be read by version ID if access permits.
Explore the idea - concept
Object retention locks and legal holds
In versioned S3, an expired retention deadline does not authorize deletion. A legal hold still blocks removal of that version, and with the hold off, deletion still requires permission.
Explore the idea - concept
Multipart uploads: parts, completion and abandoned data
A multipart upload becomes an object only when completion succeeds for the listed parts. If you stop before completion, the parts can remain stored; if writes are still in flight, don’t assume an abort has cleared them.
Explore the idea - concept
Object lifecycle transitions and expiration
In a versioning-enabled S3 bucket, check the rule against the version it targets and the age clock it uses. A match identifies an eligible action, not proof of deletion, transition, or retrieval readiness.
Explore the idea - comparison
Synchronous versus asynchronous database replication
In PostgreSQL 18, asynchronous replication needs no standby reply. With a synchronous standby selected, the primary waits for its own flush plus the standby’s OS write, durable flush, or replay, depending on the commit policy.
Explore the idea - troubleshooting
Replica lag and read-your-writes behavior
Your next read can reach a replica before it replays your acknowledged write. To establish read-your-writes, check that replica against the session’s write token and use a snapshot new enough to include the write.
Explore the idea - concept
SQL NULL and three-valued logic
An ordinary comparison with NULL yields UNKNOWN rather than FALSE. WHERE selects only TRUE, so a missing value and a known mismatch can both leave a row out for different reasons.
Explore the idea - concept
Foreign keys and cascading deletes
A foreign-key action can block a parent’s removal, cascade it to referencing children, or keep the children with NULL keys. The resulting rows must still satisfy the applicable constraints.
Explore the idea - comparison
SQL DECIMAL versus floating-point types
PostgreSQL NUMERIC rounds to the declared decimal scale, then checks whether the result fits the precision. Binary floating point represents a different set of values: a display of 0.1 need not mean an exact tenth.
Explore the idea - concept
Composite index column order
Column order determines which keys form a continuous range. For the same query, a range scan may examine fewer entries in one order than in another while returning exactly the same matches.
Explore the idea - concept
JSON document fields and schema validation
A missing field can fail a presence check. A field set to null is present but, like any value of the wrong type, can fail a type check. An undeclared field fails only if the schema’s policy rejects it.
Explore the idea - concept
Database collations and case-sensitive comparisons
The collation determines how text compares. In SQLite, `A` sorts before `a` under BINARY but ties with it under built-in NOCASE. That tie matters when a unique index uses the same rule.
Explore the idea - comparison
OFFSET versus keyset pagination
Inserts or deletes can shift rows past an offset, causing repeats or omissions. A complete keyset cursor follows saved values instead, but it can still miss a row whose sort key changes. Neither method freezes the list.
Explore the idea - concept
Database normalization and update anomalies
When orders store separate copies of a customer’s current email, changing just one leaves conflicting addresses. Storing the email once under the customer ID lets every order reference the same current value.
Explore the idea - concept
Partition pruning versus row filtering
When a query range shares no values with a partition’s declared range, the database can skip that partition. An overlap keeps the partition in play, but individual rows can still fail the query’s filter.
Explore the idea - comparison
Row-oriented versus column-oriented storage
The same four cells can occupy one block or span four. A field from many rows can touch fewer column blocks, while the fields of one row can touch fewer row blocks. The difference is physical grouping, not result size.
Explore the idea
Read the assumptions and changed conditions before applying any conclusion to a real database or filesystem.