Skip to content

Fix #445: [Model] AdditionalKey#681

Open
GiggleLiu wants to merge 6 commits intomainfrom
issue-445-additional-key
Open

Fix #445: [Model] AdditionalKey#681
GiggleLiu wants to merge 6 commits intomainfrom
issue-445-additional-key

Conversation

@GiggleLiu
Copy link
Contributor

Summary

Add the AdditionalKey satisfaction problem model from relational database theory (Garey & Johnson A4 SR27). This NP-complete problem asks whether a relational schema has a candidate key not in a given set of known keys.

Fixes #445

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 96.08696% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.03%. Comparing base (dfcc313) to head (262f635).

Files with missing lines Patch % Lines
src/models/misc/additional_key.rs 93.23% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #681      +/-   ##
==========================================
- Coverage   97.04%   97.03%   -0.01%     
==========================================
  Files         284      286       +2     
  Lines       38037    38267     +230     
==========================================
+ Hits        36914    37134     +220     
- Misses       1123     1133      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

GiggleLiu and others added 5 commits March 17, 2026 01:50
Add the Additional Key problem from relational database theory (Garey &
Johnson SR7). Given a relational schema (R, F) and known candidate keys K,
determines whether R has a candidate key not in K.

- Model file with closure computation, minimality check, and known-key filter
- 13 unit tests covering creation, evaluation, edge cases, brute force, serialization
- CLI create support with --num-attributes, --dependencies, --relation-attrs, --known-keys
- Module registration and re-exports
- Canonical example-db entry with regenerated fixtures

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Implement the AdditionalKey satisfaction problem from relational database
theory (Garey & Johnson A4 SR27). Includes model, CLI registration, unit
tests, and example-db entry.
Add problem-def entry, display name, and bibliography reference (Beeri & Bernstein, 1979)
for the Additional Key problem from relational database theory.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GiggleLiu
Copy link
Contributor Author

Implementation Summary

Changes

  • src/models/misc/additional_key.rs — New model: AdditionalKey satisfaction problem (struct, constructor, closure computation, Problem/SatisfactionProblem trait impls, declare_variants!, canonical example-db entry)
  • src/unit_tests/models/misc/additional_key.rs — 13 unit tests (creation, evaluation, brute force, serialization, paper example)
  • src/models/misc/mod.rs — Module registration + example-db chain
  • src/models/mod.rs — Re-export
  • src/lib.rs — Prelude re-export
  • problemreductions-cli/src/cli.rs — CLI flags (--num-attributes, --dependencies, --relation-attrs, --known-keys)
  • problemreductions-cli/src/commands/create.rspred create AdditionalKey handler
  • src/example_db/fixtures/examples.json — Regenerated with new model
  • docs/paper/reductions.typproblem-def("AdditionalKey") with display name, formal definition, background, and worked example
  • docs/paper/references.bib — Added beeri1979 citation

Deviations from Plan

  • src/unit_tests/trait_consistency.rs was removed in a prior refactor — skipped that step
  • Added AdditionalKey to prelude in src/lib.rs (discovered during spec review)

Open Questions

  • None

Verification

  • make test: 2173 tests passed
  • make clippy: clean
  • make paper: compiles cleanly

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new NP-complete satisfaction model, AdditionalKey, representing the “additional candidate key” problem from relational database theory, and wires it into the library exports, CLI instance creation, examples, and paper.

Changes:

  • Introduce AdditionalKey model (schema registration, evaluation via FD closure + minimality + exclusion from known keys, example-db spec).
  • Add unit tests covering evaluation behavior, brute force solving, and serde round-trip.
  • Extend CLI pred create with new flags/parsing for AdditionalKey, and add an example-db fixture plus paper reference/definition.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/models/misc/additional_key.rs New AdditionalKey model implementation, schema registration, variants declaration, and example-db spec.
src/unit_tests/models/misc/additional_key.rs Unit tests for correctness, solver integration, and serialization.
src/models/misc/mod.rs Registers the new misc module, re-exports AdditionalKey, and includes its example specs.
src/models/mod.rs Re-exports AdditionalKey from models::misc.
src/lib.rs Adds AdditionalKey to the crate prelude exports.
problemreductions-cli/src/cli.rs Adds AdditionalKey CLI flags to CreateArgs and the “Flags by problem type” help section.
problemreductions-cli/src/commands/create.rs Adds AdditionalKey instance parsing/creation and an example invocation string.
src/example_db/fixtures/examples.json Adds an AdditionalKey model fixture with sample/optimal satisfying configs.
docs/paper/references.bib Adds Beeri & Bernstein (1979) reference.
docs/paper/reductions.typ Adds paper definition block and display name mapping for AdditionalKey.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +119 to +125
}
}
// Sort known_keys entries internally for consistent comparison
let known_keys: Vec<Vec<usize>> = known_keys
.into_iter()
.map(|mut k| {
k.sort_unstable();
//! dependencies F) that is not in K. A candidate key is a minimal set of
//! attributes whose closure under F covers all of R.
//!
//! The problem is NP-complete (Garey & Johnson, SR7).
Comment on lines +75 to +76
/// Panics if any attribute index is >= `num_attributes`, or if
/// `relation_attrs` contains duplicates.
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.

[Model] AdditionalKey

2 participants