Если Вы добавляете достаточно объектов, что Вы эффективно создаете список с нуля, необходимо быть в состоянии получить лучшую производительность путем сортировки списка впоследствии.
, Если объекты главным образом в порядке, можно настроить и инкрементное обновление и регулярную сортировку для использования в своих интересах этого, но откровенно говоря, это обычно не стоит проблемы. (Также необходимо остерегаться вещей как проверка, что некоторое неожиданное упорядочивание не может заставить алгоритм взять много дольше , q.v. наивный quicksort)
И инкрементное обновление и регулярный вид списка являются O (N, регистрируют N), но можно получить лучший постоянный множитель, сортирующий все позже (я предполагаю здесь, что у Вас есть некоторый вспомогательный datastructure, таким образом, Ваше инкрементное обновление может объекты списка доступа быстрее, чем O (N)...). Вообще говоря, сортировка внезапно имеет намного больше свободы дизайна, чем поддержание упорядочивания инкрементно, так как инкрементное обновление должно поддержать полный порядок в любом случае, но внезапно объемный вид не делает.
, Если ничто иное, помните, что существует много высоко оптимизированных объемных доступных видов.
The primary table contains the parent records, those records that define the root records such as "posts" in this example.
The foreign tables contain child records, those records that add data to parent records in a related way.
So, a "comment" is a child of a "post", therefore: "Post" is parent (primary in your example) "Comment" is child (foreign in your example)
PostId values must be unique in the Post table... but the same PostId value can occur multiple times in the Comment table (because there might be many comments for a single post; comment 1 is for post 1, comment 2 is for post 1).
1-1 relationships are when two entities are peers. i.e. a Student may be a User and a User may be a Student. Two students cannot be the same user. Two users cannot be the same student. Therefore User - Student are 1-1.
Many to many relationships are best modeled with a table in between.
Book (primary)
Author (primary)
AuthorBooks (mapping)
BookId is unique in Books (only one book may have a certain id)
AuthorId уникален в Authors (только один автор может иметь определенный идентификатор)
AuthorBooks имеет столбцы BookId и AuthorId и сопоставляет книги с авторами.
Эта связь моделируется, потому что автор мог написать много книг и потому что конкретный у книги может быть много авторов.
Given:
table posts
post_id
table comments
comment_id
post_id
table posts_to_comments
post_comment_id
post_id
comment_id
posts would be your "primary" table as you're thinking of it.
For a many-many relationship: (doesn't make too much sense here, but anyway)
posts_to_comments.post_comment_id is primary key
posts_to_comments.post_id is foreign key to posts
posts_to_comments.comment_id is foreign key to comments
I never heard about primary and foreign used to indicate tables. They are characteristic of columns.
In the example you give:
For many to many relationships, such as Networks and Users, where networks can have many members, and users can belong to many networks, you'll need to introduce a third table, which can be called something like (choose whichever you find most appropriate):
This table will have a composite primary key, consisting of userId and networkId. Additionally, userId will reference Users.id as a foreign key, and networkId will reference Networks.id as a foreign key.