Compare commits

..
2 Commits
Author SHA1 Message Date
izatwin 51f720ad9f p4 start 2024-04-12 10:39:46 -04:00
izatwin f7697e992f hw4 stuff 2024-04-12 10:39:38 -04:00
17 changed files with 661 additions and 137 deletions
+3 -75
View File
@@ -1,79 +1,7 @@
# Fdb version 4 # Fdb version 4
["pdflatex"] 1709526566.41797 "/home/sean/Documents/College/s06 2024 Spring/CS 448/Homeworks/hw3/SeanRettigHW3.tex" "SeanRettigHW3.pdf" "SeanRettigHW3" 1709526566.68068 0 ["pdflatex"] 0 "/home/sean/Documents/College/s06 2024 Spring/CS 448/Homeworks/hw3/SeanRettigHW3.tex" "SeanRettigHW3.pdf" "SeanRettigHW3" 0 -1
"/home/sean/Documents/College/s06 2024 Spring/CS 448/Homeworks/hw3/SeanRettigHW3.tex" 1709526566.2752 6008 78090232afefa06aee238870a4b5d2c9 "" "/home/sean/Documents/College/s06 2024 Spring/CS 448/Homeworks/hw3/SeanRettigHW3.tex" 0 -1 0 ""
"/usr/share/texlive/texmf-dist/fonts/map/fontname/texfonts.map" 1577235249 3524 cb3e574dea2d1052e39280babc910dc8 "" "SeanRettigHW3.aux" 0 -1 0 "pdflatex"
"/usr/share/texlive/texmf-dist/fonts/tfm/jknappen/ec/tcrm0500.tfm" 1136768653 1536 b3387106d9afecbfe14bde2de6eadf47 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/jknappen/ec/tcrm0600.tfm" 1136768653 1536 12e8c510d3e158fdd0e9a42e75118bd9 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/jknappen/ec/tcrm0700.tfm" 1136768653 1536 73da8e8f1d2a4c957d51ca133585586b ""
"/usr/share/texlive/texmf-dist/fonts/tfm/jknappen/ec/tcrm0800.tfm" 1136768653 1536 05df9db6aeccc4eea94fec15c9024f79 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/jknappen/ec/tcrm1000.tfm" 1136768653 1536 e07581a4bb3136ece9eeb4c3ffab8233 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/jknappen/ec/tcrm1200.tfm" 1136768653 1536 74b7293ec3713bb7fdca8dd1bd1f469c ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/cmextra/cmex7.tfm" 1246382020 1004 54797486969f23fa377b128694d548df ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/cmextra/cmex8.tfm" 1246382020 988 bdf658c3bfc2d96d3c8b02cfc1c94c20 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msam10.tfm" 1246382020 916 f87d7c45f9c908e672703b83b72241a3 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msam5.tfm" 1246382020 924 9904cf1d39e9767e7a3622f2a125a565 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msam7.tfm" 1246382020 928 2dc8d444221b7a635bb58038579b861a ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msbm10.tfm" 1246382020 908 2921f8a10601f252058503cc6570e581 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msbm5.tfm" 1246382020 940 75ac932a52f80982a9f8ea75d03a34cf ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/amsfonts/symbols/msbm7.tfm" 1246382020 940 228d6584342e91276bf566bcf9716b83 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmbx10.tfm" 1136768653 1328 c834bbb027764024c09d3d2bf908b5f0 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmbx12.tfm" 1136768653 1324 c910af8c371558dc20f2d7822f66fe64 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmex10.tfm" 1136768653 992 662f679a0b3d2d53c1b94050fdaa3f50 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi12.tfm" 1136768653 1524 4414a8315f39513458b80dfc63bff03a ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi6.tfm" 1136768653 1512 f21f83efb36853c0b70002322c1ab3ad ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmmi8.tfm" 1136768653 1520 eccf95517727cb11801f4f1aee3a21b4 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr12.tfm" 1136768653 1288 655e228510b4c2a1abe905c368440826 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr17.tfm" 1136768653 1292 296a67155bdbfc32aa9c636f21e91433 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr6.tfm" 1136768653 1300 b62933e007d01cfd073f79b963c01526 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmr8.tfm" 1136768653 1292 21c1c5bfeaebccffdb478fd231a0997d ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmsy10.tfm" 1136768653 1124 6c73e740cf17375f03eec0ee63599741 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmsy6.tfm" 1136768653 1116 933a60c408fc0a863a92debe84b2d294 ""
"/usr/share/texlive/texmf-dist/fonts/tfm/public/cm/cmsy8.tfm" 1136768653 1120 8b7d695260f3cff42e636090a8002094 ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx10.pfb" 1248133631 34811 78b52f49e893bcba91bd7581cdc144c0 ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmbx12.pfb" 1248133631 32080 340ef9bf63678554ee606688e7b5339d ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb" 1248133631 36299 5f9df58c2139e7edcf37c8fca4bd384d ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb" 1248133631 35752 024fb6c41858982481f6968b5fc26508 ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr12.pfb" 1248133631 32722 d7379af29a190c3f453aba36302ff5a9 ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr17.pfb" 1248133631 32362 179c33bbf43f19adbb3825bb4e36e57a ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr7.pfb" 1248133631 32762 224316ccc9ad3ca0423a14971cfa7fc1 ""
"/usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmsy10.pfb" 1248133631 32569 5e5ddc8df908dea60932f3c484a54c0d ""
"/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii" 1689984000 71627 94eb9990bed73c364d7f53f960cc8c5b ""
"/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty" 1644112042 7237 bdd120a32c8fdb4b433cf9ca2e7cd98a ""
"/usr/share/texlive/texmf-dist/tex/generic/iftex/ifvtex.sty" 1572645307 1057 525c2192b5febbd8c1f662c9468335bb ""
"/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty" 1359763108 5949 3f3fd50a8cc94c3d4cbf4fc66cd3df1c ""
"/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty" 1359763108 13829 94730e64147574077f8ecfea9bb69af4 ""
"/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd" 1359763108 961 6518c6525a34feb5e8250ffa91731cff ""
"/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd" 1359763108 961 d02606146ba5601b5645f987c92e6193 ""
"/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty" 1654720880 2222 78b930a5a6e3dc2ac69b78c2057b94d7 ""
"/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty" 1654720880 4173 c989ee3ced31418e3593916ab26c793a ""
"/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty" 1654720880 88393 1adf6fa3f245270d06e3d4f8910f7fc5 ""
"/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty" 1654720880 4474 f04cd1cc7bd76eb033e6fb12eb6a0d77 ""
"/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty" 1654720880 2444 70065bddd85997dc1fd0bb7ae634e5fa ""
"/usr/share/texlive/texmf-dist/tex/latex/base/article.cls" 1689984000 20144 d5ecf0a5140c8d8d8b72cbe86e320eff ""
"/usr/share/texlive/texmf-dist/tex/latex/base/inputenc.sty" 1689984000 5048 84b05796b49b69e2d4257d537721c960 ""
"/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo" 1689984000 8448 c33a4e1cb35cee9b33c2b21033b73e39 ""
"/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty" 1689984000 2894 f2f8ee7d4fb94263f9f255fa22cab2d3 ""
"/usr/share/texlive/texmf-dist/tex/latex/enumitem/enumitem.sty" 1561238569 51697 f8f08183cd2080d9d18a41432d651dfb ""
"/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty" 1579991033 13886 d1306dcf79a944f6988e688c1785f9ce ""
"/usr/share/texlive/texmf-dist/tex/latex/gensymb/gensymb.sty" 1666126245 4629 bbc3d88bc1fe1146ecbefa95c41cab26 ""
"/usr/share/texlive/texmf-dist/tex/latex/geometry/geometry.sty" 1578002852 41601 9cf6c5257b1bc7af01a58859749dd37a ""
"/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg" 1465944070 1224 978390e9c2234eab29404bc21b268d1e ""
"/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def" 1663965824 19448 1e988b341dda20961a6b931bcde55519 ""
"/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty" 1654720880 18387 8f900a490197ebaf93c02ae9476d4b09 ""
"/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty" 1654720880 8010 a8d949cbdbc5c983593827c9eec252e1 ""
"/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty" 1654720880 2671 7e67d78d9b88c845599a85b2d41f2e39 ""
"/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty" 1654720880 4023 293ea1c16429fc0c4cf605f4da1791a9 ""
"/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def" 1673989714 30429 213676d4c7327a21d91ddaed900e7b81 ""
"/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg" 1279039959 678 4792914a8f45be57bb98413425e4c7af ""
"/usr/share/texlive/texmf-dist/web2c/texmf.cnf" 1689984000 40900 887e0dc8cac988a9e9c574af364cf837 ""
"/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map" 1709304547.76014 4547823 614eba97e0451aad345770236b030e55 ""
"/var/lib/texmf/web2c/pdftex/pdflatex.fmt" 1709304354 7871981 633732e45d8f6be00259eac260a0c514 ""
"Q13 OPT.jpg" 1709526367 932839 9684ed142e453b92cf9ac76f14db1de3 ""
"Q13 UNOPT.jpg" 1709512036 912619 bb04a33611b47b412f5e06f4dcdaa6d7 ""
"Q4A OPT.jpg" 1709526367 802322 39d99467f9ebdf542d2b7bff938e2d5e ""
"Q4A UNOPT.jpg" 1709512036 870319 024d15b77172060476042aa97eae702d ""
"SeanRettigHW3.aux" 1709526566.65019 326 114197df80b7f3ae92d20595ff706604 "pdflatex"
"SeanRettigHW3.tex" 1709526566.2752 6008 78090232afefa06aee238870a4b5d2c9 ""
(generated) (generated)
"SeanRettigHW3.aux" "SeanRettigHW3.aux"
"SeanRettigHW3.log" "SeanRettigHW3.log"
Binary file not shown.
Binary file not shown.
Binary file not shown.
+114 -62
View File
@@ -26,76 +26,128 @@ F =\\
\{A, I\} → \{I, J\}\} \{A, I\} → \{I, J\}\}
\begin{enumerate} [label=(\alph*)] \begin{enumerate} [label=(\alph*)]
\item \textbf{What is the closure of the set \{A, D\}?}\\ \item \textbf{What is the closure of the set \{A, D\}?}\\
$\{A, D\}^+ = \{A, D, E, F, G, H, I, J\}$ $\{A, D\}^+ = \{A, D, E, F, G, H, I, J\}$
\item \textbf{What is the key for R?}\\ \item \textbf{What is the key for R?}\\
Key $= \{A, B\}$, since \{A, B\}'s closure includes all atributes. Key $= \{A, B\}$, since \{A, B\}'s closure includes all atributes.
\item \textbf{What is the minimum cover for the set of functional dependencies F?}\\ \item \textbf{What is the minimum cover for the set of functional dependencies F?}\\
Convert to canonical form:\\ Convert to canonical form:\\
\{\{A, B\}→\{C\},\\ \{\{A, B\}→\{C\},\\
\{A, B\}→\{D\},\\ \{A, B\}→\{D\},\\
\{D\}→\{E\},\\ \{D\}→\{E\},\\
\{D\}→\{F\},\\ \{D\}→\{F\},\\
\{D\}→\{G\},\\ \{D\}→\{G\},\\
\{F, G\}→\{H\},\\ \{F, G\}→\{H\},\\
\{A\}→\{I\},\\ \{A\}→\{I\},\\
\{A, B\}→\{E\},\\ \{A, B\}→\{E\},\\
\{A, B\}→\{G\},\\ \{A, B\}→\{G\},\\
\{A, I\} → \{I\}\\ \{A, I\} → \{I\}\\
\{A, I\} → \{J\}\}\\ \{A, I\} → \{J\}\}\\
Eliminate extraneous stuff:\\ Eliminate extraneous stuff:\\
\{\{A, B\}→\{C\},\\ \{\{A, B\}→\{C\},\\
\{A, B\}→\{D\},\\ \{A, B\}→\{D\},\\
\{D\}→\{E\},\\ \{D\}→\{E\},\\
\{D\}→\{F\},\\ \{D\}→\{F\},\\
\{D\}→\{G\},\\ \{D\}→\{G\},\\
\{F, G\}→\{H\},\\ \{F, G\}→\{H\},\\
\{A\}→\{I\},\\ \{A\}→\{I\},\\
\{A, B\}→\{E\},\\ \{A, B\}→\{E\},\\
\{A, B\}→\{G\},\\ \{A, B\}→\{G\},\\
\{A\} → \{J\}\}\\ \{A\} → \{J\}\}\\
Eliminate redundancies:\\ Eliminate redundancies:\\
\{\{A, B\}→\{C\},\\ \{\{A, B\}→\{C\},\\
\{A, B\}→\{D\},\\ \{A, B\}→\{D\},\\
\{D\}→\{E\},\\ \{D\}→\{E\},\\
\{D\}→\{F\},\\ \{D\}→\{F\},\\
\{D\}→\{G\},\\ \{D\}→\{G\},\\
\{F, G\}→\{H\},\\ \{F, G\}→\{H\},\\
\{A\}→\{I\},\\ \{A\}→\{I\},\\
\{A\} → \{J\}\}\\ \{A\} → \{J\}\}\\
\item \textbf{Decompose R into 2NF.}\\ \item \textbf{Decompose R into 2NF.}\\
R = \{A, B, C, D, E, F, G, H, I, J\}\\ R = \{A, B, C, D, E, F, G, H, I, J\}\\
Split up:\\ Split up:\\
$R_1$ = \{\underline{A}, \underline{B}, C, D, E, F, G, H\}; $R_2$ = \{\underline{A}, I, J\}\\ $R_1$ = \{\underline{A}, \underline{B}, C, D, E, F, G, H\}; $R_2$ = \{\underline{A}, I, J\}\\
This is because every nonprime element in $R_1$ is fully functionally dependent on \{A, B\}, and every nonprime element in $R_2$ is fully functionally dependent on $\{A\}$. This is because every nonprime element in $R_1$ is fully functionally dependent on \{A, B\}, and every nonprime element in $R_2$ is fully functionally dependent on $\{A\}$.
\item Decompose R into 3NF\\ \item Decompose R into 3NF\\
$R_1$ = \{\underline{A}, \underline{B}, C, D\}; $R_2$ = \{\underline{A}, I, J\}; $R_3$ = \{\underline{D}, E, F, G\} $R_4$ = \{\underline{F}, \underline{G}, H\}\\ $R_1$ = \{\underline{A}, \underline{B}, C, D\}; $R_2$ = \{\underline{A}, I, J\}; $R_3$ = \{\underline{D}, E, F, G\} $R_4$ = \{\underline{F}, \underline{G}, H\}\\
\end{enumerate} \end{enumerate}
\newpage \newpage
\section{} \section{}
\begin{enumerate} [label=(\alph*)] \begin{enumerate} [label=(\alph*)]
\item \textbf{What are the possible sources of the information that defines the functional dependencies \item \textbf{What are the possible sources of the information that defines the functional dependencies
that hold among the attributes of a relation schema? Discuss two possible sources. Explain your that hold among the attributes of a relation schema? Discuss two possible sources. Explain your
answer.}\\ answer.}\\
Functional dependencies must be defined explicitely by someone who knows the semantics of the attributes in the relation. Functional dependencies must be defined explicitely by someone who knows the semantics of the attributes in the relation.
So what are some possible sources for these semantics?\\ So what are some possible sources for these semantics?\\
\\ \\
A possible source could be the entity that wants to use the database. Lets say its a company that want's to keep track of laptops. Perhaps they have a bunch of attributes that they A possible source could be the entity that wants to use the database. Lets say its a company that want's to keep track of laptops. Perhaps they have a bunch of attributes that they
want to be able to keep track of about the laptops. They can put together the attributes and then make some sort of ID for each laptop that has functional dependencies for the relation.\\ want to be able to keep track of about the laptops. They can put together the attributes and then make some sort of ID for each laptop that has functional dependencies for the relation.\\
\\ \\
Another possible source could be some sort of relationship that is already defined in the nature of whatever you are already trying to model. For example, the relationship between a child and their mother. Another possible source could be some sort of relationship that is already defined in the nature of whatever you are already trying to model. For example, the relationship between a child and their mother.
There is a functional dependency from the child to the mother because the child can only have one biological mother while the mother could have multiple children. There is a functional dependency from the child to the mother because the child can only have one biological mother while the mother could have multiple children.
\item \textbf{What is meant by the closure of a set of functional dependencies? Illustrate with an example.}\\ \item \textbf{What is meant by the closure of a set of functional dependencies? Illustrate with an example.}\\
The closure of a set of FD really just means that it includes all inferences that can be made from a sparser set of functional dependencies. It's the most explicit you can be about a group of relations.\\ The closure of a set of FD really just means that it includes all inferences that can be made from a sparser set of functional dependencies. It's the most explicit you can be about a group of relations.\\
For example, if there is a functional dependency between my SSN and me $(A \rightarrow B)$, and also a functional dependency between me and my mother $(B \rightarrow C)$, the closure of the set of those two would also include the functional dependency that can be inferred between my ssn and my mother. $(A \rightarrow C)$. For example, if there is a functional dependency between my SSN and me $(A \rightarrow B)$, and also a functional dependency between me and my mother $(B \rightarrow C)$, the closure of the set of those two would also include the functional dependency that can be inferred between my ssn and my mother. $(A \rightarrow C)$.
Thus, the closure of the SSN would be $A^+ = \{A, B, C\}$. Thus, the closure of the SSN would be $A^+ = \{A, B, C\}$.
\item \textbf{What is the lossless (or nonadditive) join property of a decomposition? Why is it important?}\\ \item \textbf{What is the lossless (or nonadditive) join property of a decomposition? Why is it important?}\\
This property ensures that spurious tuples, or tuples that were not in the original relation before decomposition, do not appear after rejoining the relations.\\ This property ensures that spurious tuples, or tuples that were not in the original relation before decomposition, do not appear after rejoining the relations.\\
This is important so we can complete the normalization of the data and relations without losing information. We need the benefits that come with normalizing relations, but we cannot sacrifice data to achieve it. This is important so we can complete the normalization of the data and relations without losing information. We need the benefits that come with normalizing relations, but we cannot sacrifice data to achieve it.
\end{enumerate} \end{enumerate}
\newpage
\section{}
Consider the following four schedules for transactions T1, T2 and T3:
\begin{enumerate} [label=\alph*]
\item r1(X); r3(X); w1(X); r2(X); w3(X); w2(X)
\item r1(Y); r3(Y); w3(X); w1(X); r2(X); w2(Y)
\item w2(X); r1(Y); w2(Y); r2(X); w2(Y); r3(Y)
\item r3(X); r2(X); w3(X); r1(Y); w1(X); r2(Y)
\item r3(X); r2(X); r1(X); w3(X); w1(X); w2(X)
\end{enumerate}
\begin{enumerate} [label=(\alph*)]
\item For each schedule, specify whether or not the schedule is conflict serializable and why. To
determine if a schedule is conflict serializable you can either use the precedence graph or swap
conflicting operations.
\item Then, for each serializable schedule, give the equivalent serial schedule.
\end{enumerate}
\hrule
\begin{enumerate} [label=(\alph*)]
\item \textbf{r1(X); r3(X); w1(X); r2(X); w3(X); w2(X)}\\
Not-Serializable. There is a cycle between $T_1$ and $T_3$ in the precedence graph.\\
\includegraphics[width=0.5\linewidth]{pred_graph_a.jpg}
\item \textbf{r1(Y); r3(Y); w3(X); w1(X); r2(X); w2(Y)}\\
Serializable.\\
r3(Y); w3(X); r1(Y); w1(X); r2(X); w2(Y)\\
\includegraphics[width=0.5\linewidth]{pred_graph_b.jpg}
\item \textbf{w2(X); r1(Y); w2(Y); r2(X); w2(Y); r3(Y)}\\
Serializable.\\
r1(Y); w2(X); w2(Y); r2(X); w2(Y); r3(Y)\\
\includegraphics[width=0.5\linewidth]{pred_graph_c.jpg}
\item \textbf{r3(X); r2(X); w3(X); r1(Y); w1(X); r2(Y)}\\
Serializable.\\
r2(X); r2(Y); r3(X); w3(X); r1(Y); w1(X)\\
\includegraphics[width=0.5\linewidth]{pred_graph_d.jpg}
\item \textbf{r3(X); r2(X); r1(X); w3(X); w1(X); w2(X)}\\
Not-Serializable. There is a cycle between all edges in the precedence graph.\\
\includegraphics[width=0.5\linewidth]{pred_graph_e.jpg}
\end{enumerate}
\newpage
\section{(0.75 points)}
Consider the following actions taken by transaction T1 on a database with objects X and Y:\\
\textbf{R1(X), W1(X), R1(Y), W1(Y)}\\
Without altering the order of operations of T1, give example schedules with an additional
Transactions T2 (with 4 operations accessing both database objects X and Y) that fulfill the
following conditions:\\
\begin{enumerate} [label=(\alph*)]
\item \textbf{Give an example schedule using two transactions (T1 and T2) which is conflict serializable.}\\
w2(X); r1(X); r2(Y); w2(Y); r2(X); w1(X); r1(Y); w1(Y)\\
The precedence graph shows no cycles.
\item \textbf{Give an example schedule using two transactions (T1 and T2) which is not conflict serializable. Explain why the schedule is not conflict serializable.}\\
w2(X); r1(X); r2(Y); w2(Y); w1(X); r2(X); r1(Y); w1(Y)\\
The precedence graph has a cycle between $T_1$ and $T_2$. $T_1$ writes before $T_2$ reads, but $T_2$ has already written before $T_1$.
\end{enumerate}
\end{document} \end{document}
Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 302 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 361 KiB

+135
View File
@@ -0,0 +1,135 @@
Test Case 1 (Handout example)
Log:
W:0,T1,1,1,5,-1
R:1,T1,2,2,0
W:2,T1,2,2,3,1
R:3,T1,1,5,2
C:4,T1,3
R:5,T2,1,5,-1
W:6,T2,1,5,2,5
C:7,T2,6
Test Case 2 (Three transactions)
Log:
R:0,T1,6,6,-1
R:1,T2,4,4,-1
R:2,T3,9,9,-1
W:3,T1,7,7,2,0
W:4,T2,2,2,4,1
R:5,T3,6,6,2
W:6,T1,5,5,8,3
W:7,T3,1,1,9,5
C:8,T3,7
W:9,T1,6,6,2,6
C:10,T1,9
R:11,T2,5,8,4
W:12,T2,7,2,3,11
C:13,T2,12
Test Case 3 (Deadlocks)
Log:
W:0,T1,4,4,1,-1
W:1,T2,5,5,2,-1
W:2,T3,6,6,3,-1
R:3,T1,1,1,0
R:4,T2,1,1,1
R:5,T3,2,2,2
R:6,T2,2,2,4
A:7,T3,5
W:8,T2,2,2,3,6
C:9,T2,8
W:10,T1,1,1,2,3
C:11,T1,10
Test Case 4 (No Conflicts)
Log:
R:0,T1,1,1,-1
R:1,T2,1,1,-1
R:2,T1,2,2,0
R:3,T2,2,2,1
R:4,T1,3,3,2
R:5,T2,3,3,3
W:6,T1,4,4,1,4
W:7,T2,5,5,2,5
C:8,T1,6
C:9,T2,7
Test Case 5: Multiple Deadlocks OR if deadlock detection finds T1 & T2 deadlock first:
Log: Log:
R:0,T1,1,1,-1 R:0,T1,1,1,-1
R:1,T2,2,2,-1 R:1,T2,2,2,-1
R:2,T3,1,1,-1 R:2,T3,1,1,-1
R:3,T2,3,3,1 R:3,T2,3,3,1
A:4,T3,2 A:4,T2,3
A:5,T2,3 W:5,T3,3,3,4,2
W:6,T1,2,2,1,0 W:6,T1,2,2,1,0
C:7,T1,6 C:7,T3,5
C:8,T1,6
Test Case 6: Larger deadlock cycle
Log:
R:0,T1,1,1,-1
R:1,T2,2,2,-1
R:2,T3,3,3,-1
R:3,T4,4,4,-1
A:4,T4,3
W:5,T3,4,4,3,2
C:6,T3,5
W:7,T2,3,3,2,1
C:8,T2,7
W:9,T1,2,2,1,0
C:10,T1,9
Test Case 7: Small deadlock cycle
Log:
W:0,T1,1,1,2,-1
W:1,T2,2,2,5,-1
A:2,T2,1
R:3,T1,2,2,0
C:4,T1,3
Test Case 8: Three transaction with deadlock cycle
Log:
R:0,T1,6,6,-1
R:1,T2,4,4,-1
R:2,T3,9,9,-1
W:3,T1,7,7,2,0
W:4,T2,2,2,4,1
R:5,T3,6,6,2
R:6,T2,5,5,4
W:7,T3,1,1,9,5
A:8,T2,6
C:9,T3,7
W:10,T1,2,2,8,3
W:11,T1,6,6,2,10
C:12,T1,11
Test Case 9: Small transactions without deadlock cycle
Log:
W:0,T1,1,1,2,-1
W:1,T2,3,3,5,-1
R:2,T1,2,2,0
R:3,T2,4,4,1
C:4,T1,2
C:5,T2,3
Test Case 10: Handout example with Deadlock
Log:
W:0,T1,1,1,5,-1
R:1,T2,2,2,-1
R:2,T1,2,2,0
A:3,T2,1
W:4,T1,2,2,3,2
R:5,T1,1,5,4
C:6,T1,5
Binary file not shown.
+92
View File
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.cs.purdue</groupId>
<artifactId>cs448p4</artifactId>
<version>1.0-SNAPSHOT</version>
<name>cs448p4</name>
<url>https://www.cs.purdue.edu/homes/bb/cs448f19/</url>
<properties>
<java.version>10</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<!--add test cases file in here -->
<mainClass>test.TestDriver</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
+25
View File
@@ -0,0 +1,25 @@
package CC;
import java.util.List;
public class CC
{
/**
* Notes:
* - Execute all given transactions, using locking.
* - Each element in the transactions List represents all operations performed by one transaction, in order.
* - No operation in a transaction can be executed out of order, but operations may be interleaved with other
* transactions if allowed by the locking.
* - The index of the transaction in the list is equivalent to the transaction ID.
* - Print the log to the console at the end of the method.
* - Return the new db state after executing the transactions.
* @param db the initial status of the db
* @param transactions the schedule, which basically is a {@link List} of transactions.
* @return the final status of the db
*/
public static int[] executeSchedule(int[] db, List<String> transactions)
{
//TODO
return null ;
}
}
@@ -0,0 +1,52 @@
package CC;
import java.util.Arrays;
import java.util.List;
public class Project
{
public static int[] newDB()
{
return new int[]{0,1,2,3,4,5,6,7,8,9};
}
public static void main(String[] args)
{
//Test Cases
//1) Simple testcase (handout)
List<String> tc1 = Arrays.asList(new String[]{"W(1,5);R(2);W(2,3);R(1);C","R(1);W(1,2);C"});
//2) Three transactions
List<String> tc2 = Arrays.asList(new String[]{"R(6);W(7,2);W(5,8);W(6,2);C","R(4);W(2,4);R(5);W(7,3);C","R(9);R(6);W(1,9);C"});
//3) Deadlocks
List<String> tc3 = Arrays.asList(new String[]{"W(4,1);R(1);W(1,2);C","W(5,2);R(1);R(2);W(2,3);C","W(6,3);R(2);W(2,4);C"});
//4) No conflicts
List<String> tc4 = Arrays.asList(new String[]{"R(1);R(2);R(3);W(4,1);C","R(1);R(2);R(3);W(5,2);C"});
//5) Multiple Deadlocks (handout)
List<String> tc5 = Arrays.asList(new String[]{"R(1);W(2,1);C","R(2);R(3);W(1,2);C","R(1);W(3,4);C"});
//6) Larger Deadlock Cycle
List<String> tc6 = Arrays.asList(new String[]{"R(1);W(2,1);C","R(2);W(3,2);C","R(3);W(4,3);C","R(4);W(1,4);C"});
//7) Small Deadlock Cycle
List<String> tc7 = Arrays.asList(new String[]{"W(1,2);R(2);C","W(2,5);R(1);C"});
//8) Three Transactions Deadlock Cycle
List<String> tc8 = Arrays.asList(new String[]{"R(6);W(7,2);W(2,8);W(6,2);C","R(4);W(2,4);R(5);W(7,3);C","R(9);R(6);W(1,9);C"});
//9) Small Transactions without Deadlock Cycle
List<String> tc9 = Arrays.asList(new String[]{"W(1,2);R(2);C","W(3,5);R(4);C"});
//10) Testcase with Deadlock Cycle
List<String> tc10 = Arrays.asList(new String[]{"W(1,5);R(2);W(2,3);R(1);C","R(2);R(1);W(1,2);C"});
//Consult the ExpectedOutputs.txt for the expected DB state and log
System.out.println("Schedule 1: Handout Test Case:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc1)) + "\n");
System.out.println("Schedule 2: Three Transactions Test Case:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc2)) + "\n");
System.out.println("Schedule 3: Deadlocks Test Case:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc3)) + "\n");
System.out.println("Schedule 4: No Conflicts Test Case:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc4)) + "\n");
System.out.println("Schedule 5: Multiple Deadlocks Test Case:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc5)) + "\n");
System.out.println("Schedule 6: Larger Deadlock Cycle Test Case:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc6)) + "\n");
System.out.println("Schedule 7: Testcase with two transactions and a deadlock\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc7)) + "\n");
System.out.println("Schedule 8: Testcase with three transactions and a deadlock:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc8)) + "\n");
System.out.println("Schedule 9: Testcase with two transactions and no deadlocks:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc9)) + "\n");
System.out.println("Schedule 10: Testcase with deadlock between two transactions:\n\t" + Arrays.toString(CC.executeSchedule(newDB(),tc10)) + "\n");
}
}
@@ -0,0 +1,224 @@
package tests;
import static org.junit.Assert.*;
import java.io.IOException;
import CC.*;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.util.Arrays;
import java.util.List;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class CCTest {
public final static boolean OK = true;
public final static boolean FAIL = false;
public static int[] newDB()
{
return new int[]{0,1,2,3,4,5,6,7,8,9};
}
/**
* Schedule 1. Simple testcase with 2 transactions.
* This testcase is shown in the handout, Part 2.
*/
@Test
public void test_A_Simple()
{
// expected output from the given Schedule
int expectedOutput[] = {0, 2, 3, 3, 4, 5, 6, 7, 8, 9};
// input: T1, T2
List<String> tc1 = Arrays.asList(new String[]{"W(1,5);R(2);W(2,3);R(1);C","R(1);W(1,2);C"});
// Here we are returning the state of the database after executing Schedule 1
int methodOutput[] = CC.executeSchedule(newDB(),tc1);
// Here we are checking whether method output matched with the expected output
// if both match it will pass the test, otherwise it will show an error message
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 2. Testcase with three transactions and no deadlock.
*/
@Test
public void test_B_ThreeTransactions()
{
int expectedOutput[] = {0, 9, 4, 3, 4, 8, 2, 3, 8, 9};
//Testcases
//2) Three transactions
List<String> tc2 = Arrays.asList(new String[]{"R(6);W(7,2);W(5,8);W(6,2);C","R(4);W(2,4);R(5);W(7,3);C","R(9);R(6);W(1,9);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc2);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 3. Testcase with three transactions and a deadlock.
*/
@Test
public void test_C_Deadlocks()
{
int expectedOutput[] = {0, 2, 3, 3, 1, 2, 6, 7, 8, 9};
//Testcases
//3) Deadlocks
List<String> tc3 = Arrays.asList(new String[]{"W(4,1);R(1);W(1,2);C","W(5,2);R(1);R(2);W(2,3);C","W(6,3);R(2);W(2,4);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc3);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 4. Testcase with multiple deadlocks.
* This testcase is shown in the handout, Part 3 (Deadlock Detection/Handling).
*/
@Test
public void test_D_NoConflicts()
{
int expectedOutput[] = {0, 1, 2, 3, 1, 2, 6, 7, 8, 9};
//Testcases
//4) No conflicts
List<String> tc4 = Arrays.asList(new String[]{"R(1);R(2);R(3);W(4,1);C","R(1);R(2);R(3);W(5,2);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc4);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 5. Testcase with multiple deadlocks.
* This testcase is shown in the handout, Part 3 (Deadlock Detection/Handling).
*/
@Test
public void test_E_MultipleDeadlocks()
{
// In the Schedule 5 there can be two possible outcomes depending of how you handle deadlocks.
int expectedOutput[] = {0, 1, 1, 3, 4, 5, 6, 7, 8, 9};
//Testcases
//5) Multiple Deadlocks
List<String> tc5 = Arrays.asList(new String[]{"R(1);W(2,1);C","R(2);R(3);W(1,2);C","R(1);W(3,4);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc5);
try{
// if T3 is aborted, and then T2
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}catch (AssertionError e) {
// if we abort T2
int expectedOutput_anth[] = {0, 1, 1, 4, 4, 5, 6, 7, 8, 9};
assertArrayEquals("output did not match expected result",expectedOutput_anth, methodOutput);
}
}
/**
* Schedule 6. Testcase with large number of transactions (4) and a deadlock.
*/
@Test
public void test_F_LargerDeadlock()
{
int expectedOutput[] = {0, 1, 1, 2, 3, 5, 6, 7, 8, 9};
//Testcases
//6) Larger Deadlock Cycle
List<String> tc6 = Arrays.asList(new String[]{"R(1);W(2,1);C","R(2);W(3,2);C","R(3);W(4,3);C","R(4);W(1,4);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc6);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 7. Testcase with small transactions (2) and a deadlock.
*/
@Test
public void test_G_SmallDeadlock()
{
int expectedOutput[] = {0, 2, 2, 3, 4, 5, 6, 7, 8, 9};
//Testcases
//7) Small Deadlock Cycle
List<String> tc7 = Arrays.asList(new String[]{"W(1,2);R(2);C","W(2,5);R(1);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc7);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 8. Testcase with three transactions (2) and a deadlock.
*/
@Test
public void test_H_ThreeTransactionsDeadlock()
{
int expectedOutput[] = {0, 9, 8, 3, 4, 5, 2, 2, 8, 9};
//Testcases
//8) Three Transactions Deadlock
List<String> tc8 = Arrays.asList(new String[]{"R(6);W(7,2);W(2,8);W(6,2);C","R(4);W(2,4);R(5);W(7,3);C","R(9);R(6);W(1,9);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc8);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 9. Testcase with small transactions (2) and no deadlocks.
*/
@Test
public void test_I_SmallTransactionsNoDeadlock()
{
int expectedOutput[] = {0, 2, 2, 5, 4, 5, 6, 7, 8, 9};
//Testcases
//9) Small Transactions without Deadlock Testcase:
List<String> tc9 = Arrays.asList(new String[]{"W(1,2);R(2);C","W(3,5);R(4);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc9);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
/**
* Schedule 10. Testcase with deadlock between two transactions.
*/
@Test
public void test_J_TestCaseDeadlockDeadlock()
{
int expectedOutput[] = {0, 5, 3, 3, 4, 5, 6, 7, 8, 9};
//Testcases
//10) Testcase with Deadlock:
List<String> tc10 = Arrays.asList(new String[]{"W(1,5);R(2);W(2,3);R(1);C","R(2);R(1);W(1,2);C"});
int methodOutput[] = CC.executeSchedule(newDB(),tc10);
assertArrayEquals("output did not match expected result",expectedOutput, methodOutput);
}
}
@@ -0,0 +1,16 @@
package tests;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
public class TestDriver {
public static void main(String[] args) {
Result result = JUnitCore.runClasses(tests.CCTest.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}