【发布时间】:2018-12-21 19:03:21
【问题描述】:
Table "public.policy"
Column | Type | Collation | Nullable | Default
--------+---------+-----------+----------+----------------------------------------
pol_id | bigint | | not null | nextval('policy_pol_id_seq'::regclass)
top_id | integer | | |
idn_id | integer | | |
rsc_id | integer | | |
act_id | integer | | |
tup_id | integer | | |
我的表结构是这样的,除了 pol_id 之外的所有列都是外键。搜索策略可以发生在任何列上,但它将使用 top_id。例如;搜索 top_id =1 和 act_id =2 的策略。 我怎样才能更好地索引这个表?可以只索引 top_id 还是可以索引所有列。 这是一个事务表。此表中的记录最多可达 100 万到 2 条。
【问题讨论】:
-
nextval('policy_pol_id_seq'::regclass)看起来只与 Oracle 和 PostgreSQL 数据库兼容,所以我要删除 MySQL 标记。只标记您正在使用的数据库。 -
查询总是或大部分在
top_id和除pol_id之外的另一列上使用相等操作? -
1. select * from policy where top_id =1 and idn_id = 2 or 2. select * from policy where top_id =1 and act_id = 2;依此类推...或从 top_id =1 的策略中选择 *。与 top_id 的任意组合
标签: sql postgresql database-indexes