I need to implement a custom fields in my database so every user can add any fields he wants to his form/entities.
The user should be able to filter or/and sort his data by any custom field.
I want to work with MySQL because the rest of my data is very suitable to SQL. So, unless you have a great idea, SQL will be preferred over NoSQL.
We thought about few solutions:
JSON field - Great for dynamic schema. Can be filtered and sorted. The problem is that it is slower then regular columns. Dynamic indexes can solve that but is it too risky to add indexes dynamically.
Key-value table - A simple solution but a really slow one. You can't index it properly and the queries are awful.
Static placeholder columns - Create N columns and hold a map of each field to its placeholder. - A good solution in terms of performance but it makes the DB not readable and it has limited columns.
Any thoughts how to improve any of the solutions or any idea for a new solution?
SinSQLisStructuredand that applies to the data as well as the language. The idea of dynamic columns that apply to some rows and not others is a description ofunstructuredorpartially structureddata.EAVtable ;Entity(a key to the real row you're adding data to),Attribute(a "name" for the column/attribute/field/data that you're adding to that row),Value(the, umm, value, that you're adding). Instead of adding columns, you add rows. But they are also slow when used for filtering or sorting. I suspect there is no good answer, only aleast worstand that will depend heavily on your data, use cases, application, etc.