处理大量数据的最佳实践

发布于 2024-09-14 10:52:44 字数 510 浏览 1 评论 0原文

我需要对具有 26+ 百万行的表进行大量处理:

  1. 根据所述列的数据确定每列的正确大小
  2. 识别并删除重复的行。
  3. 创建主键(自动递增 id)
  4. 创建自然键(唯一约束)
  5. 添加和删除列

请列出有关如何加快此过程的提示以及执行上面列表的顺序。

非常感谢。

更新:无需担心并发用户。此外,该表上没有索引。该表是从源文件加载的。当一切都说完之后,就会有索引。

更新:如果您使用的列表与我列出的列表不同,请随时提及。

根据迄今为止的评论和我发现的有效内容:

  1. 从 26+ 百万行中创建行的子集。我发现 500,000 行效果很好。
  2. 删除不会使用的列(如果有)
  3. 使用 max(len()) 在一次扫描中为所有列设置适当的数据类型长度
  4. 在最终将成为自然键的列上创建一个(如果可能的话唯一的)聚集索引。
  5. 对所有行重复步骤 2-4

I need to do a lot of processing on a table that has 26+ million rows:

  1. Determine correct size of each column based on said column's data
  2. Identify and remove duplicate rows.
  3. Create a primary key (auto incrementing id)
  4. Create a natural key (unique constraint)
  5. Add and remove columns

Please list your tips on how to speed this process up and the order in which you would do the list above.

Thanks so much.

UPDATE: Don't need to worry about concurrent users. Also, there are no indexes on this table. This table was loaded from a source file. When all said and done there will be indexes.

UPDATE: If you use a different list from what I listed, please feel free to mention it.

Based on comments so far and what I have found worked:

  1. Create a subset of rows from the 26+ million rows. I found that 500,000 rows works well.
  2. Delete columns that won't be used (if any)
  3. Set appropriate datatype lengths for all columns in one scan using max(len())
  4. Create a (unique if possible) clustered index on column/columns that will eventually be the natural key.
  5. Repeat steps 2-4 on all the rows

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揽清风入怀 2024-09-21 10:52:44

如果您要删除某些列,则可能应该首先执行此操作。这将减少您必须为其他操作读取的数据量。

请记住,当您修改数据时,可能还需要修改包含该数据的索引。因此,如果您计划对表进行大量更新,然后再添加它们,通常最好删除索引。

If you are going to remove some columns, you should probably do that first if possible. This will reduce the amount of data you have to read for the other operations.

Bear in mind that when you modify data this may also require modifying indexes that include the data. It is therefore often a good idea to remove the indexes if you plan to make a large number of updates to the table, then add them again afterwards.

旧人哭 2024-09-21 10:52:44

顺序:5, 2, 1, 3, 4

1:没有办法解决:Select Max(Len(...)) From ...

2:这一切都取决于您认为重复的内容。

3:联机丛书中的 ALTER TABLE 会告诉您如何操作。确实没有办法加快速度。

4:参见 3。

5:参见 3。

Order: 5, 2, 1, 3, 4

1: No way around it: Select Max(Len(...)) From ...

2: That all depends on what you consider a duplicate.

3: ALTER TABLE in Books Online will tell you how. No way to speed this up, really.

4: See 3.

5: See 3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文