Skip to content

Fix foreign key gene - #1830

Draft
agusaldasoro wants to merge 1 commit into
masterfrom
fix/foreign
Draft

agusaldasoro wants to merge 1 commit into
masterfrom
fix/foreign

Conversation

@agusaldasoro

@agusaldasoro agusaldasoro commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #1829.

Problem

The solver returned foreign key columns as plain value genes (LongGene, StringGene, …), with no link to the action of the referenced row. Z3 makes the value match the referenced primary key, but only at generation time. Once the search mutates either side, the reference breaks. FK repair in SqlActionUtils cannot fix it, because it does not see the column as a foreign key.

The root cause is that findForeignKeys was a stub returning an empty set (// TODO: Implement this method). The Table the solver rebuilt had no foreign keys at all.

Fix

All changes are in SMTLibZ3DbConstraintSolver:

  • findForeignKeys rebuilds the table's foreign keys from the schema with the same rule as SqlInsertBuilder: when the schema names no target columns, the foreign key references the target table's primary key. A foreign key whose table or columns cannot be resolved is skipped.
  • bindForeignKeys turns each foreign key column into a SqlForeignKeyGene bound to the referenced row's action (uniqueIdOfPrimaryKey = that action's insertionId). The referenced row is the earlier row of the target table whose target columns hold the values Z3 assigned to the source columns.
    • Composite foreign keys are matched on all columns together and set otherSourceColumnsInCompositeFK.
    • A column that is both PK and FK is wrapped as SqlPrimaryKeyGene(SqlForeignKeyGene), as SqlActionGeneBuilder does.
    • Referenced rows always come earlier because Fix foreign keys smtlib gen #1829 sorts rows by their dependencies.
  • Fallback. A foreign key keeps plain value genes when:
    • its target columns are not the primary key, which a SqlForeignKeyGene cannot refer to;
    • a row references itself, since no earlier action exists to bind to.
  • Refactor. Building the gene for a single value moved into toValueGene, with no behaviour change.

@agusaldasoro
agusaldasoro added this pull request to stack #1831 October 6, 2026 13:34
Base automatically changed from fix/get-values to master October 6, 2026 18:25
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