1 00:00:00,270 --> 00:00:02,980 ‫So now here's what we're going to do. 2 00:00:03,540 --> 00:00:11,100 ‫I am going to insert into grade parts, select star from. 3 00:00:13,730 --> 00:00:15,190 ‫Grades Orch. 4 00:00:15,590 --> 00:00:16,580 ‫So what will this do? 5 00:00:16,640 --> 00:00:21,600 ‫It will essentially copy the entire table into this table, right? 6 00:00:21,800 --> 00:00:23,120 ‫But it will insert one row by. 7 00:00:23,570 --> 00:00:25,970 ‫And here's the beautiful part, guys. 8 00:00:26,330 --> 00:00:34,700 ‫The beautiful part on this is every time you insert around this table, the database will decide which 9 00:00:34,700 --> 00:00:43,340 ‫partition that row goes to based on the value of G, f, G is twenty or twenty is between zero and thirty 10 00:00:43,340 --> 00:00:43,530 ‫five. 11 00:00:43,550 --> 00:00:46,840 ‫So it goes to zero zero, thirty five and so on. 12 00:00:46,850 --> 00:00:51,840 ‫So it's going to distribute our beautiful table just like that. 13 00:00:52,130 --> 00:00:54,080 ‫So let's see what all what did I do or that's wrong. 14 00:00:54,830 --> 00:00:56,150 ‫Just a different syntax. 15 00:00:56,150 --> 00:00:56,840 ‫So let's do it again. 16 00:00:57,360 --> 00:01:00,470 ‫Boompa I kept doing this clear. 17 00:01:00,750 --> 00:01:01,570 ‫That's just where. 18 00:01:01,580 --> 00:01:01,820 ‫All right. 19 00:01:01,820 --> 00:01:04,980 ‫So let's hit it and let's just wait for it. 20 00:01:05,000 --> 00:01:08,830 ‫So it's going to answer 10 million rolls into this great stable nice done. 21 00:01:09,140 --> 00:01:10,320 ‫That's pretty fast, right. 22 00:01:10,790 --> 00:01:18,380 ‫So now, guys, if I do select count start from grades bahts. 23 00:01:20,500 --> 00:01:31,690 ‫That's the same number, 10 million and one, that's an extra one, but if I do select Max, I'd not 24 00:01:32,080 --> 00:01:35,180 ‫get the grade from grades. 25 00:01:35,200 --> 00:01:37,300 ‫Parts obviously is going to be whatever. 26 00:01:37,300 --> 00:01:38,230 ‫Ninety nine is the max. 27 00:01:38,530 --> 00:01:44,050 ‫However, if I looked at the tables now themselves, they are populated. 28 00:01:45,070 --> 00:01:46,030 ‫But look at this. 29 00:01:46,300 --> 00:01:49,300 ‫The maximum value is zero zero thirty five is actually thirty four. 30 00:01:49,450 --> 00:01:49,750 ‫Right. 31 00:01:50,050 --> 00:01:51,340 ‫So that's just select count. 32 00:01:51,610 --> 00:01:56,570 ‫So you can see Canstar from G zero zero thirty five. 33 00:01:57,640 --> 00:02:00,100 ‫This is my first partition there. 34 00:02:00,110 --> 00:02:02,320 ‫Only this much rows around. 35 00:02:02,530 --> 00:02:02,740 ‫What. 36 00:02:02,760 --> 00:02:03,640 ‫Oh how much is this. 37 00:02:04,750 --> 00:02:07,890 ‫Three million is that's three million, three million rose, right? 38 00:02:08,380 --> 00:02:16,000 ‫And if I go to thirty five sixty, we have around two million and so on is just a random distribution. 39 00:02:16,330 --> 00:02:23,590 ‫So if I do select Max G from G thirty five sixty, what do you think the number will be about fifty 40 00:02:23,590 --> 00:02:23,810 ‫nine. 41 00:02:24,340 --> 00:02:24,880 ‫Exactly. 42 00:02:25,270 --> 00:02:29,350 ‫Because that's the largest grade we can get in the stable and so on. 43 00:02:29,350 --> 00:02:30,320 ‫They are just distributed. 44 00:02:31,060 --> 00:02:35,170 ‫So now guys, it's still my tables don't have an index. 45 00:02:35,590 --> 00:02:35,910 ‫Right. 46 00:02:35,960 --> 00:02:37,240 ‫And always my purpose. 47 00:02:37,390 --> 00:02:43,330 ‫So let's go ahead and create an index and should I create an index on all of the partitions. 48 00:02:44,140 --> 00:02:51,400 ‫Well prior to post because I believe 11 you that that was the only way to do it in Port Postgres 12, 49 00:02:51,400 --> 00:02:58,930 ‫I believe they added the ability or eleven on and you only have to create it on the on the partition 50 00:02:58,930 --> 00:02:59,320 ‫table. 51 00:02:59,440 --> 00:03:02,050 ‫Great parts index. 52 00:03:02,500 --> 00:03:06,940 ‫Let's call it grade parts index. 53 00:03:07,270 --> 00:03:07,720 ‫Right. 54 00:03:08,410 --> 00:03:12,340 ‫Index on grades parts. 55 00:03:14,000 --> 00:03:22,580 ‫On the act of creating it on the master or the on the leader partition and tabled, it will create the 56 00:03:22,580 --> 00:03:26,280 ‫same index on all the partitions, which is very, very powerful. 57 00:03:26,310 --> 00:03:27,280 ‫Let's let's check this out. 58 00:03:28,870 --> 00:03:33,340 ‫So it's going to create that obviously there is no index on the Masters because it's empty, there's 59 00:03:33,340 --> 00:03:33,610 ‫nothing. 60 00:03:33,610 --> 00:03:35,380 ‫It's just a virtual table almost. 61 00:03:35,380 --> 00:03:35,620 ‫Right. 62 00:03:35,890 --> 00:03:37,960 ‫So if I do great sports. 63 00:03:39,420 --> 00:03:46,980 ‫There is an index, they say this is your index, but if I go to G zero zero thirty five, hey, where 64 00:03:46,980 --> 00:03:48,550 ‫does this index come from? 65 00:03:48,570 --> 00:03:49,470 ‫I didn't create that. 66 00:03:49,770 --> 00:03:52,290 ‫The database did for me, which is beautiful. 67 00:03:52,710 --> 00:03:58,410 ‫If I go to thirty five, thirty five sixty, we have indexes on all of them. 68 00:03:58,770 --> 00:03:59,340 ‫Beautiful.