【问题标题】:(database design,mysql) Is my database design good for basic shopping cart?(I new in database design)(数据库设计,mysql)我的数据库设计适合基本的购物车吗?(我是数据库设计的新手)
【发布时间】:2010-05-25 10:55:10
【问题描述】:

我是数据库设计的新手,我想确保我做得很好。 请查看我的数据库设计的一部分:

我的基本购物车数据库设计:

//table that holds shopping cart items that customer choose(not press checkout and order //them)

**shopping_cart**
{
id (int)
product_id (int) fk
product_quantity (int)
customer_user_id (int) fk 
}

//table that holds product order data in time of checkout.(i hold them because supplier //can change after time products attributes value add some attributes or delete and change //the price of product)

**order**
{
id (int)
product_id (int)  fk
customer_user_id (int)  fk
}


//table that connect order  to attribute table for products attributes value in the moment //of   checkout

**order_attributes**
{
id (int)
order_id (int)  fk
attribute_id (int)  fk
}

//main product table
**product**
{
id (int)
sku (int) 
product_name (varchar)
supplier_user_id (int)  fk
}

//connection table many to many 
**product_attributes**
{
id (int) 
product_id (int)  fk
attribute_id (int)  fk
}

//table that holds products attributes (price, weight, color + new attributes that user //will create)

**attribute**
{
id (int)
product_id (int)  fk
attribute_name (varchar)
attribute_value(varchar)
}

谢谢你

【问题讨论】:

    标签: mysql database database-design data-structures


    【解决方案1】:

    嗯,您可以从设计中删除两个表:order_attributes、product_attributes。否则,您的选择查询将非常慢,必须从这么多表中加入。您可以将属性存储为订单和产品表中的列。

    【讨论】:

    • 如果你喜欢我的回答,你也可以把它设置为正确的,哈哈
    【解决方案2】:

    在我看来,这是一个糟糕的设计,因为它使用的是 EAV 表的属性表,这可能会导致性能问题。花点时间实际定义您想要为产品拥有的属性,大多数产品的属性(颜色、尺寸、单位(10 件装、单件等)实际上大多相似。EAV 是最后的手段。

    在 orderdetail 表中存储价格等的详细信息。如果产品价格在以后发生变化,您不希望价格发生变化。

    我的结构会是这样的: 命令 orderid, 日期, customerid 订单详细信息 order_id,Compnay_id,Product_id,part_number,product_name,数量,价格,Unit,Color,size,其他属性 订单备注 order_id,注意

    产品 product_id、Part_number、product_name、Company_id、产品价格、颜色、尺寸、单位

    当某些产品没有相同的属性时,最好使用空列(除非您有数百个通常不会使用的属性) 此外,如果您想要产品的完整规格,请考虑将它们放在一个大型 varchar 文件中并在其上放置一个全文索引。这应该比 EAV 表执行得更好。

    【讨论】:

    • 为什么magento使用EAV表?同样在我的应用程序中,我不知道产品的属性,因为供应商定义了它们。 Soo 如果每个供应商都能够添加新属性,那么表 products 将有很多列。
    • EAV 表是性能杀手,很难编写代码。如果你不知道一个部件有多少个属性,你甚至不知道加入表的次数。由于每个查询都会多次连接到这个表,它会产生锁定问题,并且通常意味着一旦你有一个真正的工作负载,性能将会很糟糕。我也不会让供应商添加列。选择零件需要六种左右的属性(颜色、尺寸、重量、单位等)。其他的都是描述性的,应该存储在一个带有全文索引的大字段中。
    • 我使用过的应用程序包含来自数千家供应商的部件,这些供应商的描述都具有高度技术性,而我们从来不需要更多。
    • 人们过分强调灵活性的能力,数据库的灵活性会带来巨大的性能成本,如果您尽职尽责并弄清楚真正需要什么,那么大多数情况下都是不必要的。我们有一个 COTS 产品,我们为此支付了超过 100,000 美元,它的设计速度非常慢,而且没有它应该有的所有东西,所以我们花了无数的工时来添加应该在那里的字段。它已经变得如此糟糕,以至于我们准备将其废弃,以便在没有大量定制的情况下工作。
    • 非常感谢。你觉得 spree(ecommerce - rubi on reils) 数据库设计怎么样?见模型图spreecommerce.ru/attachments/download/17/models.svg
    猜你喜欢
    • 2011-08-12
    • 2015-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多