Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit 86e2da0

Browse files
committed
Rebased onto 'devel' branch and resolved conflicts
Signed-off-by: Serhii Horodilov <sgorodil@gmail.com> # Conflicts: # poetry.lock # requirements.txt
1 parent 6827f99 commit 86e2da0

File tree

6 files changed

+274
-145
lines changed

6 files changed

+274
-145
lines changed

poetry.lock

Lines changed: 120 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ sphinx-intl = "^2.1.0"
3838
sphinx-rtd-theme = "^1.2.0"
3939
myst-parser = "^1.0.0"
4040
sphinxcontrib-bibtex = "^2.5.0"
41+
sphinxcontrib-mermaid = "^0.8.1"
4142

4243
[tool.poetry.dev-dependencies]
4344

requirements.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
alabaster==0.7.13 ; python_version >= "3.9" and python_version < "4.0"
2-
babel==2.11.0 ; python_version >= "3.9" and python_version < "4.0"
2+
babel==2.12.1 ; python_version >= "3.9" and python_version < "4.0"
33
certifi==2022.12.7 ; python_version >= "3.9" and python_version < "4"
4-
charset-normalizer==3.0.1 ; python_version >= "3.9" and python_version < "4"
4+
charset-normalizer==3.1.0 ; python_version >= "3.9" and python_version < "4"
55
click==8.1.3 ; python_version >= "3.9" and python_version < "4.0"
66
colorama==0.4.6 ; python_version >= "3.9" and python_version < "4.0" and sys_platform == "win32" or python_version >= "3.9" and python_version < "4.0" and platform_system == "Windows"
77
docutils==0.18.1 ; python_version >= "3.9" and python_version < "4.0"
88
idna==3.4 ; python_version >= "3.9" and python_version < "4"
99
imagesize==1.4.1 ; python_version >= "3.9" and python_version < "4.0"
10-
importlib-metadata==6.0.0 ; python_version >= "3.9" and python_version < "3.10"
10+
importlib-metadata==6.1.0 ; python_version >= "3.9" and python_version < "3.10"
1111
jinja2==3.1.2 ; python_version >= "3.9" and python_version < "4.0"
1212
latexcodec==2.0.1 ; python_version >= "3.9" and python_version < "4.0"
13-
markdown-it-py==2.1.0 ; python_version >= "3.9" and python_version < "4.0"
13+
markdown-it-py==2.2.0 ; python_version >= "3.9" and python_version < "4.0"
1414
markupsafe==2.1.2 ; python_version >= "3.9" and python_version < "4.0"
1515
mdit-py-plugins==0.3.5 ; python_version >= "3.9" and python_version < "4.0"
1616
mdurl==0.1.2 ; python_version >= "3.9" and python_version < "4.0"
@@ -19,7 +19,6 @@ packaging==23.0 ; python_version >= "3.9" and python_version < "4.0"
1919
pybtex-docutils==1.0.2 ; python_version >= "3.9" and python_version < "4.0"
2020
pybtex==0.24.0 ; python_version >= "3.9" and python_version < "4.0"
2121
pygments==2.14.0 ; python_version >= "3.9" and python_version < "4.0"
22-
pytz==2022.7.1 ; python_version >= "3.9" and python_version < "4.0"
2322
pyyaml==6.0 ; python_version >= "3.9" and python_version < "4.0"
2423
requests==2.28.2 ; python_version >= "3.9" and python_version < "4"
2524
setuptools==67.6.0 ; python_version >= "3.9" and python_version < "4.0"
@@ -31,10 +30,11 @@ sphinx==6.1.3 ; python_version >= "3.9" and python_version < "4.0"
3130
sphinxcontrib-applehelp==1.0.4 ; python_version >= "3.9" and python_version < "4.0"
3231
sphinxcontrib-bibtex==2.5.0 ; python_version >= "3.9" and python_version < "4.0"
3332
sphinxcontrib-devhelp==1.0.2 ; python_version >= "3.9" and python_version < "4.0"
34-
sphinxcontrib-htmlhelp==2.0.0 ; python_version >= "3.9" and python_version < "4.0"
35-
sphinxcontrib-jquery==2.0.0 ; python_version >= "3.9" and python_version < "4.0"
33+
sphinxcontrib-htmlhelp==2.0.1 ; python_version >= "3.9" and python_version < "4.0"
34+
sphinxcontrib-jquery==4.1 ; python_version >= "3.9" and python_version < "4.0"
3635
sphinxcontrib-jsmath==1.0.1 ; python_version >= "3.9" and python_version < "4.0"
36+
sphinxcontrib-mermaid==0.8.1 ; python_version >= "3.9" and python_version < "4.0"
3737
sphinxcontrib-qthelp==1.0.3 ; python_version >= "3.9" and python_version < "4.0"
3838
sphinxcontrib-serializinghtml==1.1.5 ; python_version >= "3.9" and python_version < "4.0"
39-
urllib3==1.26.14 ; python_version >= "3.9" and python_version < "4"
40-
zipp==3.12.0 ; python_version >= "3.9" and python_version < "3.10"
39+
urllib3==1.26.15 ; python_version >= "3.9" and python_version < "4"
40+
zipp==3.15.0 ; python_version >= "3.9" and python_version < "3.10"

src/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"sphinx.ext.imgconverter",
2424

2525
"sphinxcontrib.bibtex",
26+
"sphinxcontrib.mermaid",
2627
"sphinx_rtd_theme",
2728
"myst_parser",
2829
]

src/rdbms/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ tables and views, and monitoring tools for optimizing database performance.
2424
:name: rdbms
2525

2626
aggregation
27+
normalization

src/rdbms/normalization.txt

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
*******************************************************************************
2+
Database Normalization
3+
*******************************************************************************
4+
5+
Normalization is a process of organizing data in a database so that it is free
6+
from redundancy and dependency. It helps to eliminate data inconsistencies and
7+
anomalies, thereby improving data integrity. Normalization is a set of rules or
8+
guidelines to design a database schema in such a way that it avoids data
9+
duplication, data redundancy, and data inconsistency.
10+
11+
There are several normal forms, each building on the previous one, which guide
12+
us in the normalization process. The most commonly used normal forms are:
13+
14+
- **First Normal Form (1NF)**:
15+
Each column should hold atomic (indivisible) values.
16+
There should be no repeating groups or arrays of data in a table.
17+
- **Second Normal Form (2NF)**:
18+
Each non-key column should be functionally dependent on the entire primary
19+
key. In other words, every column in a table should be related to
20+
the primary key and not dependent on any other non-key columns.
21+
- **Third Normal Form (3NF)**:
22+
All non-key columns should be dependent only on the primary key and not on
23+
any other non-key columns. This eliminates transitive dependencies.
24+
25+
Normalization reduces data redundancy and dependency, making the database more
26+
efficient, flexible, and scalable. It also helps in maintaining data
27+
consistency and accuracy, and ensures that updates and deletions are properly
28+
handled.
29+
30+
First normal form (1NF)
31+
=======================
32+
33+
It's easier to understand normalization via examples.
34+
Let's start with some dummy orders data.
35+
36+
.. csv-table:: Initial data
37+
:header-rows: 1
38+
39+
order,customer,product,quantity,price,total
40+
1,"John Doe","(Apple, Orange)","(2, 3)","(100, 50)","(200, 150)"
41+
2,"Jane Smith","Banana",4,25,100
42+
43+
This table violates 1NF, since its columns contain multiple values. To bring
44+
this to 1NF all data within the table are to be atomic.
45+
46+
.. csv-table:: 1NF applied
47+
:header-rows: 1
48+
49+
order,customer,product,quantity,price,total
50+
1,"John Doe","Apple",2,100 ,200
51+
2,"John Doe","Orange",3,50 ,150
52+
3,"Jane Smith","Banana",4,25,100
53+
54+
From now each peace of data is represented as atomic value.
55+
56+
Second normal form (2NF)
57+
========================
58+
59+
The table above is in 1NF, but ``item price`` is dependent on the *item* entity
60+
itself and have low cohesion to *orders*. To bring it into 2NF a dedicated
61+
table to store information about items themselves is to be created. After that
62+
``order`` and ``product`` table are connected (related) to each other via a
63+
foreign key.
64+
65+
.. csv-table:: ``order`` table
66+
:header-rows: 1
67+
68+
id, customer, product_id, quantity
69+
1, "John Doe", 1, 2
70+
2, "John Doe", 2, 3
71+
3, "Jane Smith", 3, 4
72+
73+
.. csv-table:: ``product`` table
74+
:header-rows: 1
75+
76+
id, product, price
77+
1, "Apple", 100
78+
2, "Orange", 50
79+
3, "Banana", 25
80+
81+
.. mermaid::
82+
:align: center
83+
84+
erDiagram
85+
ORDER ||--|{ PRODUCT : contains
86+
ORDER {
87+
int id pk
88+
string customer
89+
int product_id fk
90+
int quantity
91+
}
92+
PRODUCT {
93+
int id pk
94+
string name
95+
int price
96+
}
97+
98+
.. note:: ``total`` field is also removed, since now it can be calculated
99+
as product of ``product.price`` and ``order.quantity``.
100+
101+
Third normal form (3NF)
102+
=======================
103+
104+
At last it's time to remove a transitive functional dependency. Customer's name
105+
is not actually dependent on a product, but on a person, who places an order.
106+
107+
.. csv-table:: ``order`` table
108+
:header-rows: 1
109+
110+
id, customer_id, product_id, quantity
111+
1, 1, 1, 2
112+
2, 1, 2, 3
113+
3, 2, 3, 4
114+
115+
.. csv-table:: ``customer`` table
116+
:header-rows: 1
117+
118+
id, customer
119+
1, "John Doe"
120+
3, "Jane Smith"
121+
122+
.. mermaid::
123+
:align: center
124+
125+
erDiagram
126+
CUSTOMER }o--|| ORDER : places
127+
ORDER ||--|{ PRODUCT : contains
128+
ORDER {
129+
int id pk
130+
int customer_id fk
131+
int product_id fk
132+
int quantity
133+
}
134+
PRODUCT {
135+
int id pk
136+
string name
137+
int price
138+
}
139+
CUSTOMER {
140+
int id pk
141+
string name
142+
}

0 commit comments

Comments
 (0)