| 1 | == Нормализација |
| 2 | |
| 3 | За табелите од нашата база на податоци, со цел разликување на самите id за секој ентитет, ќе ги преименуваме id атрибутите во <име_на_релација>_id. Со тоа добиваме: |
| 4 | user_id, property_id, property_type_id, property_image_id, unit_id, listing_id, lease_id, payment_id, payment_method_id, tenant_profile_id, landlord_profile_id, service_request_id, service_category_id, maintenance_log_id, inspection_id, document_id, address_id, message_id, unit_image_id |
| 5 | |
| 6 | **user_id** -> first_name, last_name, email, password_hash, date_of_birth, rating, address_id, bio [[br]] |
| 7 | **property_id** -> property_title, property_description, created_at, user_id, property_type_id, address_id [[br]] |
| 8 | **property_type_id** -> property_type_name [[br]] |
| 9 | **property_image_id** -> property_image, property_id [[br]] |
| 10 | **unit_id** -> unit_number, floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, property_id [[br]] |
| 11 | **listing_id** -> listing_title, available_from, available_to, listing_status, listing_description, unit_id [[br]] |
| 12 | **lease_id** -> start_date, end_date, lease_rent_amount, deposit_amount, listing_id, tenant_profile_id, landlord_profile_id [[br]] |
| 13 | **payment_id** -> amount, payment_status, payment_date, lease_id, payment_method_id [[br]] |
| 14 | **payment_method_id** -> payment_method_name [[br]] |
| 15 | **landlord_profile_id** -> managed_properties_count, is_agent [[br]] |
| 16 | **service_request_id** -> service_description, request_date, service_status, lease_id, service_category_id [[br]] |
| 17 | **service_category_id** -> service_category_name [[br]] |
| 18 | **maintenance_log_id** -> maintenance_description, maintenance_date, service_request_id [[br]] |
| 19 | **inspection_id** -> inspection_date, notes, lease_id, landlord_profile_id [[br]] |
| 20 | **document_id** -> file_type, file_url, uploaded_at, user_id, lease_id [[br]] |
| 21 | **address_id** -> street, municipality, city, number, country [[br]] |
| 22 | **message_id** -> sent_at, content, user_id, user_id, lease_id [[br]] |
| 23 | **unit_image_id** -> unit_image, unit_id [[br]] |
| 24 | **tenant_profile_id** -> / [[br]] |
| 25 | **listing_id, tenant_profile_id** -> / [[br]] |
| 26 | |
| 27 | user_id се спомнува два пати кај ФЗ со message_id од левата страна поради тоа што имаме испраќач и примач на порака. |
| 28 | |
| 29 | **R** = { user_id, first_name, last_name, email, password_hash, date_of_birth, rating, address_id, bio, tenant_profile_id, property_id, property_title, property_description, created_at, property_type_id, property_type_name, property_image_id, property_image, unit_id, unit_number, floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, unit_image_id, unit_image, listing_id, listing_title, available_from, available_to, listing_status, listing_description, lease_id, start_date, end_date, lease_rent_amount, deposit_amount, landlord_profile_id, managed_properties_count, is_agent, payment_id, amount, payment_status, payment_date, payment_method_id, payment_method_name, service_request_id, service_description, request_date, service_status, service_category_id, service_category_name, maintenance_log_id, maintenance_description, maintenance_date, inspection_id, inspection_date, notes, document_id, file_type, file_url, uploaded_at, street, municipality, city, number, country, message_id, sent_at, content } |
| 30 | |
| 31 | Лево |
| 32 | property_image_id |
| 33 | payment_id |
| 34 | maintenance_log_id |
| 35 | inspection_id |
| 36 | document_id |
| 37 | message_id |
| 38 | unit_image_id |
| 39 | tenant_profile_id |
| 40 | |
| 41 | Лево и десно |
| 42 | user_id |
| 43 | property_id |
| 44 | property_type_id |
| 45 | unit_id |
| 46 | listing_id |
| 47 | lease_id |
| 48 | landlord_profile_id |
| 49 | payment_method_id |
| 50 | service_request_id |
| 51 | service_category_id |
| 52 | address_id |
| 53 | |
| 54 | |
| 55 | |
| 56 | Десно |
| 57 | first_name, last_name, email, password_hash, date_of_birth, rating, bio, property_title, property_description, created_at, property_type_name, property_image, unit_number, floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, listing_title, available_from, available_to, listing_status, listing_description, start_date, end_date, lease_rent_amount, deposit_amount, amount, payment_status, payment_date, payment_method_name, managed_properties_count, is_agent, service_description, request_date, service_status, service_category_name, maintenance_description, maintenance_date, inspection_date, notes, file_type, file_url, uploaded_at, street, municipality, city, number, country, sent_at, content, unit_image |
| 58 | |
| 59 | |
| 60 | === Покривачи за 8-те атрибути: |
| 61 | 1.** property_image_id+** = {property_image_id, property_image, property_id, property_title, property_description, created_at, user_id, property_type_id, address_id, property_type_name, street, municipality, city, number, country, first_name, last_name, email, password_hash, date_of_birth, rating, bio} **-Не ги содржи сите атрибути.** |
| 62 | |
| 63 | 2.** payment_id+** = {payment_id, amount, payment_status, payment_date, lease_id,payment_method_id, payment_method_name, start_date, end_date, lease_rent_amount, |
| 64 | deposit_amount, listing_id, tenant_profile_id, landlord_profile_id, listing_title, available_from, |
| 65 | available_tod, listing_status, listing_description, unit_id, unit_number, floor, bedrooms, |
| 66 | bathrooms, area_sq_m, unit_rent_amount, property_id, managed_properties_count, is_agent, |
| 67 | user_id, property_title, property_description, created_at, property_type_id, address_id, |
| 68 | property_type_name, street, municipality, city, number, country, first_name, last_name, email, |
| 69 | password_hash, date_of_birth, rating, bio} **-Не ги содржи сите атрибути.** |
| 70 | |
| 71 | 3.** maintenance_log_id+** = {maintenance_log_id, maintenance_description,maintenance_date,service_request_id, service_description, request_date, service_status, lease_id, |
| 72 | service_category_id, service_category_name, start_date, end_date, lease_rent_amount, |
| 73 | deposit_amount, listing_id, tenant_profile_id, landlord_profile_id, managed_properties_count, |
| 74 | is_agent, user_id, first_name, last_name, email, password_hash, date_of_birth, rating, |
| 75 | address_id, bio, street, municipality, city, number, country, listing_title, available_from, |
| 76 | available_to, listing_status, listing_description, unit_id, unit_number, floor, bedrooms, |
| 77 | bathrooms, area_sq_m, unit_rent_amount, property_id, property_title, property_description, |
| 78 | created_at, property_type_id, property_type_name} **-Не ги содржи сите атрибути.** |
| 79 | |
| 80 | 4.** inspection_id+** = {inspection_id, inspection_date, notes, lease_id, landlord_profile_id, |
| 81 | managed_properties_count, is_agent, start_date, end_date, lease_rent_amount, |
| 82 | deposit_amount, listing_id, tenant_profile_id, user_id, first_name, last_name, email, |
| 83 | password_hash, date_of_birth, rating, address_id, bio, street, municipality, city, number, country, |
| 84 | listing_title, available_from, available_to, listing_status, listing_description, unit_id, unit_number, |
| 85 | floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, property_id, property_title, |
| 86 | property_description, created_at, property_type_id, property_type_name} **-Не ги содржи сите |
| 87 | атрибути. ** |
| 88 | |
| 89 | 5.**document_id+** = {document_id, file_type, file_url, uploaded_at, user_id, lease_id, |
| 90 | first_name, last_name, email, password_hash, date_of_birth, rating, address_id, bio, street, |
| 91 | municipality, city, number, country, start_date, end_date, lease_rent_amount, deposit_amount, |
| 92 | listing_id, tenant_profile_id, landlord_profile_id, managed_properties_count, is_agent, |
| 93 | listing_title, available_from, available_to, listing_status, listing_description, unit_id, unit_number, |
| 94 | floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, property_id, property_title, |
| 95 | property_description, created_at, property_type_id, property_type_name} **-Не ги содржи сите |
| 96 | атрибути.** |
| 97 | |
| 98 | 6.** message_id+** = {message_id, sent_at, content, user_id, lease_id, first_name, last_name, |
| 99 | email, password_hash, date_of_birth, rating, address_id, bio, street, municipality, city, number, |
| 100 | country, start_date, end_date, lease_rent_amount, deposit_amount, listing_id, tenant_profile_id, |
| 101 | landlord_profile_id, managed_properties_count, is_agent, listing_title, available_from, |
| 102 | available_to, listing_status, listing_description, unit_id, unit_number, floor, bedrooms, |
| 103 | bathrooms, area_sq_m, unit_rent_amount, property_id, property_title, property_description, |
| 104 | created_at, property_type_id, property_type_name} **-Не ги содржи сите атрибути.** |
| 105 | |
| 106 | 7.** unit_image_id+** = {unit_image_id, unit_image, unit_id, unit_number, floor, bedrooms, |
| 107 | bathrooms, area_sq_m, unit_rent_amount, property_id, property_title, property_description, |
| 108 | created_at, user_id, property_type_id, address_id, first_name, last_name, email, |
| 109 | password_hash, date_of_birth, rating, bio, street, municipality, city, number, country, |
| 110 | property_type_name}**-Не ги содржи сите атрибути.** |
| 111 | |
| 112 | 8.** tenant_profile_id+** = {tenant_profile_id, user_id, first_name, last_name, email, |
| 113 | password_hash, date_of_birth, rating, address_id, bio, street, municipality, city, number, |
| 114 | country} **-Не ги содржи сите атрибути.** |
| 115 | |
| 116 | |
| 117 | ==== Започнуваме со комбинирање на покривачите за да дојдеме до сите атрибути: |
| 118 | 1.** {property_image_id, payment_id}+** = {property_image_id, property_image, property_id, |
| 119 | property_title, property_description, created_at, user_id, property_type_id, address_id, |
| 120 | property_type_name, street, municipality, city, number, country, first_name, last_name, email, |
| 121 | password_hash, date_of_birth, rating, bio, payment_id, amount, payment_status, |
| 122 | payment_date, lease_id, payment_method_id, payment_method_name, start_date, end_date, |
| 123 | lease_rent_amount, deposit_amount, listing_id, tenant_profile_id, landlord_profile_id, |
| 124 | listing_title, available_from, available_to, listing_status, listing_description, unit_id, unit_number, |
| 125 | floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, managed_properties_count, |
| 126 | is_agent} **-Не ги содржи сите атрибути.** |
| 127 | |
| 128 | 2.** {property_image_id, payment_id, maintenance_log_id}+** = {property_image_id, |
| 129 | property_image, property_id, property_title, property_description, created_at, user_id, |
| 130 | property_type_id, address_id, property_type_name, street, municipality, city, number, country, |
| 131 | first_name, last_name, email, password_hash, date_of_birth, rating, bio, payment_id, amount, |
| 132 | payment_status, payment_date, lease_id, payment_method_id, payment_method_name, |
| 133 | start_date, end_date, lease_rent_amount, deposit_amount, listing_id, tenant_profile_id, |
| 134 | landlord_profile_id, managed_properties_count, is_agent, listing_title, available_from, |
| 135 | available_to, listing_status, listing_description, unit_id, unit_number, floor, bedrooms, |
| 136 | bathrooms, area_sq_m, unit_rent_amount, maintenance_log_id, maintenance_description, |
| 137 | maintenance_date, service_request_id, service_description, request_date, service_status, |
| 138 | service_category_id, service_category_name} **-Не ги содржи сите атрибути. ** |
| 139 | |
| 140 | 3.** {property_image_id, payment_id, maintenance_log_id, inspection_id}+** = Со ова на |
| 141 | претходните се додаваат: inspection_id, inspection_date, notes **-Не ги содржи сите |
| 142 | атрибути.** |
| 143 | |
| 144 | 4.** {property_image_id, payment_id, maintenance_log_id, inspection_id, document_id}+**= Со |
| 145 | ова на претходните се додаваат: document_id, file_type, file_url, uploaded_at -Не ги |
| 146 | содржи сите атрибути. |
| 147 | |
| 148 | 5.** {property_image_id, payment_id, maintenance_log_id, inspection_id, document_id, |
| 149 | message_id}+** = Со ова на претходните се додаваат: message_id, sent_at, content ** -Не ги |
| 150 | содржи сите атрибути.** |
| 151 | |
| 152 | 6.** {property_image_id, payment_id, maintenance_log_id, inspection_id, document_id, |
| 153 | message_id, unit_image_id}+**= Со ова на претходните се додаваат: message_id, sent_at, |
| 154 | content unit_image_id, unit_image **- Ги содржи сите атрибути!** |
| 155 | |
| 156 | Во овааа релација нема повеќекратни зависности и истата ја задоволува 1НФ. |
| 157 | Оваа релација не задоволува 2НФ поради постоење на парцијални зависности. |
| 158 | == Декомпозиција во 2НФ |
| 159 | За да ги отстраниме парцијалните зависности потребно е да ги оделиме атрибутите во |
| 160 | релации во кои целосно ќе зависат од нивниот клуч па тоа би го сториле на следен |
| 161 | начин: |
| 162 | 1. property_image_id → property_image, property_id |
| 163 | 2. payment_id → amount, payment_status, payment_date, lease_id, payment_method_id |
| 164 | 3. maintenance_log_id → maintenance_description, maintenance_date, |
| 165 | service_request_id |
| 166 | 4. inspection_id → inspection_date, notes, lease_id, landlord_profile_id |
| 167 | 5. document_id → file_type, file_url, uploaded_at, user_id, lease_id |
| 168 | 6. message_id → sent_at, content, user_id, lease_id |
| 169 | 7. unit_image_id → unit_image, unit_id |
| 170 | 8. tenant_profile_id → user_id |
| 171 | == Декомпозиција во релации |
| 172 | Овдека првин ќе ги извдоиме самите релации од погоре, но за самата декомпозиција да |
| 173 | може да се изведе подоцна, ќе ги издвоиме и релациите со примарни клучеви: |
| 174 | payment_method_id, service_category_id и service_request_id, односно релациите R1, R2 и |
| 175 | R5. Со ваква организација ќе ги тргнеме атрибутите пред самите клучеви кои ќе бидат |
| 176 | отстранети подоцна во релациите R5 (за service_category_id), R6 (за service_request_id) и |
| 177 | R4 (за payment_method_id). Конкретно, релациите ќе ги издвоиме поради следните |
| 178 | транзитивни зависности со кои не постигнуваме 3НФ: |
| 179 | * payment_method_id → payment_method_name |
| 180 | * service_category_id → service_category_name |
| 181 | * service_request_id → service_description, request_date, service_status, lease_id, service_category_id |
| 182 | **R1 {payment_method_id, payment_method_name}** |
| 183 | |
| 184 | **R2 {service_category_id, service_category_name}** |
| 185 | |
| 186 | **R3 {property_image_id, property_image, property_id} - во BCNF |
| 187 | |
| 188 | **R4 {payment_id, amount, payment_status, payment_date, lease_id, payment_method_id}-во BCNF |
| 189 | |
| 190 | **R5 {service_request_id, service_description, request_date, service_status, lease_id, |
| 191 | service_category_id } |
| 192 | |
| 193 | **R6 {maintenance_log_id, maintenance_description, maintenance_date, |
| 194 | service_request_id} - во BCNF |
| 195 | |
| 196 | **R7 {inspection_id, inspection_date, notes, lease_id, landlord_profile_id} - во BCNF |
| 197 | |
| 198 | **R8 {document_id, file_type, file_url, uploaded_at, user_id, lease_id} - во BCNF |
| 199 | |
| 200 | **R9 {message_id, sent_at, content, user_id, lease_id} - во BCNF |
| 201 | |
| 202 | **R10 {unit_image_id, unit_image, unit_id} - во BCNF |
| 203 | |
| 204 | **R11 {tenant_profile_id, user_id} - во BCNF |
| 205 | |
| 206 | **R12** - остатокот од атрибутите: {property_image_id, payment_id, maintenance_log_id, |
| 207 | inspection_id, document_id, message_id, unit_image_id, tenant_profile_id, property_id, |
| 208 | property_type_id, unit_id, listing_id, lease_id, landlord_profile_id, address_id, user_id, |
| 209 | property_title, property_description, created_at, property_type_name, unit_number, floor, |
| 210 | bedrooms, bathrooms, area_sq_m, unit_rent_amount, listing_title, available_from, available_to, |
| 211 | listing_status, listing_description, start_date, end_date, lease_rent_amount, deposit_amount, |
| 212 | managed_properties_count, is_agent, street, municipality, city, number, country, first_name, |
| 213 | last_name, email, password_hash, date_of_birth, rating, bio} |
| 214 | |
| 215 | === Проверка на 3НФ за R12 |
| 216 | R12 не е во 3НФ поради следните транзитивни зависности: |
| 217 | |
| 218 | **Транзитивна зависност : property_id → user_id, property_type_id, address_id, |
| 219 | property_title, property_description, created_at |
| 220 | |
| 221 | R12.1 {property_id, user_id, property_type_id, address_id, property_title, property_description, |
| 222 | created_at} - не е во 3НФ |
| 223 | R12.1 не е во 3НФ поради: |
| 224 | • property_type_id → property_type_name |
| 225 | • address_id → street, municipality, city, number, country |
| 226 | • user_id → first_name, last_name, email, password_hash, date_of_birth, rating, bio |
| 227 | R12.1.1 {property_type_id, property_type_name} - во BCNF |
| 228 | R12.1.2 {address_id, street, municipality, city, number, country} - во BCNF |
| 229 | R12.1.3 {user_id, first_name, last_name, email, password_hash, date_of_birth, rating, |
| 230 | bio} - во BCNF |
| 231 | R12.1.4 {property_id, user_id, property_type_id, address_id, property_title, |
| 232 | property_description, created_at} - во BCNF |
| 233 | Во R12.2 остануваат сите атрибути кои ги нема во претходните релации. |
| 234 | R12.2 - {property_image_id, payment_id, maintenance_log_id, inspection_id, document_id, |
| 235 | message_id, unit_image_id, tenant_profile_id, property_id, unit_id, listing_id, lease_id, |
| 236 | landlord_profile_id, unit_number, floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, |
| 237 | listing_title, available_from, available_to, listing_status, listing_description, start_date, end_date, |
| 238 | lease_rent_amount, deposit_amount, managed_properties_count, is_agent}. |
| 239 | -------------------------------------------------------------------------------------------------- |
| 240 | R12.2 не е во 3НФ бидејќи unit_id → unit_number, floor, bedrooms, bathrooms, area_sq_m, |
| 241 | unit_rent_amount, property_id. |
| 242 | R12.2.1 {unit_id, unit_number, floor, bedrooms, bathrooms, area_sq_m, |
| 243 | unit_rent_amount, property_id} - во BCNF |
| 244 | R12.2.2 {property_image_id, payment_id, maintenance_log_id, inspection_id, document_id, |
| 245 | message_id, unit_image_id, tenant_profile_id, unit_id, listing_id, lease_id, landlord_profile_id, |
| 246 | listing_title, available_from, available_to, listing_status, listing_description, start_date, end_date, |
| 247 | lease_rent_amount, deposit_amount, managed_properties_count, is_agent} |
| 248 | R12.2.2 не е во 3НФ бидејќи listing_id → listing_title, available_from, available_to, |
| 249 | listing_status, listing_description, unit_id |
| 250 | R12.2.2.1 {listing_id, listing_title, available_from, available_to, listing_status, |
| 251 | listing_description, unit_id} - во BCNF |
| 252 | R12.2.2.2 {property_image_id, payment_id, maintenance_log_id, inspection_id, document_id, |
| 253 | message_id, unit_image_id, tenant_profile_id, listing_id, lease_id, landlord_profile_id, |
| 254 | start_date, end_date, lease_rent_amount, deposit_amount, managed_properties_count, |
| 255 | is_agent} |
| 256 | R12.2.2.2 не е во 3НФ бидејќи landlord_profile_id → managed_properties_count, is_agent |
| 257 | R12.2.2.2.1 { landlord_profile_id, managed_properties_count, is_agent } - во BCNF |
| 258 | R12.2.2.2.2 { property_image_id, payment_id, maintenance_log_id, inspection_id, document_id, |
| 259 | message_id, unit_image_id, tenant_profile_id, listing_id, lease_id, landlord_profile_id, |
| 260 | start_date, end_date, lease_rent_amount, deposit_amount} |
| 261 | ------------------------------------------------------- |
| 262 | R12.2.2.2.2 не е во 3НФ бидејќи lease_id -> start_date, end_date, lease_rent_amount, |
| 263 | deposit_amount, listing_id, tenant_profile_id, landlord_profile_id |
| 264 | R12.2.2.2.2.1 {lease_id, start_date, end_date, lease_rent_amount, deposit_amount, |
| 265 | listing_id, tenant_profile_id, landlord_profile_id} - во BCNF |
| 266 | R12.2.2.2.2.2 { property_image_id, payment_id, maintenance_log_id, inspection_id, |
| 267 | document_id, message_id, unit_image_id} - во BCNF |
| 268 | Финални релации во BCNF |
| 269 | 1. Property_Image {property_image_id, property_image, property_id} - во BCNF |
| 270 | 2. Payment {payment_id, amount, payment_status, payment_date, lease_id, |
| 271 | payment_method_id} - во BCNF |
| 272 | 3. Maintenance_Log {maintenance_log_id, maintenance_description, maintenance_date, |
| 273 | service_request_id} - во BCNF |
| 274 | 4. Inspection {inspection_id, inspection_date, notes, lease_id, landlord_profile_id} - во |
| 275 | BCNF |
| 276 | 5. Document {document_id, file_type, file_url, uploaded_at, user_id, lease_id} - во BCNF |
| 277 | 6. Message {message_id, sent_at, content, from_user_id, to_user_id, lease_id} - во BCNF |
| 278 | 7. Unit_Image {unit_image_id, unit_image, unit_id} - во BCNF |
| 279 | 8. Tenant_Profile {tenant_profile_id, user_id} - во BCNF |
| 280 | 9. Property_Type {property_type_id, property_type_name} - во BCNF |
| 281 | 10. Address {address_id, street, municipality, city, number, country} - во BCNF |
| 282 | 11. User {user_id, first_name, last_name, email, password_hash, date_of_birth, rating, bio} |
| 283 | - во BCNF |
| 284 | 12. Property {property_id, user_id, property_type_id, address_id, property_title, |
| 285 | property_description, created_at} - во BCNF |
| 286 | 13. Unit {unit_id, unit_number, floor, bedrooms, bathrooms, area_sq_m, unit_rent_amount, |
| 287 | property_id} - во BCNF |
| 288 | 14. Listing {listing_id, listing_title, available_from, available_to, listing_status, |
| 289 | listing_description, unit_id} - во BCNF |
| 290 | 15. Lease {lease_id, start_date, end_date, lease_rent_amount, deposit_amount, listing_id, |
| 291 | tenant_profile_id, landlord_profile_id} - во BCNF |
| 292 | 16. Landlord_Profile {landlord_profile_id, managed_properties_count, is_agent} - во BCNF |
| 293 | 17. Payment_Method {payment_method_id, payment_method_name} - во BCNF |
| 294 | 18. Service_Request {service_request_id, service_description, request_date, |
| 295 | service_status, lease_id, service_category_id} - во BCNF |
| 296 | 19. Service_Category {service_category_id, service_category_name} - во BCNF |
| 297 | 20. Main_Relation {property_image_id, payment_id, maintenance_log_id, inspection_id, |
| 298 | document_id, message_id, unit_image_id} - во BCNF |
| 299 | 21.Interested {listing_id, tenant_profile_id} - во BCNF |