| | 1 | = Normalization |
| | 2 | |
| | 3 | == Initial de-normalized relation and functional dependencies |
| | 4 | |
| | 5 | === Global set of attributes |
| | 6 | This represents the initial de-normalized relation before any normalization is applied. |
| | 7 | Attribute names are made unique to avoid duplication. |
| | 8 | {{{ |
| | 9 | R = { |
| | 10 | user_id, username, email, name, surname, full_name, password_hash, user_created_at, |
| | 11 | client_id, is_blocked, blocked_at, blocked_reason, |
| | 12 | admin_id, |
| | 13 | owner_id, |
| | 14 | |
| | 15 | notification_id, notification_type, notification_message, notification_created_at, is_read, |
| | 16 | |
| | 17 | animal_id, animal_name, located_name, species, animal_type, breed, sex, date_of_birth, photo_url, |
| | 18 | |
| | 19 | listing_id, listing_status, listing_created_at, price, listing_description, |
| | 20 | |
| | 21 | saved_user_id, saved_listing_id, |
| | 22 | |
| | 23 | clinic_id, clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city, |
| | 24 | |
| | 25 | application_id, app_name, app_email, app_phone, app_city, app_address, submitted_at, app_status, reviewed_at, reviewed_by, denial_reason, |
| | 26 | |
| | 27 | appointment_id, date_time, appointment_status, notes, |
| | 28 | |
| | 29 | healthrecord_id, hr_type, hr_description, hr_date, |
| | 30 | |
| | 31 | review_id, reviewer_id, rating, comment, review_created_at, updated_at, is_deleted, |
| | 32 | target_user_id, target_clinic_id |
| | 33 | } |
| | 34 | }}} |
| | 35 | |
| | 36 | === Functional dependencies (initial set) |
| | 37 | |
| | 38 | User / specialization |
| | 39 | {{{ |
| | 40 | FD1: user_id → username, email, name, surname, full_name, password_hash, user_created_at |
| | 41 | FD2: client_id → user_id, is_blocked, blocked_at, blocked_reason |
| | 42 | FD3: admin_id → user_id |
| | 43 | FD4: owner_id → client_id |
| | 44 | }}} |
| | 45 | |
| | 46 | Notification |
| | 47 | {{{ |
| | 48 | FD5: notification_id → notification_type, notification_message, notification_created_at, is_read, user_id |
| | 49 | }}} |
| | 50 | |
| | 51 | Vet Clinic / application |
| | 52 | {{{ |
| | 53 | FD6: clinic_id → clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city |
| | 54 | FD7: application_id → app_name, app_email, app_phone, app_city, app_address, submitted_at, app_status, reviewed_at, reviewed_by, denial_reason, clinic_id |
| | 55 | }}} |
| | 56 | |
| | 57 | Animal |
| | 58 | {{{ |
| | 59 | FD8: animal_id → animal_name, located_name, species, animal_type, breed, sex, date_of_birth, photo_url, owner_id |
| | 60 | }}} |
| | 61 | |
| | 62 | Listing |
| | 63 | {{{ |
| | 64 | FD9: listing_id → listing_status, listing_created_at, price, listing_description, animal_id, admin_id |
| | 65 | }}} |
| | 66 | |
| | 67 | Appointment |
| | 68 | {{{ |
| | 69 | FD10: appointment_id → date_time, appointment_status, notes, animal_id, clinic_id |
| | 70 | }}} |
| | 71 | |
| | 72 | Health Record |
| | 73 | {{{ |
| | 74 | FD11: healthrecord_id → hr_type, hr_description, hr_date, animal_id, appointment_id |
| | 75 | }}} |
| | 76 | |
| | 77 | Review and subtypes |
| | 78 | {{{ |
| | 79 | FD12: review_id → reviewer_id, rating, comment, review_created_at, updated_at, is_deleted |
| | 80 | FD13: review_id → target_user_id |
| | 81 | FD14: review_id → target_clinic_id |
| | 82 | }}} |
| | 83 | |
| | 84 | Favorite Listing |
| | 85 | {{{ |
| | 86 | The relation FavoriteListings has composite key (saved_user_id, saved_listing_id) |
| | 87 | and no additional non-trivial functional dependencies. |
| | 88 | }}} |
| | 89 | |
| | 90 | == Candidate keys and primary key selection |
| | 91 | === Determining a candidate key |
| | 92 | To determine a candidate key of the universal de-normalized relation, we must identify a minimal set of identifiers whose closure determines all attributes in R. |
| | 93 | {{{#!comment It is not correct to simply collect all identifiers, because some identifiers are functionally determined by others. For example: |
| | 94 | application_id → clinic_id |
| | 95 | listing_id → animal_id, admin_id |
| | 96 | animal_id → owner_id |
| | 97 | owner_id → client_id |
| | 98 | healthrecord_id → appointment_id, animal_id |
| | 99 | appointment_id → clinic_id, animal_id |
| | 100 | |
| | 101 | |
| | 102 | Therefore, attributes such as clinic_id, animal_id, appointment_id, admin_id, owner_id, and client_id do not need to appear explicitly in the candidate key if they can already be derived from other identifiers. |
| | 103 | }}} |
| | 104 | |
| | 105 | A candidate key for the initial de-normalized relation is: |
| | 106 | |
| | 107 | {{{ |
| | 108 | K = {notification_id, application_id, listing_id, healthrecord_id, review_id, saved_user_id, saved_listing_id} |
| | 109 | }}} |
| | 110 | |
| | 111 | Its closure includes all attributes of R, so it determines the whole relation. |
| | 112 | |
| | 113 | === Closure proof for K |
| | 114 | {{{ |
| | 115 | Let K = {notification_id, application_id, listing_id, healthrecord_id, review_id, saved_user_id, saved_listing_id} |
| | 116 | |
| | 117 | Compute K+: |
| | 118 | Start: K+ = K |
| | 119 | |
| | 120 | From FD5: |
| | 121 | notification_id → notification_type, notification_message, notification_created_at, is_read, user_id |
| | 122 | Add: notification_type, notification_message, notification_created_at, is_read, user_id |
| | 123 | |
| | 124 | From FD1: |
| | 125 | user_id → username, email, name, surname, full_name, password_hash, user_created_at |
| | 126 | Add: username, email, name, surname, full_name, password_hash, user_created_at |
| | 127 | |
| | 128 | From FD7: |
| | 129 | application_id → app_name, app_email, app_phone, app_city, app_address, submitted_at, app_status, reviewed_at, reviewed_by, denial_reason, clinic_id |
| | 130 | Add: app_name, app_email, app_phone, app_city, app_address, submitted_at, app_status, reviewed_at, reviewed_by, denial_reason, clinic_id |
| | 131 | |
| | 132 | From FD6: |
| | 133 | clinic_id → clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city |
| | 134 | Add: clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city |
| | 135 | |
| | 136 | From FD9: |
| | 137 | listing_id → listing_status, listing_created_at, price, listing_description, animal_id, admin_id |
| | 138 | Add: listing_status, listing_created_at, price, listing_description, animal_id, admin_id |
| | 139 | |
| | 140 | From FD3: |
| | 141 | admin_id → user_id |
| | 142 | user_id already belongs to K+ |
| | 143 | |
| | 144 | From FD8: |
| | 145 | animal_id → animal_name, located_name, species, animal_type, breed, sex, date_of_birth, photo_url, owner_id |
| | 146 | Add: animal_name, located_name, species, animal_type, breed, sex, date_of_birth, photo_url, owner_id |
| | 147 | |
| | 148 | From FD4: |
| | 149 | owner_id → client_id |
| | 150 | Add: client_id |
| | 151 | |
| | 152 | From FD2: |
| | 153 | client_id → user_id, is_blocked, blocked_at, blocked_reason |
| | 154 | Add: is_blocked, blocked_at, blocked_reason |
| | 155 | user_id already belongs to K+ |
| | 156 | |
| | 157 | From FD11: |
| | 158 | healthrecord_id → hr_type, hr_description, hr_date, animal_id, appointment_id |
| | 159 | Add: hr_type, hr_description, hr_date, appointment_id |
| | 160 | animal_id already belongs to K+ |
| | 161 | |
| | 162 | From FD10: |
| | 163 | appointment_id → date_time, appointment_status, notes, animal_id, clinic_id |
| | 164 | Add: date_time, appointment_status, notes |
| | 165 | animal_id and clinic_id already belong to K+ |
| | 166 | |
| | 167 | From FD12: |
| | 168 | review_id → reviewer_id, rating, comment, review_created_at, updated_at, is_deleted |
| | 169 | Add: reviewer_id, rating, comment, review_created_at, updated_at, is_deleted |
| | 170 | |
| | 171 | From FD13: |
| | 172 | review_id → target_user_id |
| | 173 | Add: target_user_id |
| | 174 | |
| | 175 | From FD14: |
| | 176 | review_id → target_clinic_id |
| | 177 | Add: target_clinic_id |
| | 178 | }}} |
| | 179 | |
| | 180 | Therefore, K+ = R, so K is a superkey. |
| | 181 | |
| | 182 | K is also minimal, because removing any attribute from K would cause the loss of one independent component of the universal relation |
| | 183 | {{{#!comment |
| | 184 | * without notification_id, notification attributes cannot be derived |
| | 185 | * without application_id, application attributes cannot be derived |
| | 186 | * without listing_id, listing attributes cannot be derived |
| | 187 | * without healthrecord_id, health record attributes cannot be derived |
| | 188 | * without review_id, review attributes cannot be derived |
| | 189 | * without saved_user_id or saved_listing_id, the FavoriteListings relationship cannot be identified |
| | 190 | }}} |
| | 191 | |
| | 192 | So K is a candidate key. |
| | 193 | |
| | 194 | === Chosen primary key |
| | 195 | We select the candidate key above as the primary key of the initial de-normalized relation: |
| | 196 | |
| | 197 | {{{ |
| | 198 | {notification_id, application_id, listing_id, healthrecord_id, review_id, saved_user_id, saved_listing_id} |
| | 199 | }}} |
| | 200 | |
| | 201 | == Normal form checks |
| | 202 | |
| | 203 | === Check for 1NF |
| | 204 | R satisfies 1NF because all attributes are atomic and there are no repeating groups. |
| | 205 | Each row is uniquely identified by the chosen composite candidate key. |
| | 206 | |
| | 207 | === Check for 2NF |
| | 208 | R does not satisfy 2NF because it has a composite primary key and many non-key attributes depend only on part of that key rather than on the whole key. |
| | 209 | |
| | 210 | Examples: |
| | 211 | * listing_id → listing_status, listing_created_at, price, listing_description |
| | 212 | * animal_id → animal_name, species, breed, sex, date_of_birth, photo_url, owner_id |
| | 213 | * clinic_id → clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city |
| | 214 | * review_id → reviewer_id, rating, comment, review_created_at, updated_at, is_deleted |
| | 215 | * notification_id → notification_type, notification_message, notification_created_at, is_read, user_id |
| | 216 | |
| | 217 | These are partial dependencies on components of the composite key, so R violates 2NF. |
| | 218 | |
| | 219 | == Decomposition to 2NF |
| | 220 | |
| | 221 | === Grouping by determinants (partial dependencies) |
| | 222 | * user_id → username, email, name, surname, full_name, password_hash, user_created_at |
| | 223 | * client_id → user_id, is_blocked, blocked_at, blocked_reason |
| | 224 | * admin_id → user_id |
| | 225 | * owner_id → client_id |
| | 226 | * notification_id → notification_type, notification_message, notification_created_at, is_read, user_id |
| | 227 | * clinic_id → clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city |
| | 228 | * application_id → app_name, app_email, app_phone, app_city, app_address, submitted_at, app_status, reviewed_at, reviewed_by, denial_reason, clinic_id |
| | 229 | * animal_id → animal_name, located_name, species, animal_type, breed, sex, date_of_birth, photo_url, owner_id |
| | 230 | * listing_id → listing_status, listing_created_at, price, listing_description, animal_id, admin_id |
| | 231 | * appointment_id → date_time, appointment_status, notes, animal_id, clinic_id |
| | 232 | * healthrecord_id → hr_type, hr_description, hr_date, animal_id, appointment_id |
| | 233 | * review_id → reviewer_id, rating, comment, review_created_at, updated_at, is_deleted |
| | 234 | * review_id → target_user_id / target_clinic_id |
| | 235 | * FavoriteListings has key (saved_user_id, saved_listing_id) only |
| | 236 | |
| | 237 | === 2NF relations (first decomposition) |
| | 238 | * Users(user_id, username, email, name, surname, full_name, password_hash, user_created_at) |
| | 239 | * Clients(client_id, user_id, is_blocked, blocked_at, blocked_reason) |
| | 240 | * Admins(admin_id, user_id) |
| | 241 | * Owners(owner_id, client_id) |
| | 242 | * Notifications(notification_id, user_id, notification_type, notification_message, notification_created_at, is_read) |
| | 243 | * VetClinics(clinic_id, clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city) |
| | 244 | * VetClinicApplications(application_id, clinic_id, app_name, app_email, app_phone, app_city, app_address, submitted_at, app_status, reviewed_at, reviewed_by, denial_reason) |
| | 245 | * Animals(animal_id, owner_id, animal_name, located_name, species, animal_type, breed, sex, date_of_birth, photo_url) |
| | 246 | * Listings(listing_id, admin_id, animal_id, listing_status, listing_created_at, price, listing_description) |
| | 247 | * Appointments(appointment_id, clinic_id, animal_id, date_time, appointment_status, notes) |
| | 248 | * HealthRecords(healthrecord_id, appointment_id, animal_id, hr_type, hr_description, hr_date) |
| | 249 | * Reviews(review_id, reviewer_id, rating, comment, review_created_at, updated_at, is_deleted) |
| | 250 | * FavoriteListings(saved_user_id, saved_listing_id) |
| | 251 | |
| | 252 | {{{Lossless join:}}} |
| | 253 | [[BR]] |
| | 254 | The decomposition is lossless because each new relation is formed from a determinant that becomes the key of that relation. The common attributes used in the decomposition are keys in at least one of the resulting relations, so no information is lost. |
| | 255 | |
| | 256 | {{{Dependency preservation:}}} |
| | 257 | [[BR]] |
| | 258 | The decomposition is dependency-preserving because each functional dependency FD1–FD14 is represented fully inside one of the resulting relations. FavoriteListings has only its composite key and no additional non-trivial dependencies. |
| | 259 | |
| | 260 | == Check for 3NF (and decomposition) |
| | 261 | Now we look for transitive dependencies inside the produced relations. |
| | 262 | |
| | 263 | === Typical transitive issues from the ER |
| | 264 | * In Clients(client_id, user_id, …), we have client_id → user_id, but user descriptive attributes are stored in Users, so no transitive dependency remains inside Clients. |
| | 265 | * In Listings(listing_id, admin_id, animal_id, …), we have listing_id → admin_id and globally admin_id → user_id, but user attributes are stored in Users, not in Listings, so no transitive dependency remains inside Listings. |
| | 266 | * In VetClinicApplications(application_id, clinic_id, …), we have application_id → clinic_id and clinic_id determines clinic attributes, but those attributes are stored in VetClinics, not in VetClinicApplications, so no transitive dependency remains there either. |
| | 267 | |
| | 268 | === Review subtypes (User Review and Clinic Review) |
| | 269 | The ER model contains a specialization of Review into UserReview and ClinicReview. |
| | 270 | If both target_user_id and target_clinic_id are stored in Reviews, the relation mixes subtype-specific semantics and may introduce nulls or invalid combinations. |
| | 271 | So we decompose: |
| | 272 | {{{ |
| | 273 | UserReviews(review_id, target_user_id) |
| | 274 | ClinicReviews(review_id, target_clinic_id) |
| | 275 | }}} |
| | 276 | |
| | 277 | Now: |
| | 278 | * Reviews stores the common review attributes |
| | 279 | * UserReviews stores the target user of a user review |
| | 280 | * ClinicReviews stores the target clinic of a clinic review |
| | 281 | |
| | 282 | === Results after 3NF step |
| | 283 | * UserReviews(review_id, target_user_id) |
| | 284 | * ClinicReviews(review_id, target_clinic_id) |
| | 285 | |
| | 286 | After separating subtype-specific attributes into UserReviews and ClinicReviews, all resulting relations satisfy 3NF. |
| | 287 | |
| | 288 | == Check for BCNF |
| | 289 | Each resulting relation is also in BCNF because, in every non-trivial functional dependency within a relation, the determinant is a superkey of that relation. |
| | 290 | |
| | 291 | * Users: user_id is key → BCNF |
| | 292 | * Clients: client_id is key → BCNF |
| | 293 | * Admins: admin_id is key → BCNF |
| | 294 | * Owners: owner_id is key → BCNF |
| | 295 | * Notifications: notification_id is key → BCNF |
| | 296 | * VetClinics: clinic_id is key → BCNF |
| | 297 | * VetClinicApplications: application_id is key → BCNF |
| | 298 | * Animals: animal_id is key → BCNF |
| | 299 | * Listings: listing_id is key → BCNF |
| | 300 | * Appointments: appointment_id is key → BCNF |
| | 301 | * HealthRecords: healthrecord_id is key → BCNF |
| | 302 | * Reviews: review_id is key → BCNF |
| | 303 | * UserReviews: review_id is key → BCNF |
| | 304 | * ClinicReviews: review_id is key → BCNF |
| | 305 | * FavoriteListings: (saved_user_id, saved_listing_id) is key → BCNF |
| | 306 | {{{So the schema satisfies BCNF.}}} |
| | 307 | |
| | 308 | == Check for 4NF (multivalued dependencies) |
| | 309 | No additional non-trivial multivalued dependencies are identified in the resulting schema. |
| | 310 | The many-to-many relationship FavoriteListing is already decomposed into the separate relation FavoriteListings(saved_user_id, saved_listing_id), so no further decomposition is required for 4NF. |
| | 311 | {{{The schema satisfies 4NF.}}} |
| | 312 | |
| | 313 | == Final relations |
| | 314 | * Users(user_id, username, email, name, surname, full_name, password_hash, user_created_at) |
| | 315 | * Clients(client_id, user_id, is_blocked, blocked_at, blocked_reason) |
| | 316 | * Admins(admin_id, user_id) |
| | 317 | * Owners(owner_id, client_id) |
| | 318 | * Notifications(notification_id, user_id, notification_type, notification_message, notification_created_at, is_read) |
| | 319 | * VetClinics(clinic_id, clinic_name, clinic_email, clinic_phone, clinic_address, clinic_location, clinic_city) |
| | 320 | * VetClinicApplications(application_id, clinic_id, app_name, app_email, app_phone, app_city, app_address, submitted_at, app_status, reviewed_at, reviewed_by, denial_reason) |
| | 321 | * Animals(animal_id, owner_id, animal_name, located_name, species, animal_type, breed, sex, date_of_birth, photo_url) |
| | 322 | * Listings(listing_id, admin_id, animal_id, listing_status, listing_created_at, price, listing_description) |
| | 323 | * FavoriteListings(saved_user_id, saved_listing_id) |
| | 324 | * Appointments(appointment_id, clinic_id, animal_id, date_time, appointment_status, notes) |
| | 325 | * HealthRecords(healthrecord_id, appointment_id, animal_id, hr_type, hr_description, hr_date) |
| | 326 | * Reviews(review_id, reviewer_id, rating, comment, review_created_at, updated_at, is_deleted) |
| | 327 | * UserReviews(review_id, target_user_id) |
| | 328 | * ClinicReviews(review_id, target_clinic_id) |
| | 329 | |
| | 330 | == Conclusion |
| | 331 | The normalization process confirms the same structural design obtained from the ER model in phase 2. |