【发布时间】:2014-03-17 11:31:45
【问题描述】:
我有这个表结构:
CREATE TABLE user_items
(
user_id bigint references users(id) NOT NULL,
item_id bigint references items(id) NOT NULL,
col1 json DEFAULT '[{"text":""}]',
col2 json DEFAULT '[{"date":"","text":""}]',
col3 json DEFAULT '{"text":""}',
PRIMARY KEY (user_id, item_id)
)
我将运行如下查询:
SELECT * FROM user_items WHERE item_id = '?' AND col1 IS NOT NULL
在这种情况下我需要索引(item_id, col1) 吗?
如果是这样,那么正确的做法是什么,因为在尝试它时 Postgres 会抛出错误,因为 col1 是 JSON 类型。
【问题讨论】:
标签: sql json postgresql indexing