简体   繁体   English

如何在超过 1,000,000,000 条记录中更改 substring?

[英]How to change substring in more than 1,000,000,000 records?

I have a database table with columns dbValues and dbKeys .我有一个包含dbValuesdbKeys列的数据库表。 The dbKeys value is a string containing keys separated with ; dbKeys值是一个字符串,其中包含用;分隔的键。 . .

dbKeys 1: "name;age;color;...price"
dbKeys 2: "city;street;age;...favourite_meal"
...

dbValues has same formatting as dbKeys but contains values for this keys. dbValuesdbKeys具有相同的格式,但包含此键的值。

dbValues 1: "Peter;18;blue;...64"
dbValues 2: "London;Main;40;...applepie"
...

There are more than 1 000 000 000 rows.有超过1 000 000 000行。 I need to delete some keys and its values from all of the records where the key is, for example the age key, so the result would be:我需要从键所在的所有记录中删除一些键及其值,例如age键,因此结果将是:

dbKeys 1: "name;color;...price"
dbKeys 2: "city;street;...favourite_meal"
...

dbValues 1: "Peter;blue;...64"
dbValues 2: "London;Main;...applepie"
...

Do you have any recommendation how to modify all the records with the specific key value in the dbKeys column in the most effective way?您有什么建议如何以最有效的方式修改dbKeys列中具有特定键值的所有记录? I prefer some SQL, or something in .NET / C#.我更喜欢 SQL 或 .NET / C# 中的一些东西。

My solution is to create for-cycle over all the records (or over every 1000 records) and change every record separately.我的解决方案是为所有记录(或每 1000 条记录)创建循环并分别更改每条记录。 But it doesn't look very effective to me.但这对我来说似乎不是很有效。 So I'm opened for any other suggestion.所以我愿意接受任何其他建议。

This will be really difficult in SQL but pretty easy in C#.这在 SQL 中将非常困难,但在 C# 中非常容易。 Just:只是:

  • Load the record加载记录
  • Split the values (for both columns) into lists with String.Split()使用String.Split()将值(对于两列)拆分为列表
  • Loop through the keys.循环遍历键。 If there is a match, delete the index from both lists.如果匹配,则从两个列表中删除索引。
  • Join the lists back into strings with String.Join()使用 String.Join() 将列表重新加入字符串
  • Save the record保存记录

You might want to save in a batch rather than individually.您可能希望批量保存而不是单独保存。

Of course storing the data in this form is not ideal in the first place.当然,首先以这种形式存储数据并不理想。 But you probably already know that.但你可能已经知道了。

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

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