Delete, foreign key, index usage

Поиск
Список
Период
Сортировка
От Johann Spies
Тема Delete, foreign key, index usage
Дата
Msg-id CAGZ55DRKE8Jkj+aE+vxeQqC+uP46ujH5fAgL1vZLqafdeKZRiQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Delete, foreign key, index usage  (Johann Spies <johann.spies@gmail.com>)
Список pgsql-performance
While updating our database which includes a lot of deletions where a lot of foreign key references are involved we found that in the case of two tables the indexes are ignored and it slow down the process a lot.

Here are stats about those two tables:

relnameseq_scanseq_tup_readidx_scanidx_tup_fetchn_tup_insn_tup_updn_tup_deln_tup_hot_updn_live_tupn_dead_tupn_mod_since_analyze
belongs_to227525394875590077101459012514592230
publication22911502854612002540229060229483

Publication ( has a foreign key (ut) and more than 50million records) that references the top of the chain of references. This field (ut) is also the primary key of publication.

In the case of belongs_to (about 231393000 records)  which references the same table (article) ut has an index.

All other tables in this dependency chain reports 100% or near 100% usage of the indexes e.g.

citation_2010_2014002261882251001910081619104420


The indexes are on a ssd and we have set the random_page_cost to 1 for those queries.

The definition of belongs_to:

CREATE TABLE wos_2017_1.belongs_to
(
  suborg_id uuid,
  organisation_id uuid,
  address_id uuid,
  ut citext,
  uuid uuid NOT NULL,
  id integer NOT NULL DEFAULT nextval('wos_2017_1.belongs2_id_seq'::regclass),
  pref_name_id uuid,
  addr_no smallint,
  reprint_addr_no smallint,
  CONSTRAINT belongs2_pkey PRIMARY KEY (uuid),
  CONSTRAINT belongs_to_address_id_fkey FOREIGN KEY (address_id)
      REFERENCES wos_2017_1.address (uuid) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT belongs_to_pref_name_id_fkey FOREIGN KEY (pref_name_id)
      REFERENCES wos_2017_1.org_pref_name (uuid) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT belongs_to_suborg_id_fkey FOREIGN KEY (suborg_id)
      REFERENCES wos_2017_1.suborg (uuid) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE SET NULL,
  CONSTRAINT belongs_to_ut_fkey FOREIGN KEY (ut)
      REFERENCES wos_2017_1.article (ut) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE CASCADE,
  CONSTRAINT belongs2_id_key UNIQUE (id),
  CONSTRAINT belongs2_ut_suborg_id_organisation_id_address_id_addr_no_re_key UNIQUE (ut, suborg_id, organisation_id, address_id, addr_no, reprint_addr_no, pref_name_id)
)
WITH (
  OIDS=FALSE
);
with indexes on address_id, organisation_id, pref_name_id, ut

I have also tried to set enable_seqscan to false for these queries, but still no usage of the indexes.

Why would that be?

Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

В списке pgsql-performance по дате отправления:

Предыдущее
От: Riaan Stander
Дата:
Сообщение: Re: Best design for performance
Следующее
От: Johann Spies
Дата:
Сообщение: Re: Delete, foreign key, index usage