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 1gh7hu-0001Cp-DK for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jan 2019 06:51:18 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gh7ht-00058g-5q for pgsql-hackers@arkaria.postgresql.org; Wed, 09 Jan 2019 06:51:17 +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 1gh7hs-00054J-Kx for pgsql-hackers@lists.postgresql.org; Wed, 09 Jan 2019 06:51:16 +0000 Received: from mail-it1-x12d.google.com ([2607:f8b0:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gh7hp-0008Kg-5w for pgsql-hackers@postgresql.org; Wed, 09 Jan 2019 06:51:15 +0000 Received: by mail-it1-x12d.google.com with SMTP id g85so10144112ita.3 for ; Tue, 08 Jan 2019 22:51:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=qL5o9TLAAPEF9fHjf/Y2zOliztnjXXguRfWCcNZXGHQ=; b=QliiOxv9hEYHWKXRjkLcZIPitW/41+cx4c5/LSWHeiyPzND0c0gzxv/riIL4LiXRc2 1+rJPzlbFiGzl1VEmj3b79lMzeZxMgBxdXrM+nGU7BdSgiVkp0Guncz9XeR7ND53gDMU 2r2mupj0YeKAzUr62U9n2R7X6wO+WQenB1REtzywKA0PppgckH2NjZYyw5g4OJWQ+1NJ hq4iF4raSqDPOlUHgq4yDnjOOqMXzV1DI2KRS43U3vDDtef0zsBcPltD0gDi8TIW7End vBpi6rqGKk7l3jJJq7oM8t4GoIYZ0YkPzus05uxbACBrmVfi5opO2ZSb/55tEPMxcBC5 h0jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=qL5o9TLAAPEF9fHjf/Y2zOliztnjXXguRfWCcNZXGHQ=; b=RPj87Mk2Fdq4w2lcEkRZcZ1QLr0HTZKhYWZJW78kEC7HcD+dvWj2c4MyHijRYN36eu mxQ2sng6WFyN/s14cjJ1FlHWau6i5Vk5uOrMOlD3WBKgGEyw4XO6nTSunL3cjEQV3VQU 3XVcsgGpKZtMFRdHs0XHdfbQh1HH+8b+BUcR7MOY4+uG4fhmwvxLfv/JORAbnDf8/sNh nUD36X4gQG9cJnbv1gAqi/qOQ+boQrH8YlYsz3dLCmnG2YGa3JpXCsiHyx/xSDldBJJm b9gda9oPvicZEt+Dd1gNmPlgzv+kS0+6GVsMNjRQcaS++Mh0v0BwZkl7tr6UHhy+hzwy BhzQ== X-Gm-Message-State: AJcUukfpwT8eoFX8VR8VXt3ICsF7+U42BY42K1dqiAP7Ih8jcBTqblPR 9mhlq1xJeNtW2hH9ID46/7UuQA== X-Google-Smtp-Source: ALg8bN4Vy3FvRYCy+yMC+Djv+Tn5EwjC3J1oMYXFFKZL+NTbzahc2oukbGeTM9qbSXVD/21ocaEuAw== X-Received: by 2002:a24:a0cb:: with SMTP id o194mr3058262ite.115.1547016672287; Tue, 08 Jan 2019 22:51:12 -0800 (PST) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id c41sm3237061itd.15.2019.01.08.22.51.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Jan 2019 22:51:11 -0800 (PST) Received: by pryzbyj (Postfix, from userid 1000) id 04722801065; Wed, 9 Jan 2019 00:51:09 -0600 (CST) Date: Wed, 9 Jan 2019 00:51:09 -0600 From: Justin Pryzby To: pgsql-hackers@postgresql.org Cc: Alvaro Herrera , Teodor Sigaev Subject: unique, partitioned index fails to distinguish index key from INCLUDEd columns Message-ID: <20190109065109.GA4285@telsasoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk eb7ed3f3063401496e4aa4bd68fa33f0be31a72f Allow UNIQUE indexes on partitioned tables 8224de4f42ccf98e08db07b43d52fed72f962ebb Indexes with INCLUDE columns and their support in B-tree postgres=# CREATE TABLE t(i int,j int) PARTITION BY LIST (i); postgres=# CREATE TABLE t1 PARTITION OF t FOR VALUES IN (1); postgres=# CREATE TABLE t2 PARTITION OF t FOR VALUES IN (2); -- Correctly errors postgres=# CREATE UNIQUE INDEX ON t(j); ERROR: insufficient columns in UNIQUE constraint definition DETAIL: UNIQUE constraint on table "t" lacks column "i" which is part of the partition key. -- Fails to error postgres=# CREATE UNIQUE INDEX ON t(j) INCLUDE(i); -- Fail to enforce uniqueness across partitions due to failure to enforce inclusion of partition key in index KEY postgres=# INSERT INTO t VALUES(1,1); postgres=# INSERT INTO t VALUES(2,1); postgres=# SELECT * FROM t; i | j ---+--- 1 | 1 2 | 1 (2 rows) I found this thread appears to have been close to discovering the issue ~9 months ago. https://www.postgresql.org/message-id/flat/CAJGNTeO%3DBguEyG8wxMpU_Vgvg3nGGzy71zUQ0RpzEn_mb0bSWA%40mail.gmail.com Justin