我有两种设计。想要检查哪一个更适合你们。减少冗余的SQL表设计
所以我有三个表offer,offer_type和offer_type_filter。
表的原始设计
报价
id int(10) unsigned
code varchar(48)
offer_type_id int(10) unsigned
start_date datetime
exp_date datetime
value int(10)
updated timestamp
created datetime
OFFER_TYPE
id int(10) unsigned
name varchar(48)
condition varchar(512)
offer_type_filter
id int(10) unsigned
filter_type varchar(20)
filter_value varchar(50)
offer_type_id int(10) unsigned
现在,您可能会猜测,此优惠有一个类型,并且过滤器会指定在哪些特定情况下优惠活动适用。如果你想知道,那么offer_type.condition主要是购买最低价20美元。 $ 300。 Offer_type_filter仅适用于麦当劳。优惠可以不用过滤器。
当前设计的一个概念是每次创建新商品时,即使类型相同,我也必须在offer_type中创建一个重复条目,然后在offer_type_filter中使用该类型(使用当前类型将会混淆现有商品)。
所以在数据库重新设计方面,它是很明显的,OFFER_TYPE不得offer_type_filter存在,所以我相信它必须改变这样的事情
重新设计(与offer_type_filter和创造新的破除表过滤器。它基本上是重命名为更合适的东西)
过滤
id int(10) unsigned
filter_type varchar(20)
filter_value varchar(50)
filter_type_set_id int(10) unsigned
佛R以外的表,我想这两个选项
选项1(从重新设计+其他表offer_type_filter从最初的设计一样)
报价
id int(10) unsigned
code varchar(48)
offer_type_filter_mapping_id int(10) unsigned
offer_type_filter_mapping
id int(10) unsigned
filter_type_set_id int(10) unsigned > from Filter table
offer_type_id int(10) unsigned
如果我选择第一个设计,那么我会减少offer_type_filter_mapping中的任何项目。对于没有过滤器的商品,offer_type_filter_mapping将具有offer_type_id条目,并将null作为filter_type_set_id。此外,对于我创建的每种类型,我都必须在映射表中放入一个条目。所以我不喜欢这方面的设计。
选项2(offer_type_filter从重新设计+其他表从最初的设计一样)
报价
id int(10) unsigned
code varchar(48)
filter_type_set_id int(10) unsigned > from Filter table
我来选择2只因为在这种情况下,对每个冗余filter_type_set_id报价和在我的情况下报价表是巨大的
想要批评你认为哪种设计是最不痛苦的。频繁使用案例:使用和不使用过滤器创建大量优惠。我们已经有接近40-50个优惠类型。类型表不能覆盖所有场景,所以我们确实创建了10%的新类型。
另外我使用Spring和Hibernate,所以你可以从这个角度思考我的设计约束是什么。
P.S.你甚至可以在mysql中添加它,如在offer_type_filter中为每个表生成两个id是不方便的,但我正在考虑它。 Prob使用虚拟表来生成或使用外部生成的ID。
你知道设计的基数? – jcho360
是1报价只能有1种报价类型。现在,此优惠可以适用于使用或不使用过滤器。 –