YouTube2Text

01 - Course Introduction & Relational Model (CMU Intro to Database Systems / Fall 2021) — Transcript

by CMU Database Group · 11,396 words · 1,974 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Bad, bad, AND A WICKED AND BAD, BAD, and
  2. 0:04a wicked and
  3. 0:05Bad, bad, and a wicked and
  4. 0:08Bad, bad, and a wicked and
  5. 0:11Bad, bad, and This is Introduction to
  6. 0:14Database Systems.
  7. 0:15Um those of you familiar with the class,
  8. 0:18um you know that it's usually taught by
  9. 0:21uh Andy Pavlov, and as I'm sure some of
  10. 0:24you may realize, I'm not Andy Pavlov. Uh
  11. 0:28my name is Andrew Crotty. I'm a
  12. 0:30postdoctoral researcher here at uh CMU,
  13. 0:34and my research focuses mainly on
  14. 0:36database systems and data management.
  15. 0:39Uh you may also have realized that my
  16. 0:41co-instructor for the course uh Lim Maas
  17. 0:43is also not Andy Pavlov. Uh he is a
  18. 0:46postdoc here as well, and he's uh one of
  19. 0:48Andy's former PhD students. So um
  20. 0:52at this point, you might be wondering
  21. 0:53where Andy is, and uh he's actually on
  22. 0:56leave this semester
  23. 0:58um because he's filming a uh a Netflix
  24. 1:01documentary that's a follow-up uh to
  25. 1:03last year's Tiger King.
  26. 1:05Um
  27. 1:06and I unfortunately I can't say anything
  28. 1:07more uh because of the NDA that I
  29. 1:10signed, but um you should definitely
  30. 1:13check this out when it's uh when it's
  31. 1:15released. So with that, um
  32. 1:17let's move on to the course material. Uh
  33. 1:18one last thing before we begin, uh I
  34. 1:20want to thank um
  35. 1:22Google BigQuery for helping us with uh
  36. 1:25course development this semester.
  37. 1:27Um I'm sure all of you know what what
  38. 1:29Google is, but uh BigQuery specifically
  39. 1:32is a uh a database product. It's a a
  40. 1:35fully managed um
  41. 1:37cloud data warehouse. We might call it
  42. 1:39platform as a service.
  43. 1:41And uh essentially you give them your
  44. 1:43data, and then you can query it, run all
  45. 1:46sorts of analytics, machine learning,
  46. 1:47that kind of stuff.
  47. 1:49Um and at the end of the semester, uh
  48. 1:51there's there's going to be someone from
  49. 1:52Google uh who comes here to give a guest
  50. 1:54lecture and tell you about kind of all
  51. 1:56the the cool stuff they're doing Uh and
  52. 1:58you be able to see a lot of the topics
  53. 2:00that we cover in the course actually
  54. 2:01applied in practice and they'll they'll
  55. 2:04be able to talk more about kind of the
  56. 2:06the problems that come up when um
  57. 2:10uh dealing with with data at this scale.
  58. 2:14So,
  59. 2:16today's agenda, we're just going to go
  60. 2:17over the kind of beginning, what is this
  61. 2:20course, course logistics stuff
  62. 2:23and then there'll be sort of like a mini
  63. 2:26path lecture at the end. We'll we'll
  64. 2:28just kind of go through some of the core
  65. 2:29concepts
  66. 2:31that we're going to cover in the course.
  67. 2:33So, depending on timing we might get out
  68. 2:35a few minutes early.
  69. 2:36Um to start off with the waitlist, I do
  70. 2:40not control the waitlist.
  71. 2:42It is way above my paygrade.
  72. 2:44As students are going to be moved off
  73. 2:47the waitlist based on your position
  74. 2:50as new spots in the class open up. So,
  75. 2:53if you if you send us emails, there's
  76. 2:54nothing that I personally can do about
  77. 2:56it. It's just going to be based on
  78. 2:57order.
  79. 2:58And if you're not currently enrolled in
  80. 3:00the course,
  81. 3:01the likelihood that you'll get in and
  82. 3:03things will probably firm up over the
  83. 3:06next week or so, but um
  84. 3:09unfortunately, you might not be able to
  85. 3:10get in, but we do plan to make all of
  86. 3:13the
  87. 3:13course materials public. We're going to
  88. 3:15put the lectures lecture videos on
  89. 3:17YouTube and
  90. 3:19all the material will be there so you'll
  91. 3:21you'll be able to follow along.
  92. 3:25Uh in terms of lecture rules,
  93. 3:27please interrupt me at any time if any
  94. 3:30of these things happens, either I'm
  95. 3:32speaking too fast,
  96. 3:34if you don't understand something that
  97. 3:35I'm talking about or if you have a
  98. 3:37database related question, chances are
  99. 3:39that if you have a question then then
  100. 3:42um
  101. 3:43someone else does too. And if this this
  102. 3:47is kind of a big room, if I if I can't
  103. 3:49quite hear you or if I don't if I don't
  104. 3:51see you right away, just uh
  105. 3:53try to
  106. 3:54uh interrupt me at a at a a good point
  107. 3:56where I can uh take the question.
  108. 4:01So, uh just at a high level, um this
  109. 4:04course is specifically about the design
  110. 4:08and implementation of database
  111. 4:10management systems.
  112. 4:12So, that means we're going to be looking
  113. 4:14at the software
  114. 4:17uh that manages databases. So, this
  115. 4:20isn't a course about uh how to use a a
  116. 4:24DBMS to build applications. So, like
  117. 4:26imagine if you had a building a web
  118. 4:28application, and you wanted to store uh
  119. 4:31your user user data in in a database, um
  120. 4:35this this class is not about that. Uh
  121. 4:37and it's not a class about how to
  122. 4:39administer a a database system. So,
  123. 4:41there are all all sorts of um
  124. 4:44jobs out there where where people's
  125. 4:46entire role is essentially uh manage the
  126. 4:48software that manages the data. Um and
  127. 4:51that's that's also not not the the topic
  128. 4:53of this course. So, there are other
  129. 4:54courses unfortunately, one of them um is
  130. 4:55not being offered this semester. Um
  131. 4:59and actually I don't know if it's
  132. 5:00offered anymore. Um
  133. 5:02but that that's one of course the one
  134. 5:04that that uh covers those topics.
  135. 5:08Okay. So, just at a high level for the
  136. 5:11rest of the semester, the uh topics that
  137. 5:13we're going to be covering
  138. 5:15uh we're going to be starting with um
  139. 5:18uh the relational model, and that's
  140. 5:21that's a data model for databases, and
  141. 5:23that's going to be uh
  142. 5:25the main theme for the entire course.
  143. 5:27So, we're going to talk primarily about
  144. 5:29relational database management systems.
  145. 5:31There are all sorts of other um data
  146. 5:33management systems, no SQL, some of you
  147. 5:35may have heard of graph databases, all
  148. 5:37sorts of things. Um we're going to be
  149. 5:39focusing on relational databases in this
  150. 5:41course. And uh
  151. 5:44we're going to sort of build up um
  152. 5:46from the bottom level all the way up
  153. 5:48through the stack uh to look at the
  154. 5:50different parts of a database management
  155. 5:54system starting with the storage, how
  156. 5:56you actually physically store the data
  157. 5:58in memory and on on persistent storage
  158. 6:02like a hard drive or an SSD.
  159. 6:04Then we're going to move up and talk
  160. 6:06about query execution and kind of how
  161. 6:08you can
  162. 6:09either
  163. 6:11put data into update the data that
  164. 6:14you've stored or retrieve the data.
  165. 6:16Then we're going to move on to kind of
  166. 6:18concurrency control. So imagine you have
  167. 6:20several um
  168. 6:22processes that are concurrently trying
  169. 6:24to access the database. How can you sort
  170. 6:27of keep all of those together and manage
  171. 6:29them?
  172. 6:30Um
  173. 6:31the next piece that we're going to cover
  174. 6:32is recovery. So if your database crashes
  175. 6:35or if if the machine crashes,
  176. 6:38um
  177. 6:39how can you kind of make sure that your
  178. 6:41data is safe and persistent and you can
  179. 6:43kind of recover from those types of
  180. 6:45situations. And then towards the end of
  181. 6:47this this semester we're going to cover
  182. 6:48some more advanced topics,
  183. 6:50distributed database management systems
  184. 6:52and kind of just a general
  185. 6:55review of
  186. 6:57some advanced topics.
  187. 7:00So in terms of logistics, the course
  188. 7:03policies and the schedule are all on
  189. 7:06the web page.
  190. 7:08Academic honesty I'm going to talk about
  191. 7:09this
  192. 7:10in in later in the slides, but please um
  193. 7:15don't do anything stupid. If if we catch
  194. 7:19you
  195. 7:20plagiarizing or copying work or those
  196. 7:22sorts of things, it's going to be a big
  197. 7:24problem. I'll have to do a lot of
  198. 7:26paperwork
  199. 7:27and it's going to be a big problem for
  200. 7:29you. So just please it's easier
  201. 7:31if you don't do it. If you have any
  202. 7:32questions, if you're not sure about
  203. 7:33anything,
  204. 7:35please either send an email to me or
  205. 7:38Lynn or one of the TAs Um, just ask like
  206. 7:41is is this thing that I'm doing okay?
  207. 7:44Um, and I you can also refer to the the
  208. 7:46CMU policy page.
  209. 7:48Ironically, um, that link there is
  210. 7:50broken. I checked it this morning. Their
  211. 7:52their
  212. 7:54web page is down, but
  213. 7:56there's a cached version somewhere or or
  214. 7:58I can make it available to you if you if
  215. 8:00you you know me. So,
  216. 8:02um,
  217. 8:03all of the discussion and announcements
  218. 8:05for the course will be on Piazza.
  219. 8:09Um,
  220. 8:10and if if there's something that you
  221. 8:12need to contact either me or Lim about,
  222. 8:15just private private privately, um,
  223. 8:18a sensitive subject, then please send us
  224. 8:20an email,
  225. 8:21um, and we can coordinate something to
  226. 8:23to speak.
  227. 8:26So, the textbook for the course, um, is
  228. 8:28is the this database systems concepts
  229. 8:31book, um,
  230. 8:33also known as the the Silberschatz book.
  231. 8:35Uh, there are
  232. 8:36uh,
  233. 8:37so I'm not sure about the the exact
  234. 8:40difference between the sixth and the the
  235. 8:41seventh edition. I think all of the
  236. 8:43material that we're going to cover in
  237. 8:44this course is available in the sixth
  238. 8:45edition. Um,
  239. 8:48if you have that or want to want to buy
  240. 8:50that version,
  241. 8:51um, I don't think that the seventh
  242. 8:53edition is available as like a hard um,
  243. 8:57cover book anymore. I think it's like
  244. 9:00loose leaf pages that are
  245. 9:03you get sent and they've like a three
  246. 9:04hole punch in them.
  247. 9:06Um,
  248. 9:07but we'll also be providing
  249. 9:09lecture notes uh, that that will cover
  250. 9:11all of the topics as well as things that
  251. 9:13we cover in class that aren't um,
  252. 9:16covered in the book.
  253. 9:19So, in terms of grading, uh, this is
  254. 9:21going to be the breakdown for, um,
  255. 9:24how your grades are calculated. 15% for
  256. 9:26homeworks, 45% for projects,
  257. 9:30um, 20% for the midterm exam, and 20%
  258. 9:33for the final exam. So, it's it's pretty
  259. 9:35We weighted towards
  260. 9:36uh, homeworks and the the projects.
  261. 9:43Uh for homeworks, there are going to be
  262. 9:44five assignments that are are spread out
  263. 9:47over the course of the semester.
  264. 9:49Um
  265. 9:50the first homework is is a a SQL
  266. 9:53assignment. So, SQL is a
  267. 9:55We're going to talk about it a little
  268. 9:55bit at the end of this class and um
  269. 9:58in the the next class, but it's a a
  270. 10:00query language that you use uh to
  271. 10:03interact with the database management
  272. 10:04system. So, the first homework
  273. 10:06assignment is going to be up to write
  274. 10:07some SQL queries
  275. 10:09um to answer some uh
  276. 10:12questions from a a sample database we'll
  277. 10:14give you and the rest are going to be um
  278. 10:17paper and pencil assignments where you
  279. 10:19kind of like uh apply formulas or uh
  280. 10:22solve different like conceptual problems
  281. 10:25uh for topics we cover in class.
  282. 10:27And again, I mentioned earlier, um
  283. 10:31all homework should be done
  284. 10:32individually. Um you shouldn't be
  285. 10:36you know, sharing answers or doing group
  286. 10:38assignments. They're all individual
  287. 10:39assignments um and should be done
  288. 10:41individually. We'll be checking for
  289. 10:43um
  290. 10:44kind of copied uh
  291. 10:46solutions and things.
  292. 10:52So, um
  293. 10:54the projects uh are are focused around
  294. 10:57this idea that you're going to build up
  295. 10:58your own
  296. 11:00um
  297. 11:01database engine over the course of the
  298. 11:03semester. So, like I said, kind of we'll
  299. 11:05start at the lower levels and we'll work
  300. 11:07our way up through the stack. Um
  301. 11:09but what this means is that each project
  302. 11:11is going to build on the previous ones.
  303. 11:14So, for example
  304. 11:16if you have to implement a storage
  305. 11:18manager, or later on, the the later
  306. 11:21projects may interact with that storage
  307. 11:23manager to get uh data in and out. So,
  308. 11:25for that reason, it's it's important
  309. 11:27that you kind of keep up and go along.
  310. 11:29If you get too far behind on on, you
  311. 11:32know, these early projects then uh you
  312. 11:35it's going to be really difficult or
  313. 11:36impossible to to catch up later on in
  314. 11:39the semester. So, an important thing,
  315. 11:41and this was kind of already
  316. 11:44mentioned in the announcement for the
  317. 11:47first project, but
  318. 11:49we're not going to be teaching you how
  319. 11:51to write or debug C++ code in this
  320. 11:55class. It's a prerequisite for the
  321. 11:56course. We expect um
  322. 11:59this is a higher level higher level
  323. 12:00course. We expect that you know
  324. 12:02um
  325. 12:03kind of C++ as a as a prerequisite. So,
  326. 12:06if you go to, you know, TA office hours
  327. 12:08and are asking things like what is a
  328. 12:10string or what is a shared pointer or
  329. 12:11that kind of stuff, they're
  330. 12:14we've told them not not to answer those
  331. 12:16kind of questions. So,
  332. 12:18um
  333. 12:19we expect you to be comfortable working
  334. 12:20with C++.
  335. 12:22That's kind of why this this project
  336. 12:24zero is released, and it it needs to be
  337. 12:26completed
  338. 12:27by September 13th for you to
  339. 12:30uh continue in the course. So,
  340. 12:32uh it's kind of meant as like a as like
  341. 12:34a self-check kind of thing where if
  342. 12:37you're if you're really struggling with
  343. 12:38project zero, then um
  344. 12:41this might might not be the course for
  345. 12:42you because later on
  346. 12:45you're not going to be able to do the
  347. 12:46the more complicated programming
  348. 12:48projects.
  349. 12:51So, all of the projects
  350. 12:54for the course will be implemented using
  351. 12:57um the CMU DB group Bustle academic
  352. 13:01DBMS.
  353. 13:02Um
  354. 13:03it is kind of a
  355. 13:06an academic system, and so it's not
  356. 13:07really a full-fledged
  357. 13:09database system, but
  358. 13:11it has these kind of modular pieces, and
  359. 13:13and
  360. 13:14we'll go through some of these things
  361. 13:16that will make more sense later in the
  362. 13:17course, but it has kind of this
  363. 13:18disk-based storage architecture where as
  364. 13:21I said it can read and write data from
  365. 13:23disk.
  366. 13:24Um it it has a volcano style
  367. 13:27pre-processing
  368. 13:29setup where
  369. 13:31you can kind of chain together iterators
  370. 13:33basically
  371. 13:35to to iterate over your data and answer
  372. 13:37queries. It has pluggable APIs that will
  373. 13:40leverage to be able to implement the
  374. 13:41different pieces of the system that
  375. 13:43you're going to implement for the
  376. 13:44projects.
  377. 13:45Um, and it currently does not support
  378. 13:48SQL so
  379. 13:50you won't be interacting with it through
  380. 13:52SQL. You'll kind of be interacting
  381. 13:53interacting with it through
  382. 13:55um, lower um,
  383. 13:57test test programs that that we provide.
  384. 14:02Okay, so the next thing is the late
  385. 14:04policy. Um,
  386. 14:07you lose 10 point or sorry 10% of the
  387. 14:10points for a project or homework for
  388. 14:13every 24 hours
  389. 14:15late that you you hand it in so
  390. 14:18um,
  391. 14:20if
  392. 14:21you know if you hand it in after the
  393. 14:23deadline we'll round up.
  394. 14:25So if it's 4 hours late then it's going
  395. 14:28to be 10% off and we'll round up to the
  396. 14:30next
  397. 14:31um,
  398. 14:32full day.
  399. 14:34I
  400. 14:34you're going to have a total of four
  401. 14:36late days over the course of the
  402. 14:37semester to be used
  403. 14:39um, for projects only so not for the
  404. 14:41homeworks it's only for the programming
  405. 14:43projects
  406. 14:45and you're free to allocate them as you
  407. 14:48wish.
  408. 14:49For example, you could
  409. 14:52turn in one project four days late or
  410. 14:55four projects each one day late.
  411. 14:58The only thing that you cannot use them
  412. 14:59for
  413. 15:01is is the project number zero. That has
  414. 15:03to be done by September 13th for you to
  415. 15:06to continue the course.
  416. 15:08Um,
  417. 15:09we're I there's
  418. 15:11pandemic still going on. I know that
  419. 15:13there's a lot of
  420. 15:15uncertainty and things that can come up
  421. 15:16so
  422. 15:18we're also going to grant no no
  423. 15:20extensions due to
  424. 15:23extreme circumstances. So, like you have
  425. 15:24a medical emergency or a family
  426. 15:26emergency,
  427. 15:27just if something comes up,
  428. 15:30I realize you know at the time you might
  429. 15:32not be able to, but as soon as you can,
  430. 15:34just contact us and let us know what's
  431. 15:36going on
  432. 15:37and we can we can try to make
  433. 15:38arrangements for you.
  434. 15:43Okay, so again,
  435. 15:45I want to reiterate the plagiarism
  436. 15:47warning.
  437. 15:48I I
  438. 15:50know this is redundant, but I I really
  439. 15:52want to get this out there and so you've
  440. 15:55all seen it and there's there's video of
  441. 15:57me telling all of you about it. So,
  442. 15:59later on if you run into any problems,
  443. 16:02there's no excuse for not knowing what
  444. 16:04this is. So, the the homework and the
  445. 16:06projects must be your own original work.
  446. 16:09They're not group assignments. They're
  447. 16:10not meant to be done together in groups.
  448. 16:12You you cannot copy source code from
  449. 16:16other people, your peers or the web.
  450. 16:18Um in general, there's
  451. 16:22not a since since this is kind of a
  452. 16:24an academic system and we change the um
  453. 16:29projects each semester, there shouldn't
  454. 16:31be
  455. 16:32like
  456. 16:33one-for-one solutions to
  457. 16:36the projects that we're going to give
  458. 16:38you online, but I still
  459. 16:40if there's any source source code out
  460. 16:43there, please don't copy it.
  461. 16:46We're not going to to tolerate
  462. 16:48plagiarism and it is going to be a big
  463. 16:50problem. So, please do not do that.
  464. 16:55Um so, kind of the last administrative
  465. 16:58thing is office hours. We're still
  466. 17:00waiting on
  467. 17:02clarification from the university about
  468. 17:03what we're supposed to do for in-person
  469. 17:07versus remote office hours and you may
  470. 17:08have noticed the website does not have
  471. 17:11either the instructor or TA office hours
  472. 17:14yet, Um, but as soon as we get this
  473. 17:17within the the next day or two, um, we
  474. 17:20will update you. Uh, so
  475. 17:24we'll put it on the website and we'll
  476. 17:25send out a message um, to the class. If
  477. 17:28If you need to contact us sooner,
  478. 17:30uh, about anything at all, please just
  479. 17:32send us an email or uh, you can reach
  480. 17:35out if it's something that's a more
  481. 17:37general question, you can reach out um,
  482. 17:39on on Piazza.
  483. 17:46Okay, so
  484. 17:47uh, for the fun stuff, database
  485. 17:49research. Um,
  486. 17:51there is a vaccination database tech
  487. 17:54talks seminar series
  488. 17:56uh, that will take place
  489. 17:59uh, I believe on Zoom
  490. 18:00um,
  491. 18:02Mondays uh, at 4:30 p.m.
  492. 18:04uh, starting on 9:13, Monday 9:13.
  493. 18:08Um,
  494. 18:10there's a link to the schedule there.
  495. 18:11You can access it uh, and
  496. 18:14we are going to have a whole bunch of
  497. 18:17excellent
  498. 18:19people from each of these these uh,
  499. 18:21either database companies or projects
  500. 18:24uh, come and talk about their system.
  501. 18:26And these aren't like uh, marketing
  502. 18:28people that are just going to say, "Use
  503. 18:29our system." They're They're uh,
  504. 18:32technical people that are going to come
  505. 18:33and give technical talks about um, the
  506. 18:37the actual internals of their system.
  507. 18:39So, low-level stuff, kind of the the
  508. 18:41design stuff
  509. 18:43um, that we're talking about uh, in this
  510. 18:46course. So, if you're interested in
  511. 18:47that, please uh,
  512. 18:49check it out. You can check out the
  513. 18:50website there.
  514. 18:52So,
  515. 18:53that is kind of all of the uh,
  516. 18:56administrative logistics part of um,
  517. 19:01this
  518. 19:02lecture. So, uh, if there are any
  519. 19:04specific questions so far, I'd be happy
  520. 19:07to answer them. Then we can move on to
  521. 19:09the
  522. 19:11fun database stuff.
  523. 19:18Cool.
  524. 19:19Okay, and again, all of this stuff uh
  525. 19:22that I mentioned should be available on
  526. 19:25uh the website either currently or as I
  527. 19:28said in the case of Officer Owl and
  528. 19:29stuff shortly.
  529. 19:31Um so you can check there and if if you
  530. 19:33have any questions, just send us an
  531. 19:34email or ask on uh uh the answer.
  532. 19:38Okay, so databases.
  533. 19:42Let's start with what is a database?
  534. 19:45Um
  535. 19:47just out of curiosity, how like you you
  536. 19:49just raise your hands. How many of you
  537. 19:51regularly interact with a database
  538. 19:54management system databases? It doesn't
  539. 19:56have to be like on the command line
  540. 19:59writing SQL queries. No one? No no
  541. 20:01databases? All right.
  542. 20:03Um
  543. 20:04I find that a little hard to believe. Uh
  544. 20:07uh so SQLite is a a database management
  545. 20:10system. Um
  546. 20:12it is probably the most widely deployed
  547. 20:15uh database management system in the
  548. 20:16world.
  549. 20:17Um pretty new to the heads uh
  550. 20:20smartphone. It's used in iOS and
  551. 20:22Android.
  552. 20:24Web browsers. I don't know if you use
  553. 20:26web browsers. Uh there's Chrome and
  554. 20:29Safari both use uh uh SQLite for um
  555. 20:34storing data.
  556. 20:35Um and if uh if you've made a call with
  557. 20:38Skype, Sk- Skype uses uh SQLite behind
  558. 20:41the scenes. So
  559. 20:42I I guess the point I'm trying to make
  560. 20:44is that um pretty much behind every
  561. 20:48uh application anywhere where you need
  562. 20:51to store data,
  563. 20:52um there's probably a database
  564. 20:54management system running in the
  565. 20:55background handling things for you.
  566. 20:58So um
  567. 21:00a database is essentially an organized
  568. 21:02collection of interrelated data
  569. 21:06um where you're trying to uh model or
  570. 21:09capture some aspect of
  571. 21:13uh uh the real world. So, to think about
  572. 21:15like a real world entity, for example,
  573. 21:17if I have a database to model uh
  574. 21:19students in the class, um,
  575. 21:21each individual student is a data point
  576. 21:23that would be stored in my uh
  577. 21:26database.
  578. 21:28So,
  579. 21:29just as a as a practical example, uh
  580. 21:31let's create a database that models a
  581. 21:35uh a digital music store, something like
  582. 21:37um
  583. 21:38the Apple Music Store, iTunes Music
  584. 21:39Store, or
  585. 21:41uh something similar where you want to
  586. 21:43keep track of we'll just for now to
  587. 21:45simplify things, we'll just keep track
  588. 21:46of
  589. 21:47uh artists and the albums that they
  590. 21:50release.
  591. 21:52So, uh the things that we're going to
  592. 21:53need are, you know, to know about
  593. 21:55individual artists and
  594. 21:58um
  595. 21:59kind of uh a record of over time the the
  596. 22:02different uh albums that they released.
  597. 22:05And the way we can do this just as a as
  598. 22:07a straw man sort of example is using uh
  599. 22:10a flat files.
  600. 22:11So, uh imagine that we want to store our
  601. 22:14database in um
  602. 22:17uh just a a comma comma-separated value
  603. 22:20CSV file,
  604. 22:22um kind of where each each uh
  605. 22:25row or line in the file represents one,
  606. 22:28you know,
  607. 22:30data entity. So, an artist or an album,
  608. 22:33and kind of each uh column is going to
  609. 22:36represent a um
  610. 22:39uh
  611. 22:40an individual attribute about that
  612. 22:42entity. So, um
  613. 22:46you know, pretend we don't know anything
  614. 22:47about any kind of, you know, database
  615. 22:49management systems that are out there
  616. 22:51like MySQL, PostgreSQL, Oracle, SQLite,
  617. 22:54any of that stuff, um
  618. 22:57pretend we don't know about that, we're
  619. 22:57just kind of building a an application
  620. 22:59up ourselves, and what this is going to
  621. 23:02require is that, um, the application
  622. 23:05needs to, uh,
  623. 23:07parse the file each time it wants to
  624. 23:08read anything, and it's going to have
  625. 23:10to, you know, read a line, split the
  626. 23:11CSV,
  627. 23:12um, and kind of figure out what's going
  628. 23:13on every single time we want to access
  629. 23:15the data. So,
  630. 23:16um, again, here's here's just a simple
  631. 23:19example using the, um,
  632. 23:22music store, where we have two
  633. 23:24essentially tables stored as CSV files.
  634. 23:27So, there's the artist table, where we
  635. 23:30have the the name of the artist, uh, the
  636. 23:32year they they first started, um,
  637. 23:35releasing music, and the country they're
  638. 23:36from. And in this, uh,
  639. 23:39second album table,
  640. 23:41um,
  641. 23:42we have the the name of the album, the
  642. 23:44artist that released it, and the year it
  643. 23:47was, uh, released.
  644. 23:51So,
  645. 23:52now let's say that that we want to issue
  646. 23:55essentially a query on on the data that
  647. 23:58we have, and we want to know the year,
  648. 24:00uh, that Ice Cube went solo. Um,
  649. 24:04all right, so we know that
  650. 24:07Ice Cube had had some, uh, disagreements
  651. 24:09about the amount of money he was making,
  652. 24:11so he he decided to go solo,
  653. 24:13um, and start releasing albums on his
  654. 24:14own. So,
  655. 24:16um,
  656. 24:17I guess the the the way that we would do
  657. 24:19this if we have these CSV files is, um,
  658. 24:23you write, you know, you could write
  659. 24:24some kind of like, uh, Python program
  660. 24:26that looks something like this, where,
  661. 24:29uh, essentially you open up a file, and
  662. 24:30then you would iterate over every line
  663. 24:32in the file.
  664. 24:33Um, and all you have to do is take the
  665. 24:34line, remember it's just a CSV, uh,
  666. 24:37string, you have to parse it into a
  667. 24:39record, and then what you want to do is
  668. 24:41check if the,
  669. 24:43um,
  670. 24:44uh,
  671. 24:45value at position zero in the record is
  672. 24:48Ice Cube, cuz we're looking for when Ice
  673. 24:49Cube
  674. 24:51went solo, and, uh, you want to print
  675. 24:53out the, uh, the year, so we're going to
  676. 24:55cast the the, um,
  677. 24:57the second value in the string into an
  678. 24:59int
  679. 25:00and then return that.
  680. 25:02So, I I guess
  681. 25:05what's the problem with this? It seems
  682. 25:06pretty simple, pretty straightforward.
  683. 25:08Um
  684. 25:10I mean, I guess your your query could
  685. 25:12change. Maybe you want to know when The
  686. 25:14Notorious B.I.G. went solo
  687. 25:17or started releasing his album. You
  688. 25:18could
  689. 25:19just swap out the Ice Cube for for a
  690. 25:22different name and get a different
  691. 25:24result. Or if you want to know the
  692. 25:25country that someone's from,
  693. 25:27just change the position
  694. 25:30that you're printing out there. So, I
  695. 25:32guess this seems fine,
  696. 25:34but can anyone think of, you know, any
  697. 25:36issues that might come up if if you're
  698. 25:38managing things this way?
  699. 25:42Sure.
  700. 25:43Each query takes linear time in the size
  701. 25:45of the data set. Uh that is true. So, if
  702. 25:49the the data gets really large, then
  703. 25:51what you're going to have to do is kind
  704. 25:53of open the file and iterate over all of
  705. 25:55the
  706. 25:56the the lines here. I guess what you
  707. 25:58could do is modify this a little bit to
  708. 26:00as soon as if you know that there's only
  709. 26:02one
  710. 26:03record you're looking for in this case,
  711. 26:05you could modify it a little bit to just
  712. 26:07return as soon as you find it. But,
  713. 26:10that's
  714. 26:11certainly true.
  715. 26:13If if you're if you're not careful with
  716. 26:14how you code this, then
  717. 26:16you might end up
  718. 26:19iterating over every single line in the
  719. 26:20file every single time.
  720. 26:23Yeah.
  721. 26:30Uh that is another problem that can come
  722. 26:32up. So, the the
  723. 26:34statement was that there could be
  724. 26:37duplicate entries for Ice Cube and
  725. 26:39there's no way to ensure
  726. 26:41using this method that
  727. 26:45someone doesn't come in and you don't
  728. 26:46put in another record
  729. 26:48for Ice Cubes. And we there's no way to
  730. 26:50maintain kind of the um
  731. 26:54the
  732. 26:55invariant we want only one record to
  733. 26:57represent ice cream. Yes.
  734. 26:59That's another problem.
  735. 27:02Any others?
  736. 27:04I have a whole list I can go through.
  737. 27:06Okay, so
  738. 27:07the first problem
  739. 27:09or the first a series of problems
  740. 27:11relates to
  741. 27:13data integrity. So
  742. 27:16one problem might be is how do we ensure
  743. 27:18that the artist is the name
  744. 27:21the name of the artist is the same for
  745. 27:22each
  746. 27:23album entry. So if you remember
  747. 27:27in order to figure out you know kind of
  748. 27:28which
  749. 27:30artists have released which albums we
  750. 27:32store the artist name in the album CSV
  751. 27:36file. So
  752. 27:39imagine that that
  753. 27:41you know you you
  754. 27:44type in a wrong a wrong name to update
  755. 27:47one of the the album rows or
  756. 27:52you know an artist changes their name or
  757. 27:55that sort of thing. So how how do you
  758. 27:57ensure that there's consistency between
  759. 27:59the name that an artist lists in the
  760. 28:03artist file and the name that the artist
  761. 28:05lists in the albums file.
  762. 28:08Another problem that can come up is you
  763. 28:10know what if someone
  764. 28:11overwrites the album year
  765. 28:16in the the album file with an invalid
  766. 28:18string. So in that code I showed you
  767. 28:20you're expecting an integer
  768. 28:22that that represents a year when
  769. 28:27the album was released. Someone comes in
  770. 28:29and puts in just a regular string
  771. 28:32then your your code's going to break.
  772. 28:34There's going to be a problem parsing
  773. 28:36it.
  774. 28:37And again there's no kind of I guess you
  775. 28:41could have access control on your files
  776. 28:42but you know once someone's able to get
  777. 28:44in the file they could just make a
  778. 28:45mistake and put in an invalid value for
  779. 28:48a particular field.
  780. 28:51Uh
  781. 28:52what if there are multiple artists on an
  782. 28:54album? So, uh everything I showed, um
  783. 28:58you know, each each album only had an
  784. 28:59individual artist, so it's just one um
  785. 29:03field in the CSV string, but um you
  786. 29:06know, imagine that there's a a
  787. 29:08um
  788. 29:09multiple artists on a on an album like a
  789. 29:11mixtape or something. So, um
  790. 29:14in that case, I guess, you know, you
  791. 29:16could
  792. 29:17um
  793. 29:18uh
  794. 29:19change the format instead of being a
  795. 29:21single string, you could put, you know,
  796. 29:23a
  797. 29:23comma-separated list inside uh the field
  798. 29:26of the CSV file, but then you're, you
  799. 29:29know, uh
  800. 29:30complicating your parsing code. You have
  801. 29:32to go back and adjust your parsing code
  802. 29:34to now handle um
  803. 29:36you know, potentially one or more
  804. 29:38um values in that field.
  805. 29:41And kind of the last problem, and I
  806. 29:43these are just a
  807. 29:45a few that that I, you know, came up
  808. 29:47with here, but uh there are many, many
  809. 29:48more, but uh what happens if we delete
  810. 29:51an artist that has albums? So, imagine
  811. 29:54that, you know, you you deleted the
  812. 29:56record for
  813. 29:57um
  814. 29:58Ice Cube in the artist file, and now he
  815. 30:02has a bunch of um
  816. 30:04records or a bunch of records
  817. 30:07representing albums in um
  818. 30:11the album table, and now there there's
  819. 30:12no
  820. 30:13uh uh
  821. 30:14artist committing that they wanted to.
  822. 30:18Okay. So, that's kind of the data data
  823. 30:20integrity side. Uh from an
  824. 30:23information implementation perspective,
  825. 30:25and uh this was um
  826. 30:27one of the the points made is how do you
  827. 30:30find a particular record? So, again, the
  828. 30:32example,
  829. 30:33um you end up in in the code that I
  830. 30:35showed iterating through every single
  831. 30:38row every single time
  832. 30:40um
  833. 30:41you want to find something. I mean, you
  834. 30:43you there are all sorts of ways to
  835. 30:44optimize it. For example, if you know
  836. 30:46the data is sorted, you could do like a
  837. 30:48binary search or something. Um,
  838. 30:51or if you have
  839. 30:53a data structure that stores it, maybe
  840. 30:55like a a hash table or something, you
  841. 30:57could um index directly to
  842. 31:00um
  843. 31:01the the
  844. 31:02the record you're looking for. But, just
  845. 31:04you know, all of these things you're
  846. 31:06building up additional complexity in
  847. 31:08your Python program that you have to
  848. 31:10write
  849. 31:11um
  850. 31:12to access the code. So,
  851. 31:14uh all of that kind of implementation
  852. 31:16efficiency needs to be taken into
  853. 31:17consideration when when you're designing
  854. 31:19your application.
  855. 31:21Similarly, what if we want to create a
  856. 31:23new application that uses the same
  857. 31:24database? So, the database is stored in
  858. 31:27the CSV files. Imagine that, you know,
  859. 31:29someone else for some other purpose
  860. 31:31wants to come along and access the same
  861. 31:33CSV files
  862. 31:34uh concurrently. Do you want them to
  863. 31:36have to rewrite kind of all of the
  864. 31:38Python code that you've had built up? Or
  865. 31:42uh maybe they need to do it in a
  866. 31:43different language. Um, but the point is
  867. 31:46that kind of you've you've had to do uh
  868. 31:49the work to build up uh the this
  869. 31:51application, and now it has to be
  870. 31:53replicated every time someone else wants
  871. 31:55to access the same data. And even for
  872. 31:57you, um
  873. 31:59you know, like I said, if you want to
  874. 32:00change the query or or um
  875. 32:03change change things that you're looking
  876. 32:05for, you run into the problem of having
  877. 32:07to kind of re-implement things from
  878. 32:09scratch every single time.
  879. 32:12So, um
  880. 32:13kind of another implementation question
  881. 32:15is, what if two threads or two programs
  882. 32:17uh try to write to the the file at the
  883. 32:20same time? You know, if if I'm editing a
  884. 32:22file and you're editing the file,
  885. 32:24um and we both save our work,
  886. 32:26um
  887. 32:27who knows what's going to happen? Uh you
  888. 32:29know, one of us might uh
  889. 32:31overwrite the other, or maybe both of
  890. 32:34our writes get partially written, and
  891. 32:35now you have kind of this garbage re- a
  892. 32:38record in there. So, what you can end up
  893. 32:40with is
  894. 32:42kind of all of this you have to
  895. 32:44implement some kind of concurrency layer
  896. 32:46to manage concurrent accesses to
  897. 32:49the data.
  898. 32:52So, the final piece
  899. 32:53that I'm going to talk about is
  900. 32:55durability, which means like what
  901. 32:58happens if the machine crashes when when
  902. 33:00the program is updating a record. So,
  903. 33:02you're doing right
  904. 33:05power goes out or something or or the
  905. 33:07your program crashes and
  906. 33:09you know, now
  907. 33:11what happens to the data? Is it
  908. 33:12consistent? Did you finish writing the
  909. 33:14whole record you wanted to write or
  910. 33:17is it kind of
  911. 33:19half written now you have again this
  912. 33:20this garbage garbage value
  913. 33:23um
  914. 33:24in your your database.
  915. 33:27Uh
  916. 33:28what if we want to replicate the
  917. 33:29database on multiple machines so that we
  918. 33:31can have high availability?
  919. 33:33How do we handle kind of concurrent
  920. 33:34writes to different machines?
  921. 33:37Because now the machines need to be
  922. 33:39synchronized across them and kind of the
  923. 33:41list goes on and on and on with all of
  924. 33:43these problems that can come up. So,
  925. 33:45that's kind of the the reason why we
  926. 33:48want to build a database management
  927. 33:49system so we don't have to handle all of
  928. 33:52this complexity, all of those different
  929. 33:53types of problems that I mentioned in
  930. 33:55application code.
  931. 34:01Okay, so I explained what a database is.
  932. 34:04The software that manages database is
  933. 34:08a database management system.
  934. 34:10Sometimes people use the words
  935. 34:12interchangeably. I will try not to
  936. 34:13because
  937. 34:14it's confusing, but a database
  938. 34:16management system or DBMS is a system,
  939. 34:19the software that manages
  940. 34:22um the database and allows applications
  941. 34:25to store, retrieve, and analyze
  942. 34:27information that's that's stored in the
  943. 34:29database. So, rather than managing
  944. 34:31things in these
  945. 34:34CSV files, you can
  946. 34:36access them through the database and it
  947. 34:38kind of gives you all of these nice
  948. 34:39properties
  949. 34:41um
  950. 34:42that that avoid the problems that that I
  951. 34:44mentioned before.
  952. 34:45And a general purpose DBMS is designed
  953. 34:49to allow you to
  954. 34:52define, create, query, update, and
  955. 34:54administer databases
  956. 34:57in in a generic sense. So, if you have
  957. 34:59again an application for
  958. 35:02managing students in a class or for
  959. 35:04managing
  960. 35:06um
  961. 35:07an online music store,
  962. 35:09kind of it's it's general purpose enough
  963. 35:11that you can program your applications
  964. 35:16against the system. So, this really good
  965. 35:18for
  966. 35:20like business reasons for your business
  967. 35:22or startup or your your organization
  968. 35:24because the the purpose
  969. 35:26the value add that you're bringing is
  970. 35:28not
  971. 35:29the you can store data, lots of people
  972. 35:31can store data, but
  973. 35:33what what a
  974. 35:35database management system allows you to
  975. 35:37do is focus on, you know, the the core
  976. 35:39aspect of your business rather than
  977. 35:40worrying about all of these
  978. 35:43um
  979. 35:44uh
  980. 35:45issues surrounding actually managing the
  981. 35:47data. And, you know, DBMSs are widely
  982. 35:51tested and deployed
  983. 35:53so that they, you know, find all the
  984. 35:55bugs, the concurrency bugs, the
  985. 35:58consistency bugs, all those problems
  986. 35:59that come up
  987. 36:01because kind of, you know, the the
  988. 36:03chances that that every single Python
  989. 36:05program that you write is going to be
  990. 36:07100% bug free all the time are pretty
  991. 36:10much zero. So,
  992. 36:12kind of the the the whole point of a
  993. 36:14database management system is that you
  994. 36:16can leverage kind of this this core set
  995. 36:19of functionality
  996. 36:21for managing databases so you don't have
  997. 36:23to do it manually at in in application
  998. 36:25code.
  999. 36:28So, I I
  1000. 36:30database management systems are not new.
  1001. 36:34Um the first one came out in 1965
  1002. 36:38um at General Electric was called IDM.
  1003. 36:40And essentially
  1004. 36:42um
  1005. 36:44they were they were used kind of to to
  1006. 36:46manage data, but they were really uh
  1007. 36:49writing applications um they were really
  1008. 36:51difficult to build and maintain.
  1009. 36:54And that's because people were working
  1010. 36:56in very low level and there was you know
  1011. 36:58really tight coupling between
  1012. 37:00um the logical layer, so kind of the the
  1013. 37:03data model layer and and the physical
  1014. 37:05layer that like the implementation
  1015. 37:07writing to disk or retrieving it from
  1016. 37:08disk query and that kind of stuff.
  1017. 37:10Um
  1018. 37:12So,
  1019. 37:14kind of the the the big problem is that
  1020. 37:16you had to know the the queries that you
  1021. 37:18wanted your uh application execute
  1022. 37:20before you deployed the database and um
  1023. 37:23they were just really cumbersome and not
  1024. 37:25not easy to work with. So,
  1025. 37:27um kind of the things that that we're
  1026. 37:29going to talk about over the course of
  1027. 37:30the semester um might seem obvious in
  1028. 37:34retrospect, but at the time uh you know
  1029. 37:36people were struggling to build these
  1030. 37:37applications and and they were kind of
  1031. 37:39controversial. The ideas were were kind
  1032. 37:41of controversial. So,
  1033. 37:43there was this guy um at IBM named Ted
  1034. 37:45Codd. Uh that's him.
  1035. 37:47Uh who kind of observed that people were
  1036. 37:50were re-implementing the same things
  1037. 37:52over and over again reinventing the
  1038. 37:53wheel
  1039. 37:54um and and you know making a lot of
  1040. 37:56mistakes uh along the way. So, he
  1041. 37:58proposed kind of this this uh high-level
  1042. 38:01idea called the relational model.
  1043. 38:04And there is this original uh and it
  1044. 38:06came out as a technical report in 1969,
  1045. 38:09but nobody uh reads this one. This is
  1046. 38:11the one that everyone references came
  1047. 38:13out the year later in 1970.
  1048. 38:15Um
  1049. 38:16and it it's a paper called A Relational
  1050. 38:19Model of Data for Large Shared Data
  1051. 38:21Banks.
  1052. 38:22Um
  1053. 38:23and you know it's old because people
  1054. 38:27when when when they wrote in the the
  1055. 38:29text they spelled data and base as two
  1056. 38:32separate words and now we have it
  1057. 38:34combined as one. But um kind of the the
  1058. 38:37the core idea that he proposed um
  1059. 38:41was the relational model and he actually
  1060. 38:44won the Turing Award in 1981 if you know
  1061. 38:47what that is. Um it's like
  1062. 38:50the
  1063. 38:51people call it the Nobel Prize for
  1064. 38:52computing. It's like the highest um
  1065. 38:56honor you can receive in in computer
  1066. 38:57science. And he he he he won it for um
  1067. 39:03the relational model and
  1068. 39:04as I said it was kind of
  1069. 39:06um
  1070. 39:07controversial at the time. I mean you
  1071. 39:08can look at it now and say oh yeah sure
  1072. 39:09that makes sense but
  1073. 39:11um at the time I it it wasn't so
  1074. 39:14obvious. So kind of the relational model
  1075. 39:16at a high level is
  1076. 39:18a database abstraction to avoid avoid a
  1077. 39:20lot of low-level maintenance
  1078. 39:22um and problems that people were running
  1079. 39:24into writing
  1080. 39:25um
  1081. 39:26database applications. So
  1082. 39:29uh
  1083. 39:29the the the
  1084. 39:31kind of three main points um that
  1085. 39:34they're going to touch on are are the
  1086. 39:37the the databases database databases
  1087. 39:39should be stored in a simple uh data
  1088. 39:42structure called a relation
  1089. 39:44um
  1090. 39:45where a relation essentially represents
  1091. 39:48uh the relationship among attributes
  1092. 39:51stored in a table. So like the
  1093. 39:53relationship if if you um are thinking
  1094. 39:55about the the artist example um the
  1095. 39:59relationship between the artist name um
  1096. 40:02the the year
  1097. 40:04uh that they that they started producing
  1098. 40:06music and the the country they're from.
  1099. 40:07So the relationship between those
  1100. 40:08attributes.
  1101. 40:09Um
  1102. 40:11kind of the the the next piece is that
  1103. 40:13he thought you should access data
  1104. 40:14through a high-level language um
  1105. 40:18rather than kind of
  1106. 40:20telling the database database management
  1107. 40:22system explicitly how
  1108. 40:25how you want it to get the data.
  1109. 40:27Um you could just specify what data you
  1110. 40:29want it and let the database management
  1111. 40:31system figure out kind of the best
  1112. 40:33strategy to do it
  1113. 40:35because you know if if
  1114. 40:37you're building a piece of software
  1115. 40:39that's specialized to interact with
  1116. 40:40databases, it should it should be pretty
  1117. 40:43good at figuring out the best way to get
  1118. 40:45you the data you want.
  1119. 40:47Um and and finally
  1120. 40:50the the last piece is that the physical
  1121. 40:52storage of the data either at the time
  1122. 40:57on on disk or secondary storage um now
  1123. 41:01in memory also should be left up to
  1124. 41:04the the DBMS to implement. So you don't
  1125. 41:06have to worry about whether it's laid
  1126. 41:07out in in a row format in CSV file, it's
  1127. 41:11just completely abstracted to you. You
  1128. 41:12just know
  1129. 41:14what the data is that's in there and get
  1130. 41:15that and let the the DBMS kind of figure
  1131. 41:17out the specifics of of storing it. And
  1132. 41:20you know at the time like I said people
  1133. 41:22argued that um
  1134. 41:24a DBMS would never be able to generate a
  1135. 41:26query plan as efficient as kind of what
  1136. 41:30what a human could do kind of like how
  1137. 41:32people used to argue about you know
  1138. 41:33compilers. No one could ever
  1139. 41:35produce code that's uh
  1140. 41:38you know no no
  1141. 41:40computer program compiler could ever
  1142. 41:41produce code that's as efficient as what
  1143. 41:44uh
  1144. 41:44assembly that a human could write. Now
  1145. 41:47almost no one writes at that level. So
  1146. 41:49kind of it's the same idea
  1147. 41:51with databases. There there was a lot of
  1148. 41:53human effort that went into designing
  1149. 41:56programs to efficiently access it
  1150. 41:57because they thought that um
  1151. 42:00you couldn't design a
  1152. 42:01a system to do it efficiently.
  1153. 42:05So um
  1154. 42:08I I mentioned that the relational model
  1155. 42:10is a type of data model. So a data model
  1156. 42:13is just essentially at a high level a
  1157. 42:15collection of concepts
  1158. 42:17uh for describing the data that's stored
  1159. 42:20in in a database. So, it's like a
  1160. 42:22high-level abstraction
  1161. 42:24um for for how we're going to represent
  1162. 42:27data.
  1163. 42:28Now, a schema
  1164. 42:30um is more specifically a description of
  1165. 42:33a a particular collection of data
  1166. 42:37given a a data model. So, what does that
  1167. 42:39mean? Um
  1168. 42:41it means that the the schema
  1169. 42:44defines exactly what we're going to
  1170. 42:46store in the database. So, for example,
  1171. 42:48in the the music store example, um
  1172. 42:51the schema would be the artist
  1173. 42:54table followed by the different uh
  1174. 42:57attributes that are associated with an
  1175. 42:59artist. So, that's the schema that you
  1176. 43:01would define
  1177. 43:02uh that describes the data that's stored
  1178. 43:04in the database.
  1179. 43:08So, there are as I said lots of lots of
  1180. 43:10uh different data models. Um most DBMSs
  1181. 43:14that you may have heard of
  1182. 43:16um are based on this first relational uh
  1183. 43:19data model and um
  1184. 43:23for a lot of reasons, but uh probably
  1185. 43:25the biggest one is that the the
  1186. 43:27relational model is
  1187. 43:29uh probably the most flexible of all of
  1188. 43:32them. Um the relational model can kind
  1189. 43:34of model all of these other or uh um you
  1190. 43:37you you can represent all of these other
  1191. 43:39data models using the relational model.
  1192. 43:43Um and the the the exact, you know,
  1193. 43:45uh
  1194. 43:46uh API or or what's going on behind the
  1195. 43:49scenes might not be as efficient, but um
  1196. 43:51it's still general enough to be able to
  1197. 43:54uh handle all of these other models.
  1198. 43:56So, um
  1199. 44:00NoSQL is a is a a popular term. Um
  1200. 44:04it means a lot of things uh to a lot of
  1201. 44:07different people, but just at kind of a
  1202. 44:09high level
  1203. 44:11um
  1204. 44:14like
  1205. 44:15for example
  1206. 44:16it's more than just a data model. A lot
  1207. 44:18of people when they hear NoSQL think
  1208. 44:19about things like transactions or
  1209. 44:21consistency or not having
  1210. 44:23certain APIs, but just in terms of the
  1211. 44:26actual NoSQL data model it covers kind
  1212. 44:28of this key value
  1213. 44:31stores, graph database management
  1214. 44:33systems, document databases,
  1215. 44:35uh MongoDB,
  1216. 44:37um and and kind of
  1217. 44:38broader column family databases. And
  1218. 44:41um
  1219. 44:44kind of these these data models are more
  1220. 44:48restrictive than what you get with the
  1221. 44:50relational model.
  1222. 44:51And they they don't give you as many as
  1223. 44:53I said kind of guarantees in terms of
  1224. 44:56um
  1225. 44:57different properties that we're going to
  1226. 44:59discuss over the course of the semester.
  1227. 45:01I There are some just
  1228. 45:04often I would say there are some
  1229. 45:05application domains where
  1230. 45:08these data models might make sense. So
  1231. 45:10imagine I don't know you're storing
  1232. 45:12video data or you're storing
  1233. 45:15log data or something. You just want to
  1234. 45:16shove it into a key value store. That's
  1235. 45:19that's
  1236. 45:20perfectly valid and and might be better
  1237. 45:23for that particular type of application
  1238. 45:25than than a relational database.
  1239. 45:29Um array and matrix database management
  1240. 45:33systems are kind of specialized more
  1241. 45:36towards machine learning or
  1242. 45:39scientific applications. There are a few
  1243. 45:41SciDB,
  1244. 45:43TileDB, but they're not they're not
  1245. 45:44really widespread and and kind of
  1246. 45:46they're
  1247. 45:47narrowly focused on these sorts of use
  1248. 45:49cases. And And the last group,
  1249. 45:53hierarchical, network, and multi-value,
  1250. 45:56these are kind of either obsolete data
  1251. 45:58models that people tried out in the past
  1252. 46:00and
  1253. 46:01they find and found didn't work well or
  1254. 46:04they had other problems but they you
  1255. 46:06know they might still be hanging around
  1256. 46:07in legacy systems.
  1257. 46:10So,
  1258. 46:11for the purposes of this course, we're
  1259. 46:13going to be focusing exclusively on the
  1260. 46:16relational model
  1261. 46:18and um
  1262. 46:20how database management system works in
  1263. 46:22in that context.
  1264. 46:29Okay.
  1265. 46:30So,
  1266. 46:31what is the relational model exactly?
  1267. 46:34Um
  1268. 46:36the the
  1269. 46:38relational model
  1270. 46:40uh
  1271. 46:41defines
  1272. 46:42the relations inside the database. So,
  1273. 46:45like I mentioned, the individual tables.
  1274. 46:48Sometimes they in in SQL they're called
  1275. 46:50tables. Um
  1276. 46:52in the relational model they're called
  1277. 46:55um
  1278. 46:56uh relations. I I'll probably end up
  1279. 46:59using them interchangeably um
  1280. 47:01but you can think of them just
  1281. 47:03concretely as those examples from the
  1282. 47:05music store.
  1283. 47:07There's the the artist relation on table
  1284. 47:10and the album
  1285. 47:12relation.
  1286. 47:13And the the structure of the relational
  1287. 47:16model defines those relations and the
  1288. 47:19contents inside them.
  1289. 47:20So, the next piece as I mentioned is
  1290. 47:22integrity
  1291. 47:23which ensures that the database's
  1292. 47:26contents
  1293. 47:28satisfy some constraints. So, um
  1294. 47:31with the the concern about you know
  1295. 47:34uh uh
  1296. 47:34whether or not there could be a garbage
  1297. 47:36string value
  1298. 47:38inserted or overwritten on a on a um
  1299. 47:42uh
  1300. 47:43when you're expecting an integer year,
  1301. 47:46kind of the integrity aspect seeks to to
  1302. 47:49mitigate that problem
  1303. 47:50by forcing all of the the year values to
  1304. 47:53be integers and forcing that property.
  1305. 47:56Uh and finally, there's the the
  1306. 47:58manipulation aspect which is the
  1307. 48:00programming interface or API that you
  1308. 48:01use to access and modify um the contents
  1309. 48:06of the the database. And uh
  1310. 48:09this is what we're going to talk about
  1311. 48:10later
  1312. 48:12in in the lecture uh
  1313. 48:15with relational algebra. So, relational
  1314. 48:17algebra is a is a um
  1315. 48:19uh
  1316. 48:20programming programming interface for
  1317. 48:22interacting with um the relational
  1318. 48:24model.
  1319. 48:26So, uh again kind of just uh uh
  1320. 48:29going through the example, a relation is
  1321. 48:31an unordered set. So, that's important.
  1322. 48:34Um
  1323. 48:35uh
  1324. 48:36there's no order to the values. Uh we
  1325. 48:39don't necessarily care what order they
  1326. 48:41appear in
  1327. 48:42um in the database.
  1328. 48:44Um
  1329. 48:45they could be sorted, they could not be
  1330. 48:46sorted. Uh it doesn't matter. It's just
  1331. 48:48a set.
  1332. 48:50Um and it contains the relationship uh
  1333. 48:55uh of the attributes that represent
  1334. 48:57entities. So, as I said a relation or
  1335. 49:00table has many entries that are called
  1336. 49:04uh
  1337. 49:04um tuples, tapples some people say. I
  1338. 49:07don't Either's fine with me.
  1339. 49:09Um but I'll I'll probably end up saying
  1340. 49:10both, but uh tuples or records also in a
  1341. 49:14table. Tuple or record is
  1342. 49:16interchangeable. There's There's another
  1343. 49:18word that sometimes people use uh called
  1344. 49:20rows.
  1345. 49:21Um
  1346. 49:22I will try not to use that. I might
  1347. 49:23accidentally, but uh a row implies
  1348. 49:26something specific about how the data is
  1349. 49:28stored. So, in the the um CSV example,
  1350. 49:31you know, every every uh data was stored
  1351. 49:33as a individual line. Um but the the
  1352. 49:38uh tuples and records represent
  1353. 49:40individual uh data entries
  1354. 49:43in a table.
  1355. 49:44Um
  1356. 49:45The the values are uh normally um scalar
  1357. 49:51values, things like integers, strings.
  1358. 49:53That's not necessarily true anymore. Um,
  1359. 49:55the original specification they all had
  1360. 49:57to be kind of these scalar values, but
  1361. 49:59um, any popular systems uh have started
  1362. 50:03relaxing it to store things like uh
  1363. 50:05store a, you know, array maybe in a
  1364. 50:07individual column or like a a JSON
  1365. 50:09document um, in an individual individual
  1366. 50:12um,
  1367. 50:13attribute.
  1368. 50:14Um, and there's also this notion of uh a
  1369. 50:18null, which is a member of every single
  1370. 50:21uh domain. It can be any um, attribute
  1371. 50:24can be set to null, and it it's not
  1372. 50:26exactly like null in uh
  1373. 50:28like a null pointer or something, but uh
  1374. 50:31it used to signify that we don't know
  1375. 50:34what a particular value is. So, for
  1376. 50:36example, if if um,
  1377. 50:39the the country that I I SKU is from
  1378. 50:42uh were null, it it just means that we
  1379. 50:43don't we don't know what that value uh
  1380. 50:46what
  1381. 50:47we don't know the specific value for
  1382. 50:48that um, record.
  1383. 50:51So,
  1384. 50:52uh
  1385. 50:53uh uh
  1386. 50:54again, just a a relation is a is a a
  1387. 50:56mathematical term that represents um,
  1388. 50:58this unordered set, and
  1389. 51:02uh
  1390. 51:03SQL the the SQL equivalent is is a
  1391. 51:05table.
  1392. 51:08So, in n-ary relation, if I say n-ary
  1393. 51:11relation, it means that there's a table
  1394. 51:13with n individual columns and individual
  1395. 51:16attributes. So, that's just it's a
  1396. 51:18three columns.
  1397. 51:24Okay, so a a big piece of um, the
  1398. 51:27relational model is um,
  1399. 51:30that every relation should have a
  1400. 51:33primary key that uniquely identifies uh
  1401. 51:37a single tuple.
  1402. 51:39So, um,
  1403. 51:41some DBMSs will will automatically
  1404. 51:43create this for you. If you don't
  1405. 51:45specify it, they'll do it behind the
  1406. 51:46scenes. Kind think about like a you
  1407. 51:48know, auto incrementing uh um unique
  1408. 51:50integer um for for keys.
  1409. 51:54So, in this this uh table example here,
  1410. 51:57um
  1411. 51:58there's not really anything that we can
  1412. 52:00use to uniquely identify. I guess I
  1413. 52:02mean, you could potentially use the name
  1414. 52:04of the artist um
  1415. 52:07to uniquely identify, but I there's no
  1416. 52:09guarantee that, you know, all of those
  1417. 52:11values are going to be unique. So, um
  1418. 52:15what you can do is add kind of this
  1419. 52:17surrogate primary key that's essentially
  1420. 52:19just a just an integer. And like I said,
  1421. 52:21it could be auto generating or random or
  1422. 52:23whatever. Um
  1423. 52:25kind of just to to keep uh each each
  1424. 52:28record or tuple um unique.
  1425. 52:32So,
  1426. 52:34foreign keys uh
  1427. 52:37are are related to primary keys in that
  1428. 52:40they specify
  1429. 52:41um that an attribute from one relation
  1430. 52:44has a mapping uh to to some tuple in
  1431. 52:47another relation.
  1432. 52:49So,
  1433. 52:50just concretely, um if we have this
  1434. 52:54artist key here, and we have the album
  1435. 52:57key,
  1436. 52:58we know that uh the artists, so the the
  1437. 53:02new primary key ID numbers that we've
  1438. 53:04added to the album table, um the artists
  1439. 53:08uh
  1440. 53:091 2 3 7 8 9 reference artists stored
  1441. 53:14tuples stored in the uh artist table.
  1442. 53:16So, if we want to know
  1443. 53:18um
  1444. 53:19you know,
  1445. 53:20who wrote one of these or who released
  1446. 53:22one of these albums, we can go look up,
  1447. 53:24okay, what's the number um
  1448. 53:26of the artist, and then go look up which
  1449. 53:28artist that is uh in in the artist
  1450. 53:30table. But, you know, there's a problem
  1451. 53:31you can run into
  1452. 53:33uh which is I I mentioned earlier, which
  1453. 53:35is what if you want to have um
  1454. 53:38multiple artists uh uh, on on a single
  1455. 53:41album. So, again, you can release like a
  1456. 53:43mixtape or something where you have a
  1457. 53:45lot of different artists contributing,
  1458. 53:47but we only have this one,
  1459. 53:49um,
  1460. 53:49attribute to store, uh, the artist ID.
  1461. 53:53And the solution we come up with in, uh,
  1462. 53:56the relational model
  1463. 53:58is to create this, uh, a third table,
  1464. 54:01sometimes called a join table, which is
  1465. 54:03going to join or link,
  1466. 54:06the artist table with the album table.
  1467. 54:09So, we're going to do is we're going to
  1468. 54:10we're going to get rid of that artist
  1469. 54:12column in the album table
  1470. 54:14and instead, uh, create this new artist
  1471. 54:17album table that has only two things in
  1472. 54:19it. So, it has an artist ID and an album
  1473. 54:22ID.
  1474. 54:23And now, if if you look at it, we can
  1475. 54:25figure out, okay, here is how all of
  1476. 54:27the, uh, artists link to the the albums
  1477. 54:31that they they release. So,
  1478. 54:33in the case where you have, um,
  1479. 54:36you know,
  1480. 54:37one,
  1481. 54:38uh, uh,
  1482. 54:40artist on an album, then there's only
  1483. 54:42going to be one, uh, tuple in the artist
  1484. 54:45album relation. In the case where you
  1485. 54:47have multiple, you'll have now multiple
  1486. 54:49tuples.
  1487. 54:58Okay, so, data manipulation languages or
  1488. 55:01DML
  1489. 55:03are, um, the specific methods that that
  1490. 55:05we use to store and retrieve, um,
  1491. 55:07information from a database.
  1492. 55:10And they come specifically in in two
  1493. 55:13flavors. So, the first is procedural,
  1494. 55:16uh, and that's
  1495. 55:17uh,
  1496. 55:18that that a high-level query should
  1497. 55:21specify how the DBMS should compute the
  1498. 55:25answer to our query.
  1499. 55:27So, the keyword here is how. You're
  1500. 55:29telling the database how you want it to
  1501. 55:31retrieve the data.
  1502. 55:33And this is going to be, uh, uh,
  1503. 55:35relational algebra that we talked about,
  1504. 55:37uh, in in a couple slides here, um,
  1505. 55:40you're saying specifically how you want
  1506. 55:42the data to retrieve from the database.
  1507. 55:46Uh, the alternative is a non-procedural
  1508. 55:48or declarative language,
  1509. 55:50um, where, uh, you only specify what
  1510. 55:55data you want retrieved from the
  1511. 55:56database. You know, you don't tell the
  1512. 55:57database management system how you want
  1513. 55:59to get it back.
  1514. 56:01You just say, uh, what data you want,
  1515. 56:03and then the the system goes and figures
  1516. 56:05out how to how to do that for you.
  1517. 56:07So,
  1518. 56:08um, an example of this
  1519. 56:11non-procedural, uh, or declarative
  1520. 56:13language, um,
  1521. 56:15is relational calculus. I
  1522. 56:17We're not going to talk too much about
  1523. 56:18relational calculus in this class.
  1524. 56:20Um, it's important. It's, uh, really
  1525. 56:23important for query optimization,
  1526. 56:25um, but it's it's not really being
  1527. 56:27covered in this class, so don't worry
  1528. 56:28too much about it. Um,
  1529. 56:30relational algebra and relational
  1530. 56:32calculus are are,
  1531. 56:35like they're they're logically
  1532. 56:36equivalent, um, but we're, like I said,
  1533. 56:39only going to be focusing on on, uh,
  1534. 56:41this first one. Another example of, uh,
  1535. 56:44a declarative language is SQL, um, which
  1536. 56:46we're going to talk about next class.
  1537. 56:51So,
  1538. 56:52relational algebra defines the original
  1539. 56:55the original, um, specification defines
  1540. 56:57these, uh,
  1541. 56:58seven operators, and they're all
  1542. 57:01fundamental operations that you can use,
  1543. 57:04uh, to retrieve and manipulate the the
  1544. 57:07tuples in a relation. This is this These
  1545. 57:10are the the fundamental operators
  1546. 57:11proposed by, um, Codd.
  1547. 57:14And,
  1548. 57:15um,
  1549. 57:16they're based on, uh, mathematical ideas
  1550. 57:19of, uh, set algebra.
  1551. 57:22So, each operator listed here is going
  1552. 57:24to take in one or more relations as
  1553. 57:27input, and it's going to output a new
  1554. 57:29relation.
  1555. 57:31So, um, in order to build up a query to
  1556. 57:34to get the data you want out of your
  1557. 57:35database, uh you can kind of chain these
  1558. 57:37operators together um to create more
  1559. 57:40complex operations.
  1560. 57:43So, we'll just kind of go through each
  1561. 57:44one starting with uh select.
  1562. 57:46Um
  1563. 57:48Sorry, is there a question? No?
  1564. 57:50Um so,
  1565. 57:53uh
  1566. 57:54starting with select, essentially the
  1567. 57:55the goal of the select operator is to uh
  1568. 57:59choose a subset of the the tuples from a
  1569. 58:01relation
  1570. 58:03um that satisfy a particular predicate
  1571. 58:05that you uh provide.
  1572. 58:08So, the predicate, you can think about
  1573. 58:09it acting like a filter or kind of like
  1574. 58:11an if statement um that's only going to
  1575. 58:14retain
  1576. 58:15uh the tuples that qualify um
  1577. 58:18for for the the user-specified
  1578. 58:20predicate. And you can of course combine
  1579. 58:24um multiple multiple predicates using um
  1580. 58:27conjunctions or disjunctions uh to get
  1581. 58:29exactly the
  1582. 58:31the uh
  1583. 58:32subset that you want. Uh I think it's
  1584. 58:34called restrict in the original um
  1585. 58:37relational model paper, but um
  1586. 58:40everyone everyone calls it a select. Uh
  1587. 58:43the the symbol is the lowercase sigma.
  1588. 58:45Um
  1589. 58:47uh
  1590. 58:48in in relational algebra. So, just as an
  1591. 58:50example, we have this really simple
  1592. 58:52relation here. Uh R, it only has two
  1593. 58:56attributes or columns, AID and BID.
  1594. 59:00Uh so, if we want to, for example, uh
  1595. 59:05restrict um
  1596. 59:07or filter the uh relation to only cases
  1597. 59:11where AID equals A2, then we apply that
  1598. 59:16uh predicate, and we get back
  1599. 59:18uh just that subset that satisfies the
  1600. 59:21predicate that we that we specified.
  1601. 59:24And as I said, you you kind of chain
  1602. 59:25things together and then
  1603. 59:27"Okay, give me all of the the records
  1604. 59:29where AID equals A2 and
  1605. 59:32BID equal or is greater than 102." So,
  1606. 59:36in this case, you can see you're you're
  1607. 59:37only going to get that one
  1608. 59:39tuple.
  1609. 59:41Uh and then if you're wondering how this
  1610. 59:43how this works with SQL, I I apologize.
  1611. 59:45I didn't come up with the the naming
  1612. 59:47convention, but the the select
  1613. 59:49relational algebra operator maps to the
  1614. 59:52where clause in a SQL statement.
  1615. 59:55Um
  1616. 59:56might be a little confusing, but select
  1617. 59:58in relational algebra maps to where
  1618. 1:00:00clause.
  1619. 1:00:01Uh
  1620. 1:00:02and again, we'll talk more about SQL
  1621. 1:00:04next time, so we'll go through these
  1622. 1:00:06individually. But, um
  1623. 1:00:08the projection statement is essentially
  1624. 1:00:10going to generate a relation
  1625. 1:00:13with tuples that only contain the
  1626. 1:00:15attributes that you asked for. And what
  1627. 1:00:18does that mean? You can do all sorts of
  1628. 1:00:19things like rearrange the order of the
  1629. 1:00:21attributes.
  1630. 1:00:22Um you can manipulate the values of the
  1631. 1:00:24attributes.
  1632. 1:00:25Um
  1633. 1:00:27do different types of modifications.
  1634. 1:00:29It's It's specified with the lowercase
  1635. 1:00:30pi symbol and and essentially a list of
  1636. 1:00:33all of the different modifications
  1637. 1:00:35you're making.
  1638. 1:00:37So, um
  1639. 1:00:39here is just a an example query
  1640. 1:00:42where
  1641. 1:00:43again, we're doing the selection first.
  1642. 1:00:45So, I mentioned you could chain them
  1643. 1:00:46together. We're doing the selection
  1644. 1:00:48first to get only the records that have
  1645. 1:00:50AID equals A2, and then we're performing
  1646. 1:00:53a projection um
  1647. 1:00:56where we're going to modify B by
  1648. 1:00:58subtracting 100, and we're going to put,
  1649. 1:01:01you know, swap the order of
  1650. 1:01:03BID and AID. And that's that's kind of
  1651. 1:01:05the result you get. So, again, this is
  1652. 1:01:08I didn't come up with the names,
  1653. 1:01:10but the projection operator maps to the
  1654. 1:01:13select clause of the SQL statement. So,
  1655. 1:01:16the the selection operator maps to the
  1656. 1:01:18where clause, the projection operator
  1657. 1:01:20maps to the select clause.
  1658. 1:01:26The union operator is essentially going
  1659. 1:01:29to um
  1660. 1:01:31generate a relation that contains all
  1661. 1:01:33the tuples that appear in um
  1662. 1:01:36either or or both relations. Uh it's
  1663. 1:01:40just like a set union.
  1664. 1:01:42Um so for example, imagine we have
  1665. 1:01:43another second table here S which has
  1666. 1:01:45the same schema as the first one. Um
  1667. 1:01:49to perform uh R union S
  1668. 1:01:52is going to give us essentially all of
  1669. 1:01:53the tuples that appear in R, all of the
  1670. 1:01:55tuples that appear in S.
  1671. 1:01:57And uh the the SQL syntax for this is a
  1672. 1:01:59little bit different. It's union all in
  1673. 1:02:01order to get um potential duplicates
  1674. 1:02:05um
  1675. 1:02:06because of a a difference between
  1676. 1:02:08um
  1677. 1:02:09uh set algebra and like a
  1678. 1:02:11uh a bag or multi-set algebra.
  1679. 1:02:14So you can see here that there are there
  1680. 1:02:16is the the the duplicate that appears in
  1681. 1:02:18in the
  1682. 1:02:20union.
  1683. 1:02:22So in in this example, I the the output
  1684. 1:02:24is ordered, but that's again not
  1685. 1:02:27necessarily be true um because it's a
  1686. 1:02:29set they could appear in uh the output
  1687. 1:02:32relation could appear in any order.
  1688. 1:02:34And the answer would still, you know,
  1689. 1:02:36still be considered correct. So you
  1690. 1:02:37can't count on that the ordering there.
  1691. 1:02:40Uh the intersection operator um is going
  1692. 1:02:43to generate a relation that only
  1693. 1:02:45contains the tuples that appear in both
  1694. 1:02:48of the input relations. So this is R
  1695. 1:02:50intersect S. Again, it's the same um
  1696. 1:02:53example where R and S both have the same
  1697. 1:02:55schema, and what we want to do is find
  1698. 1:02:57kind of the intersection.
  1699. 1:02:59Uh it's going to give us only A3 appears
  1700. 1:03:03in both R and S. So you can do this in
  1701. 1:03:07uh in SQL using the the intersect
  1702. 1:03:10operator. So just as an example of when
  1703. 1:03:12this might be useful, uh if you think
  1704. 1:03:14about the the music store example, um
  1705. 1:03:17maybe we have one relation representing
  1706. 1:03:19the rap artists and another one
  1707. 1:03:20representing
  1708. 1:03:22rock or country artists and you want to
  1709. 1:03:24know which artists have
  1710. 1:03:27you know both rap albums and you know
  1711. 1:03:29rock or country albums. So, you would
  1712. 1:03:31just do an intersection of the two
  1713. 1:03:33relations to get that answer.
  1714. 1:03:38The difference operator
  1715. 1:03:40is going to generate a relation that
  1716. 1:03:42contains only the tuples that appear in
  1717. 1:03:44the first relation and not the second
  1718. 1:03:46relation.
  1719. 1:03:48So, in this example here, you end up
  1720. 1:03:50with only the the unique ones that
  1721. 1:03:52appear in appear in R and not in S.
  1722. 1:03:57And you can do that in SQL using the
  1723. 1:03:59except
  1724. 1:04:00keyword.
  1725. 1:04:05Okay, the product
  1726. 1:04:06is essentially going to generate a
  1727. 1:04:08relation that contains all the possible
  1728. 1:04:10combinations of tuples from
  1729. 1:04:13the both input relations. So,
  1730. 1:04:17sometimes it's called a Cartesian
  1731. 1:04:18product but it's the it's the product of
  1732. 1:04:21two relations. It's going to be all the
  1733. 1:04:22pairwise combinations.
  1734. 1:04:25So, essentially what you're going to get
  1735. 1:04:27from doing
  1736. 1:04:29the product of R and S is kind of all of
  1737. 1:04:31these
  1738. 1:04:33pairwise combinations of tuples from
  1739. 1:04:35from both relations.
  1740. 1:04:36This might seem kind of useless but it
  1741. 1:04:39it does show up sometimes.
  1742. 1:04:42You know, if you want to get generate
  1743. 1:04:44all the possible combinations
  1744. 1:04:46in in two tables. But more importantly,
  1745. 1:04:49what what this is going to be used for
  1746. 1:04:50is just from a conceptual or theoretical
  1747. 1:04:53perspective,
  1748. 1:04:54it's going to let us model the next
  1749. 1:04:56operator we're going to talk about which
  1750. 1:04:58is a join. So, kind of you can get all
  1751. 1:05:00these these pairwise
  1752. 1:05:03combinations.
  1753. 1:05:05This is the the syntax in SQL um
  1754. 1:05:08for how to do it.
  1755. 1:05:10You can get all of pairwise combinations
  1756. 1:05:12but now let's say that you just want the
  1757. 1:05:14pairwise combinations where your
  1758. 1:05:17primary key that we talked about in your
  1759. 1:05:19foreign key match. So, you have two keys
  1760. 1:05:21that match. So, the join operator is
  1761. 1:05:24going to generate a relation that um
  1762. 1:05:27contains all all the two poles that are
  1763. 1:05:29combination
  1764. 1:05:30of um
  1765. 1:05:32the the two inputs where there's a
  1766. 1:05:34common value for one or more attributes
  1767. 1:05:37depending on on what you specify.
  1768. 1:05:39So,
  1769. 1:05:40uh
  1770. 1:05:41what we're going to do is we're going to
  1771. 1:05:41look for um
  1772. 1:05:43matches here and again these two tables
  1773. 1:05:46have the same schema, but you could do
  1774. 1:05:47it in an arbitrary case in the
  1775. 1:05:49music store example you have
  1776. 1:05:51the artist uh relation and the the
  1777. 1:05:53albums relation and they share the um
  1778. 1:05:57uh
  1779. 1:05:58artist uh primary key that they join on.
  1780. 1:06:01So, um
  1781. 1:06:03what's happening here with the join uh
  1782. 1:06:05operator is that we're we're only
  1783. 1:06:07finding the matches like I said
  1784. 1:06:09uh that appear in both
  1785. 1:06:12uh the the R table and the S table.
  1786. 1:06:17So, like I said kind of this this
  1787. 1:06:19conceptually if you think about what
  1788. 1:06:20what the the um product operator does,
  1789. 1:06:23you could produce all of these pairwise
  1790. 1:06:25optimizations I already said so you
  1791. 1:06:27produce all these pairwise combinations
  1792. 1:06:29and then um filter it down to just uh
  1793. 1:06:33uh the the set that matches uh where the
  1794. 1:06:36keys match. But of course you never do
  1795. 1:06:38this um
  1796. 1:06:40uh
  1797. 1:06:41because you know you have to first
  1798. 1:06:43enumerate all the the different uh
  1799. 1:06:46uh combinations and then perform the
  1800. 1:06:47filter. So, there are different
  1801. 1:06:49optimizations you you might want to do
  1802. 1:06:50to short circuit this, but from a
  1803. 1:06:52theoretical perspective conceptual
  1804. 1:06:53perspective it's useful um to think
  1805. 1:06:56about
  1806. 1:06:57in this way.
  1807. 1:06:59So, uh the the SQL syntax for this and
  1808. 1:07:01again we'll go over these in in more
  1809. 1:07:04detail um next class, but the SQL syntax
  1810. 1:07:07to do this join here
  1811. 1:07:08um is the natural join operator.
  1812. 1:07:13Um so uh over time, like I said, there
  1813. 1:07:16there have been um
  1814. 1:07:18extensions to the original uh relational
  1815. 1:07:21algebra where they built in more
  1816. 1:07:22operators. Uh there's now
  1817. 1:07:25a bunch that people have added.
  1818. 1:07:27Rename, assignment, duplicate
  1819. 1:07:28elimination, aggregation. Imagine you
  1820. 1:07:31want to count how many
  1821. 1:07:32um
  1822. 1:07:33albums a particular artist has released.
  1823. 1:07:36Uh sorting, so you can actually impose
  1824. 1:07:38some kind of ordering
  1825. 1:07:40uh on the unordered set.
  1826. 1:07:41Um and and set division.
  1827. 1:07:44So, there are analogs for all of these
  1828. 1:07:46in SQL that that we'll talk about. Don't
  1829. 1:07:48don't worry too much about them. They're
  1830. 1:07:49not um going to be super important for
  1831. 1:07:52uh the course.
  1832. 1:07:55Um so, just an observation about
  1833. 1:07:57relation relational algebra. Um
  1834. 1:07:59kind of we've gone through all the
  1835. 1:08:00operators, but
  1836. 1:08:02it it's still defining more or less the
  1837. 1:08:05high-level steps that are necessary for
  1838. 1:08:08how to compute a query. So, essentially,
  1839. 1:08:12we're telling um
  1840. 1:08:15the the database management system
  1841. 1:08:16exactly how it should go about computing
  1842. 1:08:19the query. And in the example here, um
  1843. 1:08:23we have two,
  1844. 1:08:25you know, more or less equivalent
  1845. 1:08:26queries. On on uh the one side, you're
  1846. 1:08:29doing uh the join between R and S first
  1847. 1:08:33before applying the filter to only the
  1848. 1:08:36tuples that have BID 102.
  1849. 1:08:39And on the other side, uh you're
  1850. 1:08:40filtering S to only the tuples that have
  1851. 1:08:43102 uh BID equals 102 and then
  1852. 1:08:45performing the join. So, kind of these
  1853. 1:08:48these two, while they're going to
  1854. 1:08:49produce the exact same answer, one might
  1855. 1:08:52be a lot more um efficient than the
  1856. 1:08:55other. You know,
  1857. 1:08:56if you have, again, a billion tuples in
  1858. 1:08:59the relation, um you might want to do
  1859. 1:09:01the filtering first Uh, so you get that
  1860. 1:09:03as one rather than having to, you know,
  1861. 1:09:06find all the billion matches and then
  1862. 1:09:08then do the filter. So, in this way, um,
  1863. 1:09:11the the the
  1864. 1:09:13uh relational algebra is still
  1865. 1:09:15procedural and not declarative. So,
  1866. 1:09:18really what we'd like is is a
  1867. 1:09:19declarative language like SQL for
  1868. 1:09:21accessing
  1869. 1:09:23um, the database. And that's kind of
  1870. 1:09:25this idea where you want to state the
  1871. 1:09:28the high-level answer or exactly what
  1872. 1:09:31you want the database management system
  1873. 1:09:34to compute for you rather than telling
  1874. 1:09:36it how it should go about doing it. And
  1875. 1:09:39essentially, you can just leave the
  1876. 1:09:41low-level details about, you know, how
  1877. 1:09:44to actually do it to the database
  1878. 1:09:46management system. And if it's well
  1879. 1:09:48implemented, it should do it um, a lot
  1880. 1:09:50better than than um, the kind of
  1881. 1:09:53high-level procedural
  1882. 1:09:55uh query you would produce.
  1883. 1:10:02So, the relational model just as a
  1884. 1:10:03concept is independent of any kind of
  1885. 1:10:06specific um, query language
  1886. 1:10:08implementations. There were a lot that
  1887. 1:10:10got proposed over the years.
  1888. 1:10:12Um, I think there was an Alpha proposed
  1889. 1:10:14originally proposed by Cod, but no one
  1890. 1:10:16talks about that anymore. Uh, there's
  1891. 1:10:18Quel, um, which was produced by someone
  1892. 1:10:19from Berkeley. Um,
  1893. 1:10:22and
  1894. 1:10:24SQL kind of emerged as the de facto
  1895. 1:10:26standard. Some people call it SQL. Um,
  1896. 1:10:28some people call it SQL. Both are fine.
  1897. 1:10:30Uh, I'll still know what you're talking
  1898. 1:10:31about if you say either.
  1899. 1:10:33Um, so it's kind of emerged as the de
  1900. 1:10:35facto standard. Um, and there are
  1901. 1:10:37standard specifications, but uh, pretty
  1902. 1:10:40much every um,
  1903. 1:10:43uh system implements its own uh
  1904. 1:10:47variant. So,
  1905. 1:10:49uh if you write a a query for MySQL, it
  1906. 1:10:51might not exactly match something that
  1907. 1:10:53runs on Postgres or Oracle or SQLite or
  1908. 1:10:56whatever. Uh so, kind of that's the
  1909. 1:10:59tricky part. There is a standard that
  1910. 1:11:01everyone like, you know, 98% adheres to,
  1911. 1:11:04but there's this kind of wiggle room
  1912. 1:11:07where people implement their own special
  1913. 1:11:09um divergencies. So, going way back to
  1914. 1:11:13the Python example I gave earlier, this
  1915. 1:11:15was the uh code where you're going to
  1916. 1:11:17iterate over all the lines in the file
  1917. 1:11:19um to find the year that Ice Cube went
  1918. 1:11:22solo. And if we rewrite that in in uh a
  1919. 1:11:27SQL query, we get this a lot more
  1920. 1:11:28compact specification for what we want,
  1921. 1:11:32and not how we want the database
  1922. 1:11:35management system uh to to give it to
  1923. 1:11:37us. So, we say we want to select the
  1924. 1:11:39year from the artists table where the
  1925. 1:11:41name of the artist is Ice Cube. So,
  1926. 1:11:44that's a lot uh uh higher-level, and we
  1927. 1:11:46don't have to worry about kind of the
  1928. 1:11:48low-level details about reading the
  1929. 1:11:50lines, parsing the lines, all that
  1930. 1:11:52stuff. We just tell the database
  1931. 1:11:54management system, "This is what we
  1932. 1:11:55want. This is the answer that we want.
  1933. 1:11:58You figure out how to how to get it back
  1934. 1:12:00to me."
  1935. 1:12:02So,
  1936. 1:12:03that kind of wraps everything up. Um
  1937. 1:12:07the the two takeaways are that, you
  1938. 1:12:09know, databases are ubiquitous. They're
  1939. 1:12:10used in all sorts of applications all
  1940. 1:12:12over the place. There's any amount of
  1941. 1:12:14data being managed in the application
  1942. 1:12:17you're using,
  1943. 1:12:18um there is
  1944. 1:12:20almost certainly a database management
  1945. 1:12:22system behind the scenes.
  1946. 1:12:24Um relational algebra kind of defines
  1947. 1:12:26the the primitives for processing
  1948. 1:12:28queries on a relational database.
  1949. 1:12:31And uh
  1950. 1:12:32we're going to see relational algebra
  1951. 1:12:33again when we talk about um query
  1952. 1:12:35optimization and execution,
  1953. 1:12:37um but
  1954. 1:12:39for now, the next class is going to be
  1955. 1:12:41uh specifically about SQL and we're
  1956. 1:12:42going to go through some more advanced
  1957. 1:12:44uh topics with with SQL.
  1958. 1:12:45So, um that's it. And then uh I will see
  1959. 1:12:48you on Wednesday. Yeah.
  1960. 1:12:59This R C K talking about the Saint
  1961. 1:13:01Ides brew.
  1962. 1:13:03Share with my crew is magnificent.
  1963. 1:13:05Busters mellow. And for the rest of the
  1964. 1:13:07commercial, pass the mic on to my
  1965. 1:13:09fellow.
  1966. 1:13:09for a mic check, Frosty. The beat is all
  1967. 1:13:11set to grab a 40. The funky Yorkers snap
  1968. 1:13:13they necks. Saint Ides. Take a sip and
  1969. 1:13:15wipe your lips till my 40 is getting
  1970. 1:13:17warm. I'm outie, got to split. Drink a
  1971. 1:13:19drink a drink a Then I burp after I
  1972. 1:13:21slurp ice cold. I'm putting much work
  1973. 1:13:23with the B M T and the E double get us a
  1974. 1:13:26Saint Ides brew on the job.

About this transcript

This page contains the full transcript of 01 - Course Introduction & Relational Model (CMU Intro to Database Systems / Fall 2021) by CMU Database Group, generated from the public captions YouTube serves with the video. The transcript has 11,396 words across 1,974 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.