我有多个表:
results
id, data
filters
id, name, table
filter_strings
id, filter_id, result_id, value
filter_integers
id, filter_id, result_id, value
filter_booleans
id, filter_id, result_id, value我使用这种结构是因为我事先不知道筛选器,因此我不能拥有一个包含如下预定义筛选器列的表:
results
id, data, filterA, filterB, ...但是,我也可以使用json类型来存储其中的所有过滤数据:
results
id, data, filters
1, 'somedata', { age: 30, gender: 'male' }这将大大降低我的数据库的复杂性,但我担心查询会对性能造成很大的影响。有人有使用JSON查询的经验吗?
发布于 2018-01-31 01:17:36
这取决于你将在数据库上做什么类型的选择。如果您的查询几乎是针对过滤器内容的,那么直接在表上进行查询可能比必须获取所有行然后解析JSON更好。我主要使用不支持MySQL直接解析的JSON,但我听说Postgress的最新版本似乎支持它,在这种情况下,它可能是一个很好的选择。
https://stackoverflow.com/questions/48526947
复制相似问题