如何在数据库级别设计定价模块

发布于 2024-12-28 09:52:09 字数 1504 浏览 0 评论 0原文

我想在数据库中模拟以下场景:

我有一个包,由独立的 ActivitiesHotel 组成:

包 P:

  • 活动 A1、A2、A3< /strong>
  • 酒店H

活动酒店 是独立的实体,在定义时定义了自己的价格的实体。

当实体添加到套餐时,其价格可以更改(仅特定于套餐)。因此,每个套餐的活动/酒店都有独特的价格。

例如 (定义活动和酒店)

A1 - 10$
A2 - 20$

H1 - 100$

(将活动和酒店添加到包中)

Package p;
p.addActivity("A1", 15);
p.addActivity("A2", 25);
p.addHotel("H1", 50);

yields => 

p
 - A1 - 15
 - A2 - 25
 - H1 - 50

数据库端:

定义

  • 活动< /代码>:

    活动 ID、开始日期、结束日期、价格

  • 酒店

    酒店 ID、开始日期、结束日期、价格

添加到套餐后

  • 套餐表

套餐 ID、酒店 ID、活动 ID

  • 套餐-活动价格表

    Package-id, Activity-id, Price //package-id和activity-id作为唯一键

  • 套餐-酒店价格表:

    Package-id, Hotel-id, Price //package-id 和 hotel-id 作为唯一键

我需要一些关于我的设计的反馈。 我把这件事搞得太复杂了吗?有没有更简单/更好的方法来做到这一点? 另外,当我写这篇文章时,我认为一个套餐可以包含许多酒店和活动,因此需要在这里考虑这一点。 因为对于实体的每次价格查找我都将执行连接,所以我是否过于分散了?

编辑

找到了有关连接性能的相关链接:何时为什么数据库连接很昂贵?

I want to model the following scenario in the database:

I have a Package, comprising of independent Activities and Hotel:

Package P:

  • Activities A1, A2, A3
  • Hotel H

Activities and Hotel are independent entities which have their own price defined at the time of definition of entity.

When an entity is added to the package, it's price can be changed (only specific to the package). Hence, every package would have a unique price for the activities/hotels.

E.g.
(Defining activities and hotel):

A1 - 10$
A2 - 20$

H1 - 100$

(Adding activities and hotel to package):

Package p;
p.addActivity("A1", 15);
p.addActivity("A2", 25);
p.addHotel("H1", 50);

yields => 

p
 - A1 - 15
 - A2 - 25
 - H1 - 50

Database Side:

Definition:

  • Activity:

    Activity-id, StartDate, EndDate, Price

  • Hotel:

    Hotel-id, StartDate, EndDate, Price

After adding to package

  • Package table:

Package-id, Hotel-id, Activity-id

  • Package-Activity price table:

    Package-id, Activity-id, Price //package-id and activity-id serve as unique key

  • Package-Hotel price table:

    Package-id, Hotel-id, Price //package-id and hotel-id serve as unique key

I need some feedback on the design that I've come up with.
Have I over complicated this ? Is there a simpler/better way to do this ?
Also, as I was writing this, I figured a package can have many Hotels and Activities, so will need to factor that in here.
Have I fragmented this too much since, for each price lookup of an entity I will be performing a join ?

EDIT

Found a relevant link on performance with Joins: When and why are database joins expensive?

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

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

发布评论

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

评论(1

半暖夏伤 2025-01-04 09:52:10

实际上你这里确实需要五张桌子。

您有三个实体:活动、酒店和套餐(假设每个套餐都有一些与酒店或活动无关的数据)。您有两个多对多关系,即套餐-酒店和套餐-活动。每个关系行都标有特定的价格。

五张桌子是正确的选择。不,必须进行联接不是问题:它比拥有非正常数据要好。您可以稍后如有必要对性能进行非规范化。

You actually do need five tables here.

You have three entities: activities, hotels, and packages (assuming each package has some data which is not hotel- or activity-related). You have two relationships, both many-to-many, namely package-hotel and package-activity. Each relationship row is annotated with a particular price.

Five tables is the way to go. No, having to do a join is not a problem: it's better than having non-normal data. You can denormalize for performance later if necessary.

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