Skip to content

docs(integrity): stable and injective identification, inherited identity, cascade of whole entities - #321

Open
dimitri-yatsenko wants to merge 10 commits into
mainfrom
docs/normalization-and-integrity
Open

dimitri-yatsenko wants to merge 10 commits into
mainfrom
docs/normalization-and-integrity

Conversation

@dimitri-yatsenko

Copy link
Copy Markdown
Member

Integrity and normalization pages: identification, inherited identity, cascade

Corrects five pages where they misstated the relational workflow model, in each case to text that matches what the released library does (checked against datajoint-python master and v2.3.6). Tier names stay Manual / Imported / Computed here.

explanation/normalization.md

  • Said: the three lenses "converge on the same schema", and the workflow lens is "the tightest" and "the strictest"; "every workflow-normalized schema is in 3NF". Says: each lens catches what the others cannot see, and they are not ranks on one scale. Functional dependencies cannot record when a fact arises, so a table can pass every normal form and still merge workflow steps; a design built entity by entity tends to satisfy the normal forms as a consequence. Why: the page's own order table passes the first two lenses and fails the third, which contradicts convergence, and no result ranks the perspectives.
  • The heading "Workflow normalization is stricter than 3NF" is now "A table in third normal form can still merge workflow steps". The fragment changes; the only link to it in src/ was on the same page and is updated.
  • Said: "Every table represents an entity type that is created at a specific step in a workflow…". Says: "Every table represents the facts about one entity type that come into being at one step of a workflow, and all of its attributes describe that entity as it exists at that step." Why: under the earlier wording, Payment, Shipment, and Delivery read as three entity types. A new paragraph says an entity type can be split across steps and that the tables share its identity, and the order example says the four tables are one entity type keyed by order_id.
  • Said: removal_date=null : date in CageAssignment (under "Fully normalized (correct)") and in GroupAssignment. Says: CageAssignment has no end date, since a move is a new assignment; GroupAssignment is followed by a later table, GroupRemoval, and the assignments in force are GroupAssignment - GroupRemoval. Why: a null that means "not yet" needs an update to fill, which fails the page's own UPDATE test. The page now states the one meaning of null: the value was not provided when the row was created.
  • order_date moves below the --- in Order. With the date in the key, the same order entered under two dates is two entities, and the three later tables inherit a two-attribute key; the page's table already marked only order_id as the key.
  • Said: update1() only "when nothing downstream depends on the attribute being changed". Says: only in a row that nothing depends on, directly or as a part of a master that something depends on, and update1() does not look for dependent rows. Why: a computation reads the whole parent row, and the library checks only that the row exists.
  • AnalysisParams gains contents, so the "versioned configurations" example declares its rows; the Lookup lead says the rows in contents are part of the schema definition.
  • The "Non-optionally" bullet allows a nullable attribute for a value that may be unknown when an instance is entered.

explanation/entity-integrity.md

  • Said: the primary-key constraint "handles" duplicate records, and "the database enforces the first question through the primary-key constraint". Says: the primary key gives uniqueness (no two records share a key, no key value is null). The one-to-one correspondence also needs an identification process that is stable (the same entity always receives the same key) and injective (two entities never receive the same key). An unstable process gives one entity two records, and the key cannot detect it because the keys differ. Why: the page's own table already said the database cannot prevent one entity from having two records.
  • Said: for surrogate keys "the 'real-world process' half of entity integrity does not apply". Says: a key generated afresh at each insertion is injective but not stable, so repeating the insertion creates a second record with no key collision; the key must be generated once per entity and reused. The advice on when to choose a surrogate is unchanged.
  • Added: Inherited identity. A table whose key is inherited whole from one parent identifies no new entities and takes its parent's identification process. Autopopulated masters and their parts inherit identity the same way, provided make() assigns distinct keys to the distinct members it produces.
  • Said: "Partial entity integrity": some applications need only one direction of the mapping. Says: "Entity integrity holds for the entity type a table represents": an Account table has full entity integrity for accounts; a person is a different entity type that it does not identify. Why: the model defines only the two-way correspondence. The #partial-entity-integrity fragment is gone; nothing in src/ links to it.
  • SubjectProfile is "at most one profile per subject", since nothing requires a profile to exist.

explanation/data-integrity.md

  • Said: a constraint "cannot be bypassed"; all seven types are "enforced by the database for every client, always" and are "Unbypassable". Says: the database engine enforces declared constraints (attribute types, required attributes, primary keys, foreign keys) on every write. The seven types are built on these, and some need more: an identification process, insertion of a master with its parts in one transaction, codec validation and cascading deletes that run in the library, and the make() contract. Why: the page itself says Manual master-part atomicity is a convention and that identification is a real-world process, and the library offers allow_direct_insert=True and part_integrity="ignore".
  • Said: "Deletion cascades from master to parts in either case." Says: deleting a master removes all of its parts; a delete that would remove part rows and leave their master is refused by default, and part_integrity="cascade" extends it to the master and all of its parts. Cascade in the referential section is stated as everything downstream.
  • Said: "populate() walks this graph". Says: each table's populate() computes the keys whose upstream rows exist, so populating the tables in dependency order completes the workflow. Why: populate() is a method of one table.
  • The entity-integrity section names the stable and injective identification process and inherited identity.

explanation/referential-integrity.md

  • Said: removing a parent removes "every child… down the whole hierarchy", and "you may always delete a child". Says: deleting a row removes everything downstream, through secondary foreign keys as through primary ones. A master and its parts leave as one entity: a delete issued on a part table, or a cascade that reaches a part through another parent, is refused under the default part_integrity="enforce" and extends to the whole master-part entity under "cascade". A child that is not a part can always be deleted without its parent. The default check compares tables, not rows; the cascade specification lists what it misses.
  • Said: "4. Update restriction on key values… DataJoint does not support updating a primary-key or foreign-key value". Says: "4. Rows are not edited in place": a child row is created in view of its parent row as a whole, so an in-place edit leaves every foreign key satisfied while dependents reflect values that no longer exist. update1() never changes a primary-key value, can change a secondary foreign key, and does not look for dependents. Why: the old claim was untrue for secondary foreign keys (table.py builds the SET list from every non-key attribute). The #4-update-restriction-on-key-values fragment is gone; nothing in src/ links to it.
  • Said: "Nothing external schedules the work". Says: the foreign-key graph determines what may run, what must run first, and what is pending; a person or a scheduler still calls populate() on each table.

how-to/design-primary-keys.md

  • Said: "The primary key is how a table enforces entity integrity". Says: the primary key is the database's part of entity integrity (unique, non-null key values); the correspondence also needs an identification process that gives the same entity the same key every time and never gives two entities the same key. The surrogate-key and auto-increment advice is not touched here.

Left for the library

These statements stay as written, because the library behaves differently from the model and the docs follow the library:

  • Explicit keys, no auto-increment (entity-integrity.md, data-integrity.md). The library accepts auto_increment and serial in a key (declare.py:68) and a constant default on a key attribute (declare.py:1241-1262).
  • Master-part insertion (data-integrity.md, "by convention" for Manual masters). The direct-insert guard covers autopopulated masters only (table.py:874, autopopulate.py:105); a part of any master accepts inserts outside its master's transaction.
  • Default part check on delete. The part_integrity="enforce" post-check is per table, not per row (table.py:1209-1221), as the cascade specification's Limitations section records.
  • update1() does not refuse a row that has dependents (table.py:598-611).
  • Grain and dimensions of autopopulated tables (entity-integrity.md). key_source can be overridden to change granularity (autopopulate.py:247), and jobs.allow_new_pk_fields_in_computed_tables skips the no-new-key check (autopopulate.py:214).
  • Lookup contents. contents rows are inserted only when contents is longer than the table, existing rows are never removed or changed, and runtime inserts are accepted (schemas.py:330-340).

Open

  • Tier names, the surrogate-key advice, and "derived" for computed rows are later changes.
  • relational-workflow-model.md still quotes the earlier wording of the workflow normalization principle.
  • Three fragments changed (listed above). External links to them will open at the top of the page.

Checks

mkdocs build --strict, scripts/check_links.py on the built site, scripts/check_markdown_lists.py, and codespell pass. markdownlint reports the same two unlabelled code fences as on main.

…ion must be stable and injective

State the two properties the identification process needs, add inherited
identity for tables whose key is inherited whole and for autopopulated
tables, and recast partial entity integrity as the choice of the entity
type a table represents. The primary-key how-to states the same split.
… a later table

Quote the workflow normalization principle in its current wording, drop the
claims that the lenses converge and that the workflow lens is the strictest,
replace nullable removal dates with a later table, key the order by order_id
alone, and scope update1 to rows nothing depends on.
…est rests on the library and on process

Replace the unbypassable claim, state cascade as removal of everything
downstream with master-part entities kept whole, and describe populate()
as filling one table.
…aster-part entities whole

Describe part_integrity for deletes that reach a part, retitle the update
effect as rows not edited in place with what update1() does, and say that
populate() is called per table.
… members take keys from make()

- entity-integrity: an autopopulated master and any table keyed whole by a
  parent take identity from upstream; members of an autopopulated master's
  parts are identified by the keys make() assigns.
- data-integrity, referential-integrity: define downstream with master-part
  entities, subject to the part_integrity mode; note that the default check
  compares tables; failed make() keys are held in an error state under job
  reservation.
- normalization: null covers "does not apply"; group assignments end only by
  a GroupRemoval row; drop filler.
- norm-mouse-housing.svg, norm-order-workflow.svg: hover titles match the
  edited definitions (no removal_date; order_date is a secondary attribute).
…ity inherited from one parent; group in the assignment key
datajoint-python#1764 checks rows and refuses before deleting, so drop
"the default check compares tables, not rows" and add a Changed in 2.3.7
note on both pages.
@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Updated for datajoint/datajoint-python#1764, now merged: main merged in, and data-integrity.md and referential-integrity.md no longer say the default check compares tables rather than rows. Each now says the check refuses before anything is deleted, with a "Changed in 2.3.7" note on the old behavior (same wording style as delete-data.md from docs#312). Ready for review.

@dimitri-yatsenko

Copy link
Copy Markdown
Member Author

Two more fixes (2f38277): relational-workflow-model.md now states the workflow normalization principle in the same words as normalization.md, and a blank line separates the "Changed in 2.3.7" note in data-integrity.md from the paragraph after it. With #324 merged, the cascade.md#part_integrity-modes links now land on the updated modes section. Ready for review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant