分层数据库模型[英] Hierarchical database model

本文是小编为大家收集整理的关于分层数据库模型的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在设计一个有关宠物的分类网站,该网站将有3个(主要)类别的广告:

A- Sale
B- Breeding
C- Jobs

我面临的问题是所有3个广告类别都有一些共同点,但它们也有一些差异.

例如,类别A,B和C都有以下共同点:

category_id
ad_id
user_id
location

但是,B类广告不能归类为"寻找/出售",而B&C可以.此外,每个类别都将具有自己的子类别.例如,类别A将具有采用子类别,并且销售子类别和类别C将具有作业子类别和服务子类别.

他们还将仅在C类中具有一些不常见的属性.

我已经开始作为实体 - 属性值模型来研究它,但是我有几个问题:

  1. 这会影响性能吗?因为用户应该能够根据某些唯一属性进行搜索.因此,通过一张巨大的桌子查询会影响性能吗?

  2. 我的属性之一是"动物"(A&B独有),最初我想拥有一个动物桌和一个品种桌(类似于分类DB模型的位置在其自身桌上的位置类似).但是我无法想象如何使用实体 - 属性模型进行此操作.

这是我想出的数据库设计: http://i.imgur.com/jyv6cjc .png

[更新]

在class表中阅读后,它似乎比EAV模型更好,因此我将EER更改为: http://i.imgur.com/jwpjt23.png

  1. 职位广告和销售广告可以归类为"寻找/提供",但是属性上没有太多差异,可能只是其名称(例如,价格与优先价格).因此,您认为有必要在这里添加其他级别的继承,或者是麻烦?

  2. 销售广告可以是出售的宠物,收养宠物,要求收养,要求购买宠物.您认为我应该将它们分成两个表.收养和销售?属性不会有很大的区别,可能只是一个不同的属性.

推荐答案

您的问题听起来像是类/子类的情况.在对象建模中,设计使用了继承的基本机制以及扩展和修改超类的子类的设计模式.

关系建模与对象建模不同,表设计与对象设计不同.有几种技术有助于弥合差距.该区域中有两个标签相关,.我将自由地将这两个标签添加到您的问题中.如果您不喜欢它们,请将它们备份.

本文地址:https://www.itbaoku.cn/post/597336.html

问题描述

I'm designing a classifieds website about pets that will have 3 (main) categories of ads:

A- Sale
B- Breeding
C- Jobs

The problem I'm facing is that all 3 ad categories have some things in common, but they also have some differences.

For example, categories A, B and C all have the following in common:

category_id
ad_id
user_id
location

However, category B ads cannot be classified as "Looking For/For Sale", whereas B & C can. Furthermore, each category will have its own subcategories. For example, category A would have an adoption subcategory and a sale subcategory & category C would have a Jobs subcategory and a Services subcategory.

They'll also have some uncommon attributes like salary in category C only.

I've began working on it as an entity-attribute-value model, but I have several concerns:

  1. Is this going to affect performance? Because users should be able to search based on some of the unique attributes. So wouldn't querying through one huge table affect performance?

  2. One of my attributes is "Animal" (unique to A & B), initially I wanted to have an Animal table and a Breed table (Similar to how Location is in a table of its own for classifieds DB models). But I can't imagine how I can do this with the entity-attribute-model.

Here's the database design I've come up with: http://i.imgur.com/jyV6Cjc.png

[Update]

After reading up in class table inheritance, it seemed like a better fit than the EAV model, so I changed my EER to this: http://i.imgur.com/JWPjt23.png

  1. Job Ads and Sale Ads can be classified as "Looking For/Offering", but there wouldn't be many differences in the attributes, probably just their names (Price vs. Preferred Price for example). So do you think it would be necessary to add another level of inheritance here, or would it be a hassle?

  2. A Sale Ad can be a pet for sale, pet for adoption, requesting an adoption, requesting buying a pet. Do you think I should split these into two table. Adoption and Sale? There wouldn't be a big difference in the attributes, probably just one different attribute.

推荐答案

Your question sounds like a case of class/subclass. In object modeling, the design uses the fundamental mechanism of inheritance, and the design pattern of subclasses that extend and revise superclasses.

Relational modeling is different from object modeling, and table design is different from object design. There are a couple of techniques that help bridge the gap. There are two tags in this area that are relevant, and . I'm about to take the liberty of adding those two tags to your question. Back them out if you don't like them.