Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFkwm-0001Z2-1Z for pgsql-general@arkaria.postgresql.org; Wed, 02 Oct 2019 20:10:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iFkwi-00039w-Kx for pgsql-general@arkaria.postgresql.org; Wed, 02 Oct 2019 20:10:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iFkwi-00039F-3F for pgsql-general@lists.postgresql.org; Wed, 02 Oct 2019 20:10:00 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iFkwe-0005r4-Ne for pgsql-general@lists.postgresql.org; Wed, 02 Oct 2019 20:09:58 +0000 Received: by mail-ed1-x541.google.com with SMTP id r16so300454edq.11 for ; Wed, 02 Oct 2019 13:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=open-lab-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=pXRLwMUwXYcW1oYIXTrgr4a90UEpiD8MgToFzKoQxDQ=; b=OaO0U0u39yT7vsvMshTrWsvohfpBJagSEhKvOPRZiK0W+J034C8X/u68liSro6ZB+X uG88iu3R+dNlG2iNGEm5sfjhstSzaqOYxlK7zOBmPBFhY9adsTRnedb21x2f2DmKkmj5 P0yZFlgkFrYdT0ZbPsdN4AxKjTwkcJip7os6pKsvX4n6wTG0k/mZX3pAgaSEj0B6cYNK ZxXhwwSt1B50EJIAibtYSDJlTaHl+u8bidVbFDvaEPk+LN8APYpy7ZqYGok8mHSU0Mnr 5oDNhInvG4ix2pNtaeTOqfONzCF7EITBcU1v2RwIGOkkan38zdqycP9sjKO4ukPCFhL6 vqGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=pXRLwMUwXYcW1oYIXTrgr4a90UEpiD8MgToFzKoQxDQ=; b=DLDIRr8WRR4J5pB+q9VrtpJyZ1KNzzpcsIwqK8yQvP5bYUcrzhaKU13g1veqvqfRzd 0rrwMy/oSGbRsR7yVsoLIX62d9CCs8/atEP2dTduyfNBMG62cb/wpCRsqp6HNRHZSV5K izaGKQXzpItDOsSsk3Sh8gZtMN2nuS1TirqIUDcQHPdYK6YU8QOzibcECAhz7t09Pr7/ HwoKGrep8mbS1EpaN2+MXDhR1io0Oznvs5N5/sZ63D6CSLR6b9InA9S15yqH7JNBuiOM S05uVVhLei081DdapQnkGd0mCEafUQEVPge/3AlInrIoaxTl6vfJSweHj82G6PV06LPh Gklg== X-Gm-Message-State: APjAAAWQetq0PV0SQ53+37tgpta0CD+osGP3ZZ9DI3TqaDQWHFqhB3FN 2CxUOegCnuvcoXPuZ74eE1Chbp+2VKw= X-Google-Smtp-Source: APXvYqyeHtN4MZeDClnQA7loKjYjKyL+9DVvi/1HR8LJpQE3SrP+Q3QU/C+rhg6PjOAQfNiDRw+ZLw== X-Received: by 2002:a50:886d:: with SMTP id c42mr5848895edc.24.1570046994221; Wed, 02 Oct 2019 13:09:54 -0700 (PDT) Received: from [10.0.1.21] (ip5b41bfc9.dynamic.kabel-deutschland.de. [91.65.191.201]) by smtp.gmail.com with ESMTPSA id i5sm31730edq.30.2019.10.02.13.09.53 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Oct 2019 13:09:53 -0700 (PDT) From: "Enrico Thierbach" To: pgsql-general@lists.postgresql.org Subject: partitions vs indexes Date: Wed, 02 Oct 2019 22:09:52 +0200 X-Mailer: MailMate (1.13r5655) Message-ID: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_MailMate_69C57464-2F3F-440B-B759-69B1C448F8E6_=" Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --=_MailMate_69C57464-2F3F-440B-B759-69B1C448F8E6_= Content-Type: text/plain; charset="UTF-8"; format=flowed; markup=markdown Content-Transfer-Encoding: 8bit Hello list, I run into some trouble with partitions: I would like to convert a table with a primary key into a partitioned setup by a column which is not part of the primary key. Also, a column might hold a referenece to a parent row. So this is my current table setup, slimmed down: CREATE TYPE statuses AS ENUM ('ready', ‘processing’, ‘done’); CREATE TABLE mytable ( id BIGSERIAL PRIMARY KEY NOT NULL, parent_id BIGINT REFERENCES mytable(id) ON DELETE CASCADE, status statuses DEFAULT 'ready' ); Since entries in the table are often frequented when status is not ‘done’ I would like to partition by state. However, if I want to do that: CREATE TABLE mytable ( id BIGSERIAL NOT NULL, parent_id BIGINT REFERENCES mytable(id) ON DELETE CASCADE, status statuses DEFAULT 'ready' -- UNIQUE(id, status) -- doesn’t work: can’t reference parent -- UNIQUE(id) -- doesn’t work: can’t partition ) PARTITION BY LIST(status); I need to add status to the primary key or another unique constraint. In that case, however, I can no longer have the foreign key constraint on parent_id. Weirdly enough partitioning works fine if there is no unique constraint on that table: CREATE TABLE mytable ( id BIGSERIAL NOT NULL, status statuses DEFAULT 'ready' ) PARTITION BY LIST(status); So partitioning seems to require the column being in a unique constraint if and only if a unique constraint exist on the table. Also I cannot create multiple unique constraints on the table. Here comes my question: - Do I miss something? - ThI don’t understand the requirement the partition value to be part of a unique constraint if such a constraint exists, since partitioning seems to work fine if the table has no unique constraints at all. Can someone shed some light on that? Is that maybe an artificial limitation that will go away on the future? - Any suggestions how I could proceed? Thank you for any suggestion! Best, Eno -- me on github: http://github.com/radiospiel --=_MailMate_69C57464-2F3F-440B-B759-69B1C448F8E6_= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hello list,

I run into some trouble with partitions:

I would like to convert a table with a primary key into a= partitioned setup by a column which is not part of the primary key. Also= , a column might hold a referenece to a parent row. So this is my current= table setup, slimmed down:

CREATE TYPE statuses AS ENUM ('ready', =E2=80=98processing=E2=80=
=99, =E2=80=98done=E2=80=99);

CREATE TABLE mytable (
  id          BIGSERIAL PRIMARY KEY NOT NULL, =

  parent_id   BIGINT REFERENCES mytable(id) ON DELETE CASCADE,  =

  status statuses DEFAULT 'ready'
);

Since entries in the table are often frequented when stat= us is not =E2=80=98done=E2=80=99 I would like to partition by state. Howe= ver, if I want to do that:

CREATE TABLE mytable (
  id          BIGSERIAL NOT NULL, =

  parent_id   BIGINT REFERENCES mytable(id) ON DELETE CASCADE,  =

  status statuses DEFAULT 'ready'

  -- UNIQUE(id, status)        -- doesn=E2=80=99t work: can=E2=80=99t ref=
erence parent
  -- UNIQUE(id)                -- doesn=E2=80=99t work: can=E2=80=99t par=
tition
) PARTITION BY LIST(status);

I need to add status to the primary key or another unique= constraint. In that case, however, I can no longer have the foreign key = constraint on parent_id.

Weirdly enough partitioning works fine if there is no uni= que constraint on that table:

CREATE TABLE mytable (
  id          BIGSERIAL NOT NULL, =

  status statuses DEFAULT 'ready'
) PARTITION BY LIST(status);

So partitioning seems to require the column being in a un= ique constraint if and only if a unique constraint exist on the table. Al= so I cannot create multiple unique constraints on the table.

Here comes my question:

  • Do I miss something?
  • ThI don=E2=80=99t understand the requirement the partition value to b= e part of a unique constraint if such a constraint exists, since partitio= ning seems to work fine if the table has no unique constraints at all. Ca= n someone shed some light on that? Is that maybe an artificial limitation= that will go away on the future?
  • Any suggestions how I could proceed?

Thank you for any suggestion!

Best,
Eno

--
me on github: http://github.com/= radiospiel

--=_MailMate_69C57464-2F3F-440B-B759-69B1C448F8E6_=--