pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Perry Smith <pedz@easesoftware.com>
Cc: pgsql-general@postgresql.org <pgsql-general@postgresql.org>
Subject: Re: ***SPAM*** Re: Help with large delete
Date: Sat, 16 Apr 2022 13:15:33 -0400
Message-ID: <1958274.1650129333@sss.pgh.pa.us> (raw)
In-Reply-To: <D025163A-B67D-4F70-B83A-8DECFA6D8704@easesoftware.com>
References: <3823FD54-2910-41E5-B908-869DA917DE82@easesoftware.com>
	<1939729.1650123237@sss.pgh.pa.us>
	<D025163A-B67D-4F70-B83A-8DECFA6D8704@easesoftware.com>

Perry Smith <pedz@easesoftware.com> writes:
> On Apr 16, 2022, at 10:33, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The most obvious question is do you have an index on the referencing
>> column.  PG doesn't require one to exist to create an FK; but if you
>> don't, deletes of referenced rows had better be uninteresting to you
>> performance-wise, because each one will cause a seqscan.

> For Tom’s question, here is the description of the table:

> psql -c '\d dateien' find_dups
>                                           Table "public.dateien"
>    Column   |              Type              | Collation | Nullable |               Default
> ------------+--------------------------------+-----------+----------+-------------------------------------
>  id         | bigint                         |           | not null | nextval('dateien_id_seq'::regclass)
>  basename   | character varying              |           | not null |
>  parent_id  | bigint                         |           |          |
>  dev        | bigint                         |           | not null |
>  ftype      | character varying              |           | not null |
>  uid        | bigint                         |           | not null |
>  gid        | bigint                         |           | not null |
>  ino        | bigint                         |           | not null |
>  mode       | bigint                         |           | not null |
>  mtime      | timestamp without time zone    |           | not null |
>  nlink      | bigint                         |           | not null |
>  size       | bigint                         |           | not null |
>  sha1       | character varying              |           |          |
>  created_at | timestamp(6) without time zone |           | not null |
>  updated_at | timestamp(6) without time zone |           | not null |
> Indexes:
>     "dateien_pkey" PRIMARY KEY, btree (id)
>     "unique_dev_ino_for_dirs" UNIQUE, btree (dev, ino) WHERE ftype::text = 'directory'::text
>     "unique_parent_basename" UNIQUE, btree (COALESCE(parent_id, '-1'::integer::bigint), basename)
> Foreign-key constraints:
>     "fk_rails_c01ebbd0bf" FOREIGN KEY (parent_id) REFERENCES dateien(id) ON DELETE CASCADE
> Referenced by:
>     TABLE "dateien" CONSTRAINT "fk_rails_c01ebbd0bf" FOREIGN KEY (parent_id) REFERENCES dateien(id) ON DELETE CASCADE

Yeah.  So if you want to make deletes on this table not be unpleasantly
slow, you need an index on the parent_id column, and you don't have one.

(unique_parent_basename doesn't help, because with that definition it's
useless for looking up rows by parent_id.)

			regards, tom lane





view thread (2+ messages)

Message-ID: <1958274.1650129333@sss.pgh.pa.us>
Permalink:  ../1958274.1650129333@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1958274.1650129333@sss.pgh.pa.us

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pedz@easesoftware.com
  Subject: Re: ***SPAM*** Re: Help with large delete
  In-Reply-To: <1958274.1650129333@sss.pgh.pa.us>
  References: <3823FD54-2910-41E5-B908-869DA917DE82@easesoftware.com> <1939729.1650123237@sss.pgh.pa.us> <D025163A-B67D-4F70-B83A-8DECFA6D8704@easesoftware.com> <1958274.1650129333@sss.pgh.pa.us>

* 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