This repository contains the implementation of a database fragmentation system using core chase algorithms for a master's thesis. The system processes medical database records through a multi-step pipeline involving TGD (Tuple Generating Dependencies) generation, security extraction, core chase computation, graph analysis, and data fragmentation.
The system implements a complete pipeline for database fragmentation with the following key components:
- Database Creation and Population (
a1_0_create_fill_db.py) - TGD Generation (
a2_1_sensitive_tgd_information.py) - Security Extraction (
a3_0_move_to_fo.py) - Core Chase Algorithm (
a4_core_chase.py) - Graph Construction (
a5_graph.py) - Path Traversal (
a6_0_traversal.py) - Minimal Union Computation (
a7_minimal_union.py) - Final Fragmentation (
a8_fragmentation.py)
The easiest way to run the complete pipeline is using the benchmark runner:
python bench_runner.pyThis will automatically:
- Create base databases with different patient sizes (250,000, 500,000, 1,000,000)
- Generate TGDs with different rule counts (100, 200, 400)
- Execute the complete pipeline for each combination
- Track runtime performance for each step
- Save results to
bench_results.csv - Perform union verification checks
You can modify the benchmark parameters by editing bench_runner.py:
PATIENTS_LIST = [250_000, 500_000, 1_000_000] # Patient counts to test
TGDS_LIST = [100, 200, 400] # TGD rule counts to testThe benchmark runner creates the following directory structure:
runs/
├── p250000/ # Patient size 250,000
│ ├── fs_base.db # Base source database
│ ├── fo_base.db # Base target database
│ ├── t100/ # 100 TGDs
│ │ ├── fs.db # Working source database
│ │ ├── fo.db # Working target database
│ │ ├── chase.db # Chase result database
│ │ ├── fs_copy.db # Backup for verification
│ │ └── ... # Intermediate files
│ └── t200/ # 200 TGDs
└── bench_results.csv # Performance results
If you want to run the pipeline step by step or customize specific components:
python a1_0_create_fill_db.pyThis creates three databases:
fs_records.db- Source database with medical recordsfo_records.db- Empty target databaseChaseTable.db- Database for chase operations
python a2_1_sensitive_tgd_information.pyGenerates:
rules.txt- TGD rulesC.txt- Security constraints (sensitive information markers)
python a3_0_move_to_fo.pyMoves sensitive data from fs_records.db to fo_records.db based on constraints in C.txt.
python a4_core_chase.pyApplies TGD rules to derive new tuples until a fixpoint is reached.
python a5_graph.pyConstructs dependency graphs and saves them to graphs.txt.
python a6_0_traversal.pyAnalyzes graph paths and saves results to paths.txt.
python a7_minimal_union.pyCalculates the minimal hitting set and saves to union_greedy.txt.
python a8_fragmentation.pyPerforms final data transfer and deletion based on the minimal union.
The check_same_tbl.py utility provides database analysis and verification capabilities.
# Count all tables
python check_same_tbl.py count fs_records.db
# Count specific tables only
python check_same_tbl.py count fs_records.db --tables Patient,Illness,MedicineCheck if the union of two databases equals a third database (FS ∪ FO == FS_original):
# Basic union check
python check_same_tbl.py union fs_records.db fo_records.db fs_copy.db
# Union check with specific options
python check_same_tbl.py union fs_records.db fo_records.db fs_copy.db \
--set \
--tables Patient,Illness \
--sample 10--set: Use set equality instead of multiset (ignores duplicates)--tables TableA,TableB: Only check specific tables--sample N: Show up to N examples when differences are found--no-color: Disable colored output--no-emoji: Disable emoji indicators
Union check (MULTISET): (DB1 ∪ DB2) ?= DB3
DB1 = fs_records.db (fs_records.db)
DB2 = fo_records.db (fo_records.db)
DB3 = fs_copy.db (fs_copy.db)
------------------------------------------------------------------------------
Table DB1 DB2 DB3 Result
------------------------------------------------------------------------------
Patient 1000 0 1000 ✅ MATCH
Illness 850 150 1000 ✅ MATCH
Medicine 750 250 1000 ✅ MATCH
------------------------------------------------------------------------------
PASS — The union of DB1 and DB2 exactly equals DB3.
The system works with a medical database containing the following tables:
- Patient: Name, Age, Gender
- Illness: PatientName, Diagnosis
- Medicine: PatientName, MedName
- Allergy: PatientName, AllergyName
- Insurance: PatientName, InsuranceName
- LabResult: PatientName, TestName
- Appointment: PatientName, AppointmentDate
- Hospital: PatientName, HospitalName
- Treatment: PatientName, TreatmentName
The benchmark runner tracks the following metrics for each step:
generate_tgds: Time to generate TGD rulesextract_to_fo: Time to extract sensitive datacore_chase: Time to execute chase algorithmbuild_graphs: Time to construct dependency graphspaths_union: Time to traverse paths and compute uniontransfer_delete: Time for final fragmentationtotal_runtime: Total execution time
Results are saved in bench_results.csv with timestamps for analysis.
- Python 3.7+
- SQLite3
- Standard library modules:
sqlite3,random,csv,time,pathlib,argparse
The scripts must be run in sequence or use the benchmark runner. Each step depends on outputs from previous steps:
a1 → creates databases
a2 → creates rules.txt, C.txt
a3 → uses C.txt, modifies databases
a4 → uses rules.txt, chase.db
a5 → uses rules.txt, C.txt, chase.db → creates graphs.txt
a6 → uses graphs.txt, databases → creates paths.txt
a7 → uses paths.txt → creates union_greedy.txt
a8 → uses union_greedy.txt, modifies databases
This implementation is part of a master's thesis on database fragmentation using core chase algorithms. For questions or issues, please refer to the thesis documentation or contact the author.