Erasure
forget, §M14.24 R2
Ez az oldal a nucleus saját dokumentációjából készül, ezért angol nyelvű.
Subject columns. ALTER TABLE t SET SUBJECT (column, …) marks the
columns that say whose a row is — a user, a customer, an agent: any type
— and DROP SUBJECT unmarks them (the owner’s; an unknown column
42703, one named twice 42701; on a partitioned table, not a
partition, 0A000). A memory store’s subject is marked when it is
made. The table record (version 18) keeps them as column positions
after the memory spec; a memory store of version 17 reads as marked.
FORGET SUBJECT value (an expression or a parameter; NULL 23502;
not in a transaction block, 25001, as the scrubbing that will follow
its commit is not transactional) deletes, in one transaction, every row
any subject column of any table names: for each table (partitions
through their parent) and each of its subject columns into whose type
the value casts — 'alice' is none of a bigint column’s rows, 7 is
both a bigint’s and a text‘s '7' — DELETE FROM t WHERE c1 = $1 OR c2 = $1 …, run as the caller: its DELETE (and SELECT) privileges
and its row-level security policies apply, the foreign keys’ actions
and derived rows (chunks, embedding jobs, indexes) follow as for any
delete. Tables are deleted from referencing ones first (among the
subject tables; a cycle in no particular order), so a RESTRICT key
between two of them does not stop it; a key from a table without
subject columns acts as declared (RESTRICT: 23503, the erasure
undone — mark that table, or make its key cascade). All or
nothing: after each delete the rows of the subject left are counted
as the system; any — row security hid them from the caller — refuses
the statement (42501) and nothing is deleted. It returns one row,
erasure (the record’s number), rows (deleted, not counting what
the foreign keys’ actions deleted), scrubbed and found (below).
The scrub (§M14.24 R2b; forget::finish, after the commit, before
the row is sent). A delete leaves a row’s bytes in many places: MVCC
versions and tombstones (an index key holds the indexed values), free
pages (copy-on-write leaves the old page as it was), log segments, an
HNSW graph’s vector pages (a dead node keeps its vector and key until a
consolidation; a consolidated one, until its page is written again), a
text index’s segments (a deleted document’s terms), column segments
(a delete only marks a row), ANALYZE samples, the embedding queue,
and memory: decoded index objects, column segments, a model’s cached
vectors. For every table the delete may have reached — the subject
tables, those referencing them through keys, transitively, and their
partitions — the scrub, as the system:
- rewrites each index method’s structures without the rows gone
(
IndexMethod::scrub): an HNSW graph’s waiting rows sealed and folded, its dead nodes consolidated, thenhnsw::store::Index::scrubzeroes the vector and empties the key of every node cut from the graph whose row is not current, rewriting their vector pages; a text or sparse index’s waiting rows sealed and each segment with deleted documents merged alone (text::index::store::Store::scrub); - rewrites a
columnorrow, columntable’s segments: the delta taken in, each segment with rows marked deleted written again without them (column_store::scrub; a dropped segment leaves the decoded-column cache whenever it is dropped); - takes the statistics’ sample again where the table has one;
- empties the caches keyed by a hash of contents, which cannot be told
by row: decoded index objects (
object_cache::clear) and models’ vectors (models::clear_cache); and blanks the statement statistics’ kept last texts (the index advisor’s samples, memory only) holding the subject (statements::erase, matched as the audit log’s details are, below); - runs the KV store’s scrub (
Kv::scrub, §6.1) over each table’s data, its sample (00 04 id) and its embedding queue (00 17 id,00 18 id), and the audit log’s records when it blanked any: versions purged past history, free pages and the log’s dropped segments zeroed — after the snapshots older than the erasure end (waited for up to 60 s; elsescrubbedis false and the bytes stay until a later scrub or vacuum); - searches every file of the database for the deleted rows’ values
(
Kv::find_bytes,nucleus_storage::scan, §4.6): texts andbyteafrom 8 bytes (whole up to 64 bytes, else 32-byte windows every 128 bytes), vectors as stored and normalized, other extension types’ bytes, arrays’ items — less what the table’s kept rows hold too (the same text or vector found where it rightly is), and bytes of fewer than 8 distinct values (zeros, padding, a sparse vector: found by chance).foundis the number of places still holding one — 0 is the proof the erasure asks for;NULLwhen the scrub did not run through.
What is not scrubbed: the server’s own logs (their texts are masked,
below), files outside the database’s directory (exports, replicas —
each is erased where it is kept; BACKUP’s backups are made unreadable
for the subject by destroying its key, §8.30), a value encoded past
recognition (bit-packed numbers: a layer’s own encoding must drop a
deleted row by construction, which the steps above do), and short
values (under 8 bytes) the search does not look for — they are scrubbed
all the same.
The audit log. Its records of version 2 (§9) hash a detail’s
SHA-256, not the detail: the erasure blanks, in its own transaction,
the detail of each record holding the subject as a literal ('alice')
or the head of one of its rows’ texts (8 bytes or more, as a literal
writes it), and the chain still holds; nc_catalog.audit shows the
detail as NULL and the erasure that blanked it. A record of version 1
(written before) is hashed over its detail and is left as it is.
The erasure record (00 19 <seq>, the last number at 00 1A;
forget::all): when, who (session and current user), the tables with
the rows deleted from each, the rows in all — never a value of the
subject; written in the erasure’s transaction.
nc_catalog.erasures (erasure, at, session_user_name,
user_name, tables text[] — 'notes: 2' —, rows, scrubbed,
found, audit_erased; the record’s version 2 adds the last three)
shows an administrator every record and other roles their own. FORGET is
always in the audit log (as a statement that changes what the database
holds, kind ddl), and every log keeps its text with its constants
masked — strings as '***', numbers as *** (statements::redacted,
which the audit log, the server’s query log and the PostgreSQL front
end use; statement statistics keep normalized texts, constants as
$n). The drivers’ forget_subject / forgetSubject run it. Tests:
tests/forget.rs.