简体   繁体   English

各种对象的数据库设计

[英]Database design for various objects

I have application where users can create/update info about different objects (flats, rooms, houses, lands, etc.) 我有一个应用程序,用户可以在其中创建/更新有关不同对象(公寓,房间,房屋,土地等)的信息。

Every type of object has different set of parameters. 每种类型的对象都有不同的参数集。

I see to solutions: 我看到解决方案:

  1. Store all info inside one table id,title,object_type,rooms_count,house_floors_count,land_area,flat_area, description, etc.. 将所有信息存储在一个表id,title,object_type,rooms_count,house_floors_count,land_area,flat_area, description, etc..
    Pros : fast search (because every column has correct datatype, rooms_count - integer, description - text) 优点 :快速搜索(因为每一列都有正确的数据类型,rooms_count-整数,描述-文本)
    Cons : huge denormalization 缺点 :极大的非正规化

  2. Store info inside different tables objects: id,title,object_type,price object_params: id, param_title, param_type(integer,text,float,etc.) object_param_values: id_param,id_object,value (column of type text ) 将信息存储在不同的表对象中:id,title,object_type,price object_params:id,param_title,param_type(整数,文本,float等)object_param_values:id_param,id_object,value(类型为text列)
    Pros : denormalization, frontend guarantees that when object_type='flat' , then only parameters for flat are shown to user (in 1. it works like this too) 优点 :反规范化,前端保证当object_type='flat' ,仅向用户显示flat参数(在1.也是如此)
    Cons : value in object_param_values has type text what is bad for speed. 缺点object_param_values中的value具有text类型,这对速度不利。

There's a third option, use two tables. 还有第三个选项,使用两个表。

One table to store the basics of the object: id, title, object_type 一个表,用于存储对象的基础知识:id,title,object_type

Another table to store the parameters: id, object_id (from the previous table), parameter, data 另一个用于存储参数的表:id,object_id(来自上一个表),参数,数据

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM