简体   繁体   English

将多个表映射到相同的类型/集合

[英]Mapping multiple tables to the same Type/Collection

I'm working on a little project that's designed to record a lot of data, I've estimated that I need to store about 100-150 million rows of data in my database. 我正在做一个旨在记录大量数据的小项目,我估计我需要在数据库中存储大约100-1.5亿行数据。 These rows don't contain much data but are going to have frequent inserts and I want relatively quick data retrieval (this is going to be infrequent but will require rapid aggregation of the data). 这些行包含的数据并不多,但是会频繁插入,并且我希望相对快速地进行数据检索(这种情况很少见,但需要快速汇总数据)。

From the information I've read at these sort of sizes I need to know what I'm doing and ensure Indexes etc are set up properly. 根据我所阅读的有关此类大小的信息,我需要知道我在做什么,并确保正确设置了索引等。 What I could do however is actually split my table of data up (into roughly 250, 500k row tables). 但是,我实际上可以将数据表拆分为大约250个,500k行表。

I guess the first question is, could someone validate that this would be a good idea? 我想第一个问题是,有人可以验证这将是一个好主意吗? From the things I've read I believe reads/inserts should be much quicker so it seems like a logical step to take. 从我读过的东西来看,我认为读/插入应该更快,所以这似乎是一个合乎逻辑的步骤。

I was also planning on using Entity Framework for this (despite the tables being quite simple) but I'm not sure if it's possible to map the same entity to lots of different tables. 我还计划为此使用Entity Framework(尽管表非常简单),但是我不确定是否可以将同一实体映射到许多不同的表。 I've found a number of articles on mapping two tables to the same entity. 我发现了许多有关将两个表映射到同一实体的文章。 So the second question is does Entity Framework allow you to map two tables to different entities of the same type? 因此,第二个问题是,实体框架是否允许您将两个表映射到相同类型的不同实体?

Splitting the data into multiple separate tables is not a good idea. 将数据分为多个单独的表不是一个好主意。 Databases in general and SQL Server in particular can handle large tables, even tables with hundreds of millions of rows. 总体而言,数据库尤其是SQL Server可以处理大型表,甚至是具有数亿行的表。 And, the implications of working with thousands of tables are daunting. 而且,使用数千个表的含义令人生畏。 It prevents you from setting up triggers and foreign key references. 它阻止您设置触发器和外键引用。 It makes security more difficult. 这使安全性更加困难。 It is daunting just to list the tables in the database. 仅列出数据库中的表是艰巨的。

One capability that might help you is vertical partitioning, described here . 一个功能,可以帮助你的是垂直分区,描述在这里 Partitions allow you to store one table in separate table spaces. 分区允许您将一个表存储在单独的表空间中。 This can speed queries, because only one partition may need to be read. 这可以加快查询速度,因为可能只需要读取一个分区。 This can speed deletes, because some deletes can be handled by dropping a partition. 这可以加快删除速度,因为某些删除操作可以通过删除分区来处理。

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

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