1 00:00:00,060 --> 00:00:06,810 ‫Today's topic is right, amplification, database, right, amplification, you know, guys, this is 2 00:00:06,810 --> 00:00:15,390 ‫one of the reasons that Ueber have moved from PostgreSQL to my school and we obviously talked about 3 00:00:15,630 --> 00:00:23,520 ‫that move that is not entirely approved by the community because nobody missed a lot of things in that 4 00:00:23,520 --> 00:00:27,490 ‫article, but it was a valid reason nevertheless. 5 00:00:27,840 --> 00:00:28,050 ‫So. 6 00:00:28,050 --> 00:00:28,260 ‫Right. 7 00:00:28,260 --> 00:00:36,570 ‫Amplification, if you don't know guys, it's like a phenomena where your update stadtmueller your school 8 00:00:36,570 --> 00:00:37,290 ‫or whatever. 9 00:00:37,290 --> 00:00:37,710 ‫Right. 10 00:00:37,710 --> 00:00:39,330 ‫You are performing logically. 11 00:00:39,840 --> 00:00:42,870 ‫The actual physical representation of that. 12 00:00:42,870 --> 00:00:50,640 ‫Right, is double or triple or maybe a magnitude more order of magnitude more than the actual logical. 13 00:00:50,640 --> 00:00:50,950 ‫Right. 14 00:00:51,210 --> 00:00:55,230 ‫So you would think like, hey, I just did a single field in a single role. 15 00:00:55,440 --> 00:01:03,870 ‫But you look at the disk usage at that point and you see it doing thousands and thousands and thousands 16 00:01:03,870 --> 00:01:04,920 ‫of kilobytes. 17 00:01:04,920 --> 00:01:11,820 ‫Like what what I did, I, I merely updated a 32 bit integer a what the heck happened? 18 00:01:12,090 --> 00:01:13,350 ‫The right amplification. 19 00:01:13,350 --> 00:01:15,480 ‫You can look at it from three tiers. 20 00:01:15,690 --> 00:01:19,620 ‫The first thing was I kind of I saw from building apps. 21 00:01:19,620 --> 00:01:19,940 ‫Right. 22 00:01:20,160 --> 00:01:21,720 ‫And I called it the application. 23 00:01:21,720 --> 00:01:22,050 ‫Right. 24 00:01:22,050 --> 00:01:22,950 ‫Amplification. 25 00:01:23,160 --> 00:01:25,320 ‫The second type is the data base. 26 00:01:25,320 --> 00:01:25,650 ‫Right. 27 00:01:25,650 --> 00:01:28,920 ‫Amplification and the third time is the disk right. 28 00:01:28,920 --> 00:01:30,750 ‫Amplification, which is the SSD. 29 00:01:30,750 --> 00:01:31,860 ‫Right amplification. 30 00:01:32,040 --> 00:01:34,650 ‫I'm going to talk about the three of them as this. 31 00:01:34,710 --> 00:01:37,740 ‫These are infamous for right amplification. 32 00:01:37,740 --> 00:01:39,060 ‫So I'm going to talk about that. 33 00:01:39,060 --> 00:01:43,260 ‫And then database, which is something that is hidden from you, depends really. 34 00:01:43,260 --> 00:01:48,650 ‫Database platform and then the application itself, which is kind of your fault as a backing engineer. 35 00:01:48,990 --> 00:01:50,640 ‫So let's jump onto each one of them. 36 00:01:50,830 --> 00:01:51,020 ‫All right. 37 00:01:51,300 --> 00:01:52,890 ‫So let's start with the application. 38 00:01:53,040 --> 00:01:53,520 ‫Right. 39 00:01:53,520 --> 00:02:02,640 ‫Amplification and this is maybe your end user is expecting something, but it turns out that the actual 40 00:02:02,640 --> 00:02:10,970 ‫work behind that API single call or update is magnificently larger. 41 00:02:11,400 --> 00:02:15,360 ‫For example, you're taking your to do item. 42 00:02:15,360 --> 00:02:22,530 ‫Hey, I just done this desk, but so to the to the developer, the front end developer in this case 43 00:02:22,920 --> 00:02:31,390 ‫calling that API to kind of just hey, I just deleted I just I just marked this as done right so far. 44 00:02:31,440 --> 00:02:31,890 ‫The developer. 45 00:02:31,890 --> 00:02:32,340 ‫My thing. 46 00:02:32,340 --> 00:02:33,510 ‫Oh this is just an update. 47 00:02:33,510 --> 00:02:39,900 ‫Statement maybe our own a Synagro, but a back end developer could have written this application in 48 00:02:39,900 --> 00:02:48,540 ‫a way so that, hey, it goes to the to do app mark that's to do as done and then goes to another table, 49 00:02:48,690 --> 00:02:53,430 ‫maybe inserts that raw into another archive table. 50 00:02:53,430 --> 00:02:54,870 ‫Hey there, Hosain. 51 00:02:54,870 --> 00:02:57,660 ‫Have done has washed the dishes, for example. 52 00:02:57,980 --> 00:02:58,920 ‫It goes into another. 53 00:02:58,920 --> 00:02:59,580 ‫So that's two. 54 00:02:59,580 --> 00:03:00,060 ‫Right. 55 00:03:00,270 --> 00:03:07,290 ‫And then maybe you have another table maintaining the count of the task that you have done. 56 00:03:07,290 --> 00:03:12,200 ‫So you your increment or your update, another table with the actual work. 57 00:03:12,210 --> 00:03:16,080 ‫So one single API translate to many, many rides. 58 00:03:16,080 --> 00:03:19,160 ‫And obviously there's this goes downstream and affects us. 59 00:03:19,350 --> 00:03:22,110 ‫So this is the simplest of thing you think is the single. 60 00:03:22,110 --> 00:03:29,010 ‫Right, but the actual API implementation, it does a lot of things and relational databases are designed 61 00:03:29,010 --> 00:03:34,530 ‫this way, especially if you have normalized table where you have many, many tables that you have to 62 00:03:34,860 --> 00:03:37,440 ‫kind of maintain and keep it consistent. 63 00:03:38,140 --> 00:03:38,490 ‫Right. 64 00:03:39,180 --> 00:03:42,630 ‫That doesn't mean obviously N Equal is infamous of that. 65 00:03:42,630 --> 00:03:45,270 ‫Obviously, it has its own limitation as well. 66 00:03:45,630 --> 00:03:48,480 ‫But now this is the first time the application. 67 00:03:48,780 --> 00:03:49,440 ‫Right. 68 00:03:49,440 --> 00:03:55,800 ‫Amplification your app claims to do one thing, but actually behind the scene is doing way, way, way, 69 00:03:55,800 --> 00:03:56,760 ‫way, way, way more. 70 00:03:57,190 --> 00:04:04,770 ‫Another famous thing is delete some people, implement, delete as as a as an actual update and an insert. 71 00:04:04,770 --> 00:04:08,820 ‫Some people implement delete as as a logical delete. 72 00:04:08,820 --> 00:04:09,120 ‫Right. 73 00:04:09,120 --> 00:04:11,250 ‫Where do they do more and more work at the back end. 74 00:04:11,370 --> 00:04:12,920 ‫So a really different. 75 00:04:12,940 --> 00:04:13,950 ‫So that's an application. 76 00:04:13,950 --> 00:04:14,130 ‫Right. 77 00:04:14,790 --> 00:04:19,080 ‫Let's talk about database write ID and this is whenever you hear right. 78 00:04:19,080 --> 00:04:25,350 ‫Amplification, it could be either the the database ID or the other one which is this is the ID. 79 00:04:26,100 --> 00:04:32,070 ‫So the database ID is is a property that is hidden from you as a database platform. 80 00:04:32,430 --> 00:04:38,850 ‫I'm going to give the example of positives because of the most infamous and it is the exact same thing 81 00:04:38,880 --> 00:04:41,220 ‫as my sequel. 82 00:04:41,760 --> 00:04:49,650 ‫But with that, my isaam storage engine, they both work almost identically in this case. 83 00:04:49,650 --> 00:04:50,850 ‫Oh, not not quite. 84 00:04:50,850 --> 00:04:55,980 ‫So let's say you have a table with six columns, write five columns, have an index indexes, each has 85 00:04:55,980 --> 00:04:56,700 ‫an index on them. 86 00:04:56,970 --> 00:04:59,940 ‫And the last one, which is the sixth column, doesn't happen in. 87 00:05:00,380 --> 00:05:09,380 ‫So if you execute an updated statement, you pulled a singer on the stable and then you updated one 88 00:05:09,380 --> 00:05:13,890 ‫of the columns, I say column one, which happened to have an index on them in PostgreSQL. 89 00:05:14,240 --> 00:05:15,230 ‫This is what will happen. 90 00:05:15,710 --> 00:05:18,600 ‫Postgres will create a brand new row. 91 00:05:18,620 --> 00:05:19,490 ‫That's how it works. 92 00:05:19,490 --> 00:05:25,390 ‫Always any update, any modification on the Tupelo's create a new Topal idea. 93 00:05:25,400 --> 00:05:28,690 ‫That is a terrible idea that uniquely identifies the road. 94 00:05:29,090 --> 00:05:32,890 ‫Yeah, it will create a new one with the new values that you have. 95 00:05:33,620 --> 00:05:34,780 ‫Copy, exact copy. 96 00:05:35,030 --> 00:05:38,520 ‫We have to update the column responding index because we choose the value. 97 00:05:38,540 --> 00:05:40,540 ‫So now we update the index. 98 00:05:40,940 --> 00:05:43,250 ‫That's something we have to do anyway. 99 00:05:43,490 --> 00:05:44,470 ‫So that's another. 100 00:05:44,470 --> 00:05:44,670 ‫Right. 101 00:05:44,670 --> 00:05:52,700 ‫So we inserted a new role and now we want to go to the index and change that tuple idea from pointing 102 00:05:52,700 --> 00:05:55,250 ‫to the older or it points to the new role. 103 00:05:55,250 --> 00:05:57,110 ‫And we also change the value. 104 00:05:57,110 --> 00:06:01,840 ‫We introduce the new value that you inserted and that tuple in that right. 105 00:06:01,880 --> 00:06:04,780 ‫So now it's almost two changes. 106 00:06:04,850 --> 00:06:07,340 ‫And you might say, what about the rest of the index? 107 00:06:07,460 --> 00:06:09,510 ‫These five indexes still point to the old row. 108 00:06:10,220 --> 00:06:15,530 ‫Polska is used to update those indexes, to point to the new tuple. 109 00:06:16,280 --> 00:06:19,430 ‫And that's what you didn't like back in, what, 91 or 92? 110 00:06:19,430 --> 00:06:20,110 ‫I don't remember. 111 00:06:20,690 --> 00:06:28,940 ‫And so so the right volume volume that is happening as a result was enormous, especially when you start 112 00:06:29,240 --> 00:06:30,940 ‫you did a single update. 113 00:06:30,960 --> 00:06:33,830 ‫Now you're touching all these index and you have a lot of indexes. 114 00:06:33,830 --> 00:06:38,570 ‫All of sudden these indexes have to be touch despite them not being changed. 115 00:06:38,570 --> 00:06:40,550 ‫If you think about it, they will not change. 116 00:06:40,850 --> 00:06:43,730 ‫But Postgres actually solved this problem. 117 00:06:43,740 --> 00:06:48,680 ‫I don't remember when maybe it was nine four or nine three doing something called the heap only to build 118 00:06:48,680 --> 00:06:49,790 ‫a hot Topal. 119 00:06:50,900 --> 00:06:58,730 ‫That essentially it's a trick, so, OK, it says we didn't really change the value if we didn't really 120 00:06:58,730 --> 00:07:04,400 ‫change a value, we don't really go to the index to update it because that's that's just wasteful. 121 00:07:05,240 --> 00:07:07,460 ‫So they they definitely fixed that. 122 00:07:07,490 --> 00:07:15,500 ‫The only Topal will create the road, the new road to topple it and then points to the old road to the 123 00:07:15,500 --> 00:07:21,860 ‫new one is that, hey, by the way, if anyone happened to land on the old road, tell them that there 124 00:07:21,860 --> 00:07:23,210 ‫is a new version of this. 125 00:07:23,210 --> 00:07:28,970 ‫There is a new heap, only Topal that points the only limitation here. 126 00:07:28,980 --> 00:07:30,830 ‫It has to be in the same page. 127 00:07:30,830 --> 00:07:31,100 ‫Right. 128 00:07:31,220 --> 00:07:34,760 ‫If the page is full, then you cannot really do that. 129 00:07:34,760 --> 00:07:35,000 ‫Right. 130 00:07:35,010 --> 00:07:36,760 ‫That's that's why it's called hipbone and that's why. 131 00:07:36,780 --> 00:07:38,420 ‫Well, full factor come in. 132 00:07:38,570 --> 00:07:40,530 ‫You have to choose the correct fill of factors. 133 00:07:40,550 --> 00:07:42,500 ‫It's a really complex things to understand. 134 00:07:42,510 --> 00:07:46,570 ‫You have to be really careful when you're building this stuff anyway. 135 00:07:46,790 --> 00:07:49,700 ‫So it used to do that, but no, not anymore. 136 00:07:49,760 --> 00:07:51,530 ‫But I wanted to give this example to right. 137 00:07:51,530 --> 00:07:57,940 ‫Amplification is a faint, especially with Postgres, but it could be with any really any other database. 138 00:07:58,100 --> 00:08:00,680 ‫Let's say you did another one single update. 139 00:08:01,220 --> 00:08:03,140 ‫You updated one roll with many values. 140 00:08:03,140 --> 00:08:05,000 ‫You changed almost all columns. 141 00:08:05,120 --> 00:08:05,450 ‫Right. 142 00:08:06,080 --> 00:08:12,560 ‫There is no way in my school, on Postgres, on Oracle, we have to do we wrote one single value, one 143 00:08:12,560 --> 00:08:16,210 ‫single rule, but as a result, we have to touch all the indexes. 144 00:08:16,400 --> 00:08:17,100 ‫That's another. 145 00:08:17,100 --> 00:08:17,410 ‫Right. 146 00:08:17,420 --> 00:08:24,530 ‫Amplification, OK, because if you look at the update segment, it's logically, it looks to me like 147 00:08:24,530 --> 00:08:25,730 ‫updated a single row. 148 00:08:26,090 --> 00:08:29,990 ‫But to the database, you actually did more and more work. 149 00:08:29,990 --> 00:08:33,620 ‫You did a lot a lot of physical work. 150 00:08:34,160 --> 00:08:37,280 ‫And when I say physical here, I mean database physical. 151 00:08:37,280 --> 00:08:37,580 ‫Right. 152 00:08:37,580 --> 00:08:43,340 ‫Because it gets really confusing when I say logical and physical, where ordinarily when I say logical 153 00:08:43,340 --> 00:08:44,120 ‫database. 154 00:08:44,630 --> 00:08:45,290 ‫Right. 155 00:08:45,290 --> 00:08:51,620 ‫Is the school and physical database right on essentially the wall changes the right ahead log. 156 00:08:51,660 --> 00:08:51,920 ‫Right. 157 00:08:52,070 --> 00:08:54,690 ‫All these actual changes that you have the pages. 158 00:08:54,710 --> 00:08:54,970 ‫Right. 159 00:08:55,580 --> 00:09:01,880 ‫But when it comes to this, this D, which is the next topic, that's a different beast, physical and 160 00:09:01,880 --> 00:09:04,550 ‫logical becomes different things right now. 161 00:09:04,790 --> 00:09:07,430 ‫This is the database ID, very powerful. 162 00:09:07,430 --> 00:09:08,660 ‫You have to really understand it. 163 00:09:08,660 --> 00:09:08,880 ‫Right. 164 00:09:09,080 --> 00:09:14,540 ‫So that's the second type of medication that goes to the final one, which is a very infamous one without 165 00:09:14,540 --> 00:09:15,200 ‫ID. 166 00:09:15,410 --> 00:09:19,190 ‫Even if you go to the wiki page, when you write random application, that's the only one that shows 167 00:09:19,190 --> 00:09:22,160 ‫up anyway, which is the zero ID. 168 00:09:23,180 --> 00:09:30,290 ‫So to talk about that, we really need to understand how is this really works. 169 00:09:30,590 --> 00:09:38,180 ‫So this is the guys have this idea of someone invented something called the charge strap is a technique 170 00:09:38,180 --> 00:09:41,630 ‫where you can store multiple level of electrons. 171 00:09:42,020 --> 00:09:50,690 ‫You can from zero electrons up to certain levels and the quantity of the electrons determines certain 172 00:09:50,690 --> 00:09:51,110 ‫values. 173 00:09:51,110 --> 00:09:54,260 ‫And this is the trick we used to correspond to this. 174 00:09:54,410 --> 00:10:00,770 ‫And these trap are put into cells like so Acel can have a lot of charge traps. 175 00:10:01,130 --> 00:10:09,980 ‫And as a result, one single cell can have up to the recent newer stuff up to 16 different charge levels. 176 00:10:10,370 --> 00:10:14,720 ‫So if you do the math right with the computer science, 16 is how many bits? 177 00:10:14,720 --> 00:10:15,410 ‫It's four bits. 178 00:10:15,410 --> 00:10:15,710 ‫Right. 179 00:10:16,310 --> 00:10:21,530 ‫So that means each cell can store four bits and once you charge them, you store them. 180 00:10:22,280 --> 00:10:25,160 ‫You can turn off electricity works. 181 00:10:25,160 --> 00:10:26,150 ‫It's persisted. 182 00:10:26,150 --> 00:10:27,800 ‫It stays for ages. 183 00:10:27,950 --> 00:10:31,510 ‫It does not go it does not get released. 184 00:10:31,520 --> 00:10:31,850 ‫Right. 185 00:10:32,270 --> 00:10:34,880 ‫And you can essentially read those values back. 186 00:10:35,060 --> 00:10:39,170 ‫And then based on the quantity of number of electrons, they'll get this. 187 00:10:39,170 --> 00:10:40,580 ‫Oh, this is zero zero zero zero. 188 00:10:40,700 --> 00:10:42,140 ‫Oh, this is zero zero zero one. 189 00:10:42,140 --> 00:10:43,580 ‫Oh, this is zero zero one zero. 190 00:10:43,580 --> 00:10:44,100 ‫This is oh. 191 00:10:44,100 --> 00:10:48,700 ‫Is this the one one one one based on this trick, they build the entire SSD. 192 00:10:48,800 --> 00:10:53,840 ‫So now they took one cell, they organized into a row and then the rose becomes the, the, the, the 193 00:10:53,960 --> 00:10:54,590 ‫pages. 194 00:10:54,590 --> 00:10:54,770 ‫Right. 195 00:10:54,770 --> 00:10:57,380 ‫So there is a page has many cells and many rows. 196 00:10:57,650 --> 00:11:06,080 ‫I so think of a page now this have a lot of these charge drives so a page can have a lot of bits stored 197 00:11:06,080 --> 00:11:07,310 ‫in it and you can do that. 198 00:11:07,490 --> 00:11:10,010 ‫And then pages are organized into blocks. 199 00:11:10,010 --> 00:11:10,280 ‫Right. 200 00:11:10,430 --> 00:11:11,390 ‫And here's the trick here. 201 00:11:11,810 --> 00:11:12,130 ‫Right. 202 00:11:12,170 --> 00:11:16,130 ‫So now you have you have control of a block that has many pages. 203 00:11:16,130 --> 00:11:18,500 ‫And this is what we're interested in here at this level. 204 00:11:18,500 --> 00:11:18,770 ‫Right. 205 00:11:19,040 --> 00:11:23,750 ‫And if you love to read more about it, I'm going to reference a video that absolutely offers a very 206 00:11:23,750 --> 00:11:25,790 ‫technical, low level thing. 207 00:11:25,850 --> 00:11:27,200 ‫If you're going to learn more about it. 208 00:11:27,200 --> 00:11:27,700 ‫This is deep. 209 00:11:28,250 --> 00:11:29,750 ‫It's a very good animations. 210 00:11:29,750 --> 00:11:30,530 ‫So I loved it. 211 00:11:31,460 --> 00:11:34,430 ‫So so now this is what we need to understand. 212 00:11:34,430 --> 00:11:36,290 ‫Block and pages. 213 00:11:36,800 --> 00:11:38,420 ‫However, nothing is free. 214 00:11:38,420 --> 00:11:40,370 ‫Obviously, here is the condition. 215 00:11:40,720 --> 00:11:41,420 ‫Is this D? 216 00:11:41,630 --> 00:11:42,050 ‫Yeah. 217 00:11:42,470 --> 00:11:46,190 ‫You can write stuff for us, you can write in pages. 218 00:11:47,060 --> 00:11:47,360 ‫Right. 219 00:11:47,360 --> 00:11:49,730 ‫As long as the page is. 220 00:11:50,800 --> 00:11:58,150 ‫It doesn't have anything right, does it have any levels kept as one of the pages you can write anything 221 00:11:58,150 --> 00:11:59,240 ‫you want on it, right? 222 00:11:59,320 --> 00:12:00,940 ‫And when you write it, we're going to store it. 223 00:12:01,360 --> 00:12:08,800 ‫But if there is a page that is already has some content in it and you want to update that content to 224 00:12:08,800 --> 00:12:12,160 ‫something else, let's say you have a bunch of rows and have values. 225 00:12:12,250 --> 00:12:17,160 ‫You want to update something, you have to erase this page and write it back. 226 00:12:17,350 --> 00:12:19,470 ‫You cannot just overwrite it, right. 227 00:12:20,260 --> 00:12:21,130 ‫That's impossible. 228 00:12:21,250 --> 00:12:23,470 ‫So what this is does when you want to update. 229 00:12:23,470 --> 00:12:32,080 ‫So what what it does is says, OK, let's just write the new value into a brand new page and then leave 230 00:12:32,080 --> 00:12:40,360 ‫the old page as a stale market, as stale so future people can clean it up if they want to use a future 231 00:12:40,360 --> 00:12:40,960 ‫requests. 232 00:12:41,530 --> 00:12:42,890 ‫And here's another limitation. 233 00:12:42,890 --> 00:12:46,350 ‫And this is the you cannot clean up one page at a time. 234 00:12:46,660 --> 00:12:48,640 ‫You have to clean a whole block. 235 00:12:48,760 --> 00:12:50,290 ‫And you can see some pictures here. 236 00:12:50,290 --> 00:12:52,150 ‫A block, a block has many pages. 237 00:12:52,880 --> 00:12:55,180 ‫And I think it's eight or something like that. 238 00:12:55,190 --> 00:12:58,700 ‫If I come with with a payload, I want to update a page. 239 00:12:59,770 --> 00:13:02,560 ‫I have a block or the three pages. 240 00:13:02,830 --> 00:13:04,000 ‫I have four pages. 241 00:13:04,000 --> 00:13:05,650 ‫Let's write them abcde. 242 00:13:05,740 --> 00:13:07,510 ‫We just write them back right there. 243 00:13:07,690 --> 00:13:09,220 ‫OK, and then let's follow that. 244 00:13:09,220 --> 00:13:10,120 ‫And you can see the second page. 245 00:13:10,120 --> 00:13:17,500 ‫I took this from Wikipedia resources right now and then let's follow it up with writing e f g h. 246 00:13:17,500 --> 00:13:17,950 ‫Right. 247 00:13:18,100 --> 00:13:19,540 ‫And then so that's four pages. 248 00:13:19,540 --> 00:13:27,430 ‫But I also want to update pages A, B, C, D, so an update what it is to do. 249 00:13:27,580 --> 00:13:34,630 ‫It marks those old ABCDE pages as stale and then write new four pages in the same block. 250 00:13:34,810 --> 00:13:36,220 ‫So now this blog is filled. 251 00:13:37,750 --> 00:13:43,840 ‫If you have a new rights that you want to come in and you want to use this block, you cannot use it 252 00:13:44,290 --> 00:13:46,630 ‫to the ISS, the drivers. 253 00:13:47,320 --> 00:13:50,260 ‫This is filled, this block is filled. 254 00:13:50,260 --> 00:13:51,550 ‫You cannot use it at all. 255 00:13:52,270 --> 00:13:52,620 ‫Right. 256 00:13:52,870 --> 00:13:54,730 ‫And as a result is just filled. 257 00:13:54,760 --> 00:13:57,240 ‫You cannot use that block. 258 00:13:57,580 --> 00:14:03,460 ‫So there is this process that's called garbage collection and it runs asynchronously. 259 00:14:03,790 --> 00:14:05,890 ‫It cleans up this kind of thing. 260 00:14:05,890 --> 00:14:09,360 ‫So so this block has four pages that is in use then. 261 00:14:09,360 --> 00:14:13,810 ‫And it's costing us a lot of precious page memory space. 262 00:14:13,810 --> 00:14:14,110 ‫Right. 263 00:14:14,500 --> 00:14:20,860 ‫So what we do is, hey, garbage collection, move all the active pages from this block into a brand 264 00:14:20,860 --> 00:14:28,540 ‫new block and then just slam that block a block shot clean, flush the whole thing, clean it up so 265 00:14:28,540 --> 00:14:29,410 ‫I can use it. 266 00:14:29,410 --> 00:14:31,680 ‫I can start using all the free spaces. 267 00:14:31,960 --> 00:14:38,740 ‫So now my pages have moved to the block, the second block, and they have now for around four spaces 268 00:14:38,740 --> 00:14:40,570 ‫that I can use to write the stuff. 269 00:14:40,870 --> 00:14:44,980 ‫That is why is is these do not like updates because of this thing. 270 00:14:44,980 --> 00:14:45,190 ‫Right. 271 00:14:45,200 --> 00:14:52,750 ‫You you're marking this pressure old pages as stale and then writing in the new locations every time, 272 00:14:53,170 --> 00:14:58,570 ‫as opposed of new, fresh, nice sequential rights. 273 00:14:58,870 --> 00:14:59,320 ‫Right. 274 00:14:59,560 --> 00:15:03,760 ‫Every time you just using new pages, you never touching the old pages. 275 00:15:03,890 --> 00:15:09,250 ‫So if you don't touch old pages, if you don't see old data, you're never going to mark these pages 276 00:15:09,250 --> 00:15:16,030 ‫as stale and you're never going to have blocks with stale pages, which is the worst thing you can do 277 00:15:16,390 --> 00:15:21,400 ‫if you have blocks with stale pages that have been updated, the garbage collection is going to kick 278 00:15:21,400 --> 00:15:27,130 ‫in and the water level is another thing that's going to kick in, which is it's going to start flushing 279 00:15:27,130 --> 00:15:32,650 ‫and moving in new pages to talk to a new blog and then flushing blocks. 280 00:15:32,950 --> 00:15:38,730 ‫All this work, all this is this is going to do as a side effect of your original, right. 281 00:15:39,130 --> 00:15:47,110 ‫So updates are the worst thing you can do is the SSD like SSD like is it is always like beautiful, 282 00:15:47,320 --> 00:15:48,040 ‫just single. 283 00:15:48,040 --> 00:15:48,370 ‫Right. 284 00:15:48,370 --> 00:15:52,160 ‫So that's why Beta is right. 285 00:15:52,270 --> 00:16:02,200 ‫You if you go to the databases, beta causes this kind of behavior over time on SSD, because even if 286 00:16:02,200 --> 00:16:07,360 ‫you're doing only inserts, Beta is still need to get updated gear. 287 00:16:07,360 --> 00:16:15,190 ‫Updating in place a big three pointer you're updating in place. 288 00:16:15,190 --> 00:16:16,570 ‫Beta is locations. 289 00:16:16,780 --> 00:16:18,670 ‫You're rebalancing the trees. 290 00:16:19,330 --> 00:16:24,370 ‫And when you do that, B or B, B plus three, when you do an update, what do you do with this is do 291 00:16:24,370 --> 00:16:25,390 ‫you go to that page? 292 00:16:25,390 --> 00:16:26,020 ‫What exists? 293 00:16:26,170 --> 00:16:32,390 ‫Slavitt as stale and then take that value, take the new value and write it to a new blog. 294 00:16:32,710 --> 00:16:37,390 ‫So now the more you do this, the more you're going to have blocks with stale data. 295 00:16:37,390 --> 00:16:41,640 ‫And when you have blocks with stale data garbage collection, you'll get a kick in this sky. 296 00:16:41,650 --> 00:16:45,850 ‫Start moving your Prussia's block to some one place, which is an expensive process. 297 00:16:46,090 --> 00:16:48,040 ‫It's going to happen again and again and again. 298 00:16:48,610 --> 00:16:50,050 ‫Eventually you will get. 299 00:16:50,080 --> 00:16:59,250 ‫They down very, very quickly because it's going to you're going to start using all your pages in unnecessarily, 300 00:16:59,280 --> 00:17:00,930 ‫let's put it this way. 301 00:17:01,850 --> 00:17:06,770 ‫And when you start using all the pages and as deep as this, these have this are going on with where 302 00:17:06,770 --> 00:17:13,310 ‫leveling where they essentially says, OK, I have this page sitting for years, nobody touch this, 303 00:17:13,490 --> 00:17:16,340 ‫and nobody written in that page. 304 00:17:16,340 --> 00:17:18,500 ‫And maybe I forgot to mention that. 305 00:17:18,500 --> 00:17:24,260 ‫But that page has only limited no amount of time to write, after which it just dies. 306 00:17:24,410 --> 00:17:26,150 ‫That page location just dies. 307 00:17:26,180 --> 00:17:30,520 ‫You cannot write to it maybe 2500 times or whatever. 308 00:17:30,530 --> 00:17:32,600 ‫There is always this is this has a lifetime. 309 00:17:33,200 --> 00:17:33,550 ‫All right. 310 00:17:33,800 --> 00:17:41,120 ‫So there will be if you without leveling, there will be pages that is very busy where you are writing 311 00:17:41,120 --> 00:17:43,130 ‫to it a lot, this physical location. 312 00:17:43,850 --> 00:17:47,380 ‫And there will be pages that are never touched. 313 00:17:47,540 --> 00:17:48,890 ‫So there will be unbalanced. 314 00:17:48,910 --> 00:17:54,110 ‫So we're levelling as this is the concept where it just really bana's this thing says, OK, hey, this 315 00:17:54,110 --> 00:17:56,900 ‫is a cold page from 1998. 316 00:17:56,900 --> 00:17:57,650 ‫Nobody touched it. 317 00:17:57,840 --> 00:18:04,550 ‫Let me move it to a new location and let me use that precious location to write new pages because you're 318 00:18:04,550 --> 00:18:06,610 ‫doing all these updates eventually. 319 00:18:07,510 --> 00:18:07,900 ‫All right. 320 00:18:08,180 --> 00:18:15,410 ‫So as the the more you're doing that, the more we're going to kick in and to start using all this pages, 321 00:18:15,410 --> 00:18:20,500 ‫all uses these in a balanced manner to update's always kills Orissa's. 322 00:18:20,510 --> 00:18:21,600 ‫The fast, doesn't I? 323 00:18:21,620 --> 00:18:25,700 ‫When I say that I'm talking years and years, obviously I'm not talking about bouncier. 324 00:18:25,700 --> 00:18:25,950 ‫Right. 325 00:18:27,170 --> 00:18:28,100 ‫So, yeah, that's why. 326 00:18:29,710 --> 00:18:37,210 ‫People came in with a log structure ministry as an append only, so that we are having nice inserts 327 00:18:37,780 --> 00:18:45,970 ‫tucked in together so my blocks don't have these stale pages and always have a six consecutive pages 328 00:18:45,970 --> 00:18:47,290 ‫that are never updated. 329 00:18:47,410 --> 00:18:52,350 ‫And as a result, SSD, these love this stuff is going only have pages that are never updated. 330 00:18:52,360 --> 00:18:54,130 ‫As a result, there are clean. 331 00:18:54,840 --> 00:19:00,310 ‫If you go back to old pages and start updating them as they have to move them to a new location, they 332 00:19:00,310 --> 00:19:05,890 ‫have this block now all of a sudden have a stale page and all of the other pages are reused. 333 00:19:06,100 --> 00:19:10,900 ‫So it has to move those pages to somewhere else and flush it or use it. 334 00:19:10,900 --> 00:19:13,200 ‫And that's a lot of work for this August. 335 00:19:13,340 --> 00:19:18,390 ‫So that was the right amplification from the application point of view, from the database point to 336 00:19:18,400 --> 00:19:26,890 ‫and from this is the so you're single to do marketing the to do app as done if you're doing that single 337 00:19:26,890 --> 00:19:31,810 ‫update that the front end developer, things that you're doing a single day, but you're actually touching 338 00:19:31,810 --> 00:19:35,350 ‫all these tables and those tables kick in the database. 339 00:19:35,350 --> 00:19:35,680 ‫Right. 340 00:19:35,680 --> 00:19:40,120 ‫Amplification, which is table has like an all seven index and in this day will have three indexes and 341 00:19:40,120 --> 00:19:42,220 ‫this day will have, I don't know, four, four indexes. 342 00:19:42,670 --> 00:19:48,640 ‫Those if you're touching those obviously values with indexes, then those corresponding indexes have 343 00:19:48,640 --> 00:19:49,240 ‫to be touch. 344 00:19:49,610 --> 00:19:53,860 ‫And here's another one right in Postgres. 345 00:19:53,860 --> 00:20:00,280 ‫There is this concept of toast tables where a string, if there is a long string, it never stored in 346 00:20:00,280 --> 00:20:00,820 ‫line. 347 00:20:00,820 --> 00:20:01,090 ‫Right. 348 00:20:01,090 --> 00:20:02,470 ‫Is not another table. 349 00:20:02,470 --> 00:20:03,430 ‫That's a toast table. 350 00:20:03,670 --> 00:20:05,080 ‫So that table need to be updated. 351 00:20:05,080 --> 00:20:08,440 ‫So the right amplification just triples. 352 00:20:08,440 --> 00:20:12,340 ‫If it is just like order of magnitude, there's a lot of work. 353 00:20:12,670 --> 00:20:16,900 ‫And then now all these rights, which some of them are updated, some of them are insert. 354 00:20:17,910 --> 00:20:24,000 ‫It translates to SSD, right, amplification, ad, the physical disc level. 355 00:20:24,570 --> 00:20:32,430 ‫So all these pages that you have to update and then move the new page, mark the old pages still move 356 00:20:32,450 --> 00:20:41,970 ‫the create a new page and then have this is the point, the logical page pointer to the new page physical 357 00:20:41,970 --> 00:20:46,830 ‫page, because that doesn't have the physical and the logical as it is as the concept. 358 00:20:47,110 --> 00:20:53,340 ‫I know guys, it's a very complex topic, but I just wanted to make a video roar like that. 359 00:20:53,800 --> 00:20:56,670 ‫It's a very, very important topic to understand. 360 00:20:56,670 --> 00:21:02,490 ‫And then we're going to have to make a new and more more videos about this and maybe I'll go make a 361 00:21:02,490 --> 00:21:05,190 ‫practical video discussing this in details. 362 00:21:05,790 --> 00:21:08,580 ‫This was a right amplification. 363 00:21:09,300 --> 00:21:10,820 ‫Just keep an eye on it. 364 00:21:11,340 --> 00:21:12,450 ‫It's really critical. 365 00:21:14,350 --> 00:21:14,530 ‫By.