简体   繁体   English

是否可以使用辅助分片密钥对 Visess 进行分片

[英]is it possible to shard Vistess with the secondary sharding Key

We are using Vitess database to scale and achieve Horizontal Sharding in mysql.我们正在使用 Vitess 数据库在 mysql 中扩展和实现水平分片。 is it possible to do the secondary shard in Vitess.是否可以在 Vitess 中做二级分片。

For eg: Table 1 - Agency ( AgencyID INT, CreatedOn DATETIME )例如: Table 1 - Agency ( AgencyID INT, CreatedOn DATETIME )

Table 2 - PayrollDetails ( AgencyID INT FOREIGN KEY TO Agency Table, PayrollID INT, PayrollCreatedOn DATETIME )

Now We sharded both the tables with AgencyID as a Sharding Key.现在我们使用 AgencyID 作为分片键对两个表进行分片。 but PayrollDetails table is very huge and it has more then 100 million of records.但是 PayrollDetails 表非常庞大,它有超过 1 亿条记录。 So now we are planning to shard PayrollDetails table again with the PayrollCreatedOn field and Primary Shard for both the tables should be with the Agency Key but payrollDetails table should shard with the both AgencyID and PayrollCreatedOn.How can we achieve it in Vitess?所以现在我们计划再次使用 PayrollCreatedOn 字段对 PayrollDetails 表进行分片,两个表的主分片都应该使用 Agency Key,但 payrollDetails 表应该使用 AgencyID 和 PayrollCreatedOn 进行分片。我们如何在 Vitess 中实现它?

Conceptually, the sharding key (primary vindex) is used to decide which shard a row goes to.从概念上讲,分片键(主 vindex)用于决定一行进入哪个分片。 So, it's not possible to have two sharding keys because they would dictate conflicting locations for the row.因此,不可能有两个分片键,因为它们会指定行的冲突位置。

If I understand correctly, you want to query the table using PayrollCreatedOn in the where clause, you can create a secondary Vindex.如果我理解正确,您想在 where 子句中使用PayrollCreatedOn查询表,您可以创建辅助 Vindex。 This will create a lookup table that points at where the row lives, and Vitess can exploit that.这将创建一个查找表,指向行所在的位置,Vitess 可以利用它。 There's an explanation for this here: https://vitess.io/docs/reference/vindexes/ .这里有一个解释: https://vitess.io/docs/reference/vindexes/ There is a new command called CreateLookupVindex that is capable of backfilling this lookup table.有一个名为CreateLookupVindex的新命令能够回填此查找表。 It's yet to be documented, though.不过,它还没有被记录在案。

Vitess also lets you "materialize" a table by using a different primary vindex. Vitess 还允许您通过使用不同的主 vindex 来“实现”表。 In that case, the second table will be a real-time copy of the first table, but sharded differently.在这种情况下,第二个表将是第一个表的实时副本,但分片方式不同。 You can see a demo for this on the vitess front page (scroll down to the video).您可以在 vitess 首页上看到一个演示(向下滚动到视频)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM