YY Taobao commodity database design (transfer)

 

http://www.cnblogs.com/mmmjiang13/archive/2010/11/04/1868609.htm

YY Taobao commodity database design

 

foreword

  In the past few months, I have been working on a system for offline management of Taobao stores through Taobao API, and I have learned a lot. Here I want to express my own thoughts on the design of Taobao commodity tables. If you think it is nonsense, you can write your own opinions. .OK, to cut to the chase.

  The complexity of Taobao's products is the most complex and flexible among the e-commerce websites I have ever seen. Before reading the following, let's talk about the following terms in Taobao: key attributes, sales attributes, non-key Attributes. As shown below:

Key attribute : The attribute that can confirm the unique product, which can be one or a combination of multiple key attributes, for example: the "brand" and "model" of the camera can determine the unique product, and the "brand" and "item number" of the clothing can determine the unique product. product

Sales attributes : special attributes that make up the SKU , it will affect the buyer's purchase and the seller's inventory management, such as the "color", "package" and "size" of clothing, pay attention to the SKU here, Taobao sales attributes are combined into SKUs

Non-key attributes : It is the attribute of the product, some attributes that describe the product

Design of eigenvalues, eigenvalues

The first understanding of this kind of design was the guidance of the project manager. After he glanced at the data structure, he immediately said: The typical characteristic quantity corresponds to the design of the characteristic value. Um, admiration. Well, look at the data of the two tables below, it is very clear,

In the feature value table, store all names such as: brand, series, color, size, and store specific values ​​in the feature value. For example, there are 12 colors of clothes, then there are ID: 1, name: color in the left table , stored in the table on the right

For specific values ​​such as yellow, green, etc., the characteristic scale is a parent-child relationship. For example, some brands have series under the series, and there may be series under the series. It is unavoidable that there is redundancy in the data in the right table. For example, clothes have 24 colors. , shoes have 24 colors, although the eigenvalues ​​are the same, they belong to different eigenvalues.

Then as shown in the figure above, (note that I did not add a parent-child relationship to the feature scale in the above figure, there is a parent-child relationship during the design) I want to add a condom product, which is divided into at least 2 steps, first in the category table. Select family planning products --> until the sub-category of condoms, through the ID of the sub-category, cascade query the feature quantity and feature value table, get attributes such as brand, size, color, if there is a hierarchical relationship, such as brand The following series, there may also be series below the series, through the parent-child relationship in the feature scale, continue to query, of course, can also be queried at one time through the category ID, and then display the relationship.

Different price and quantity designs for the same commodity with different attributes?

  

  Let's look at the situation of adding clothes and digital cameras to Taobao. After selecting the "key attribute" color + size, you need to fill in the price and quantity and the merchant's external code for the combination of different colors and sizes, and the camera is color + package + The external code, and the shampoo is the capacity + buy more cheap + external code, here is the SKU introduced above, if you don't know the SKU, you can understand it, the direct advantage of doing this is that different combinations may have For different prices, accurate statistics can be achieved when doing inventory and sales statistics. Through the merchant's external code, the merchant can be associated with the local system, which is also for the convenience of statistics and inventory.

Well, everyone, take a look at my design, if you want to shoot, please tap

2011-03-23 ​​Fixed: This article has a problem with the table design as I understand it now! ! Please see here and leave immediately! You can also follow my follow-up Taobao analysis related articles~

1. Category and feature quantity, feature quantity and eigenvalue are not a many-to-many relationship, but a one-to-many relationship

2. Both categories and feature quantities are parent-child tables

3. The key attributes of the product such as: brand series (only store sub and ID), other attributes, such as pants type, suitable for the crowd, and other attributes are stored in the basic attribute table, here only the sub and ID are stored in the brand series because of consideration At this point, if you don't want to create too many tables, users can search for all the information by indexing such as luck. When doing statistics or data analysis, it can also be done through the parent-child relationship of parent-child feature quantities.

4. The separation of sales attributes is because, for example, shampoo, the values ​​in our feature value table may not meet the needs of users, so users can customize the values, upload pictures for colors, etc., and the sales attributes are generally multiple combinations. So create a separate table.

5. The SKU table of the product, the combination of this feature ID is actually the ID combination of the sales attribute table

When we add a product, we need these steps without considering the page display:

1. Insert the basic information of the product into the product table 

2. Insert basic attributes and key attributes into the product basic attribute table 

3. Insert the sales attribute into the sales attribute table

4. Insert the sales attribute ID combination, quantity, price, etc. into the product SKU table.

When we display products on the page:

1. Cascading 6 tables to query the information required by the product. Since there are multiple levels of key attributes, only subsums are stored here, and a recursion is required. Of course, you can consider your own implementation methods such as caching

2. Analyze product SKU combinations to generate sales attribute combinations and constraints, such as different prices after color + size selection, and whether they are still available. If the color has a picture, use the uploaded picture instead of the default background

The difficulty lies in:

1. The display of the page must be dynamically constructed regardless of the foreground or the background. On the basis of dynamic construction, basic verification is added. For example, the user chooses color A+ size, there are only 3 pieces in stock, and the quantity is filled in 5. It is necessary to remind the user that there is no such thing. Most of them, there are still some attributes in the dynamic construction that have hierarchical relationships. You need to choose one-time loading or AJAX loading according to your own strategy, and analyze and display

2. The design of several table association queries, which method can minimize the complexity of the program, whether it is done directly in the database, or the database combines memory tables (cache feature quantities and feature values).

On-page presentation and other designs

The way I add products in the actual project is to serialize attributes into json strings to the page, and dynamically create page forms according to whether the features are enumeration, parent attributes, key attributes, and sales attributes. Such as his API page , if you are interested, you can refer to his JS

In Brother Yang Guo 's blog, this article talks about how to dynamically create forms when adding products to his website. There is also an article on the design of category attributes. That category attribute design is also a good design. If you are interested, you can take a look. .

Well, the article is over here, go to sleep. Today may be another small climax of the soft articles of Blog Park 360 and qq, tragedy!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327037001&siteId=291194637