温馨提示:文本由机器自动转译,部分词句存在误差,以视频为准
00:01
前面我们提到了单表数据量过大,可能有两种情况,这节课呢,我们来讲第一种情况,第一种情况呢,就是数据记录太多,但是呢,它的磁盘空间的占用比较大,这是什么原因呢?这有可能呢是单条记录的数据内容比较多,有可能呢是表中的列很多,更有可能呢,是表中有个别的字段存储了特别多的内容,比如说。我们来看这张表,这张表当中呢,有ID name ageckname和这样的几个字段,那么假设呢,这是一个婚恋网站哈,婚恋网站当中呢,用户信息有用户ID,用户名,用户年龄,用户的性别以及用户的昵称和用户的个人介绍。那么我们在婚恋网站当中在筛选其他用户的时候呢,其实你更多的情况呢,是根据用户的年龄和性别来进行数据的查询,昵称和用户详情描述这两个字段呢,其实主要是用于展示的,也就是说我们根据年龄和性别把用户查询出来之后呢,那有可能只给我们先展示一个用户名,用户年龄和用户性别就可以了,有可能有的时候也要展示用户头像什么的哈,那在这个表当中,我们就把其余的字段就省略掉了啊好,那么如果你想进一步的根据展示出来的这个用户信息来再查看用户详情的话。
01:41
我们呢,在系统当中的操作呢,就是点击这个用户查看用户详情,那这个就是另外一个查询,所以说呢,针对于额外的这样的一些数据呢,我们是可以把它拆分到另外一个表当中的,比如我们这个里面呢,是拆分了,以及因为ckme和第一一般会在业务查询中用到第二这个字段呢,本身又比较长。
02:11
所以我们可以把这两个字段呢,独立到另外一表当中,这样在查询和的时候呢,就能带来一定的性能的提升,那么垂直分表引入的复杂性主要体现在哪个方面呢?主要就是操作表的数量增加了,因为原来你要操作一张表,而现在呢,你要操作的是两张表,原来呢,我们要查询完整的用户记录呢,只要进行一次查询就好了,那现在呢,我们要进行第二次查询,也就是再要根据ID呢,查询这个那个name和description,我们这个拆分的过程大家要注意哈,我们第一张表呢,它是有ID的,第二张表也有ID啊,就是两张表的ID呢,是要保持一致的,所以这个呢,我们管它叫主建一对一的一个关联关系啊,这张表。
03:05
和这张表是一对一对应的,而且这两张表的ID呢是一致的啊,那如果第一张表它是有ID的自己的主见策略的话,那么第二张表它的主见策略呢,就是要和第一张表的ID呢是一致的。所以这个呢,就是在垂直分表的过程当中引入的一个业务的复杂性。刚才呢,我们讲的是单表数据量过大的第一种情况就是数据记录不太多,但是呢,表占用的磁盘空间很大,我们用到的是垂直拆分,那么如果单表的数据记录比较大啊,也就是说表的行数特别大,那么这个时候呢,就比较适合于水平拆分了,也就是我们接下来要介绍的水平分片。
我来说两句