From: rstander@exa.co.za
To: pgsql-performance@lists.postgresql.org
Subject: Index and statistics not used
Date: Mon, 17 May 2021 22:42:25 +0200
Message-ID: <028e01d74b5d$25494700$6fdbd500$@exa.co.za> (raw)
Good day
I'm struggling with a Postgres 13 performance issue and nothing I do seem to
help.
I have two tables with one having a foreign key to the other. It happens to
be for this one client the foreign key is always null, so no violation would
be possible. When deleting from the one table the foreign key trigger for
constraint takes 20 seconds to run.
The tables look as follows
table1
id bigint pkey
value number
table2 (55 mil entries)
id bigint pkey
table1_id bigint (fkey to table1 id)
value number
Running delete from table1 where id = 48938 the trigger for constraint runs
for 20 seconds
Event when doing a simple select from table2 where table1_id = 48938 takes
about 8 seconds
I've tried the following, but nothing seems to change the outcome:
CREATE INDEX table2_idx ON table2(table1_id);
CREATE INDEX table2_idx2 ON table2(table1_id) WHERE table1_id IS NOT NULL;
CREATE INDEX table2_idx3 ON table2(table1_id) INCLUDE (id) WHERE table1_id
IS NOT NULL;
alter table table2 alter column table1_id set statistics 10000;
None of these steps changes the planner and it would continue to do table
scans.
Regards
Riaan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: rstander@exa.co.za, pgsql-performance@lists.postgresql.org
Subject: Re: Index and statistics not used
In-Reply-To: <028e01d74b5d$25494700$6fdbd500$@exa.co.za>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox