How to design a database for User Defined Fields?

前端 未结 14 600
花落未央
花落未央 2020-11-27 08:37

My requirements are:

  • Need to be able to dynamically add User-Defined fields of any data type
  • Need to be able to query UDFs quickly
  • Need to be
14条回答
  •  失恋的感觉
    2020-11-27 09:27

    Our database powers a SaaS app (helpdesk software) where users have over 7k "custom fields". We use a combined approach:

    1. (EntityID, FieldID, Value) table for searching the data
    2. a JSON field in the entities table, that holds all entity values, used for displaying the data. (this way you don't need a million JOIN's to get the values values).

    You could further split #1 to have a "table per datatype" like this answer suggests, this way you can even index your UDFs.

    P.S. Couple of words to defend the "Entity-Attribute-Value" approach everyone keeps bashing. We have used #1 without #2 for decades and it worked just fine. Sometimes it's a business decision. Do you have time to rewrite your app and redesign the db or you can throw a couple of bucks on cloud-servers, which are really cheap these days? By the way, when we were using #1 approach, our DB was holding millions of entities, accessed by 100s of thousands of users, and a 16GB dual-core db server was doing just fine

提交回复
热议问题