添加新的多个索引,我可以删除单个索引吗?

时间:2015-04-16 08:57:28

标签: sql database postgresql

我有数据库postgresql,其中是table。

CREATE TABLE film_ratings
(
  id serial NOT NULL,
  film_id integer NOT NULL,
  user_id integer NOT NULL,
  rating smallint NOT NULL,
  inserted_datetime timestamp without time zone DEFAULT date_trunc('second'::text, now()),
  updated_datetime timestamp without time zone DEFAULT date_trunc('second'::text, now()),
  CONSTRAINT film_ratings_pkey PRIMARY KEY (id),
  CONSTRAINT film_ratings_film_id_fkey FOREIGN KEY (film_id)
      REFERENCES pw_filmy (id) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE CASCADE,
  CONSTRAINT film_ratings_user_id_fkey FOREIGN KEY (user_id)
      REFERENCES pw_uzivatele (id) MATCH SIMPLE
      ON UPDATE RESTRICT ON DELETE CASCADE,
  CONSTRAINT film_ratings_film_id_user_id_ukey UNIQUE (film_id, user_id)
);

CREATE INDEX film_ratings_inserted_datetime_index ON film_ratings (inserted_datetime DESC);
CREATE INDEX film_ratings_user_id_inserted_datetime_index ON film_ratings (user_id, inserted_datetime DESC);
-- two single indexies
CREATE INDEX film_ratings_film_index ON film_ratings (film_id);
CREATE INDEX film_ratings_user_index ON film_ratings (user_id);

我的问题是,我可以删除最后两个索引( film_ratings_film_index film_ratings_user_index )吗?包含多个索引的位置,如唯一 film_ratings_film_id_user_id_ukey film_ratings_user_id_inserted_datetime_index

表有超过7000万行。

1 个答案:

答案 0 :(得分:0)

你的索引主要是在where子句的列中选取的,如果你有经常使用的sql的where子句中的film_id或user_id以及唯一的一个列,你可以保留它。