Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcCOr-0002AW-Uj for pgsql-performance@arkaria.postgresql.org; Tue, 14 Mar 2023 21:41:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pcCOq-000434-5m for pgsql-performance@arkaria.postgresql.org; Tue, 14 Mar 2023 21:41:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pcCOp-00042v-Rk for pgsql-performance@lists.postgresql.org; Tue, 14 Mar 2023 21:41:39 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pcCOl-0000xY-Ky for pgsql-performance@postgresql.org; Tue, 14 Mar 2023 21:41:39 +0000 Received: by mail-ed1-x541.google.com with SMTP id ek18so36675761edb.6 for ; Tue, 14 Mar 2023 14:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; t=1678830094; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=up5T5Xk+YmfCIHwBlYsx5TOgRGiscGSLNmWNp1dp/iU=; b=4bxiQMcx+cHHJ4JW3nUKJZBnd1+NLoecSj+KMbhxzchj7Hi3YP+OrKFQuMAlUWimQh MUe3lxsw3ZtDca7lOEJO6SfTkpUwb3nvBmzTuAx5DtJlRUTerL0E0BNcCpWcVwVZnpQ3 1xjyF+pLk6goek19IIBbSriZ+uT+tG/UJlLBOgzIb+6yVzjhAvPK37WlEmw1+ZZApN2z h9w6Y/S1t58GsLC/kQQyL5lissQ9oQ4nzmCMz0HRhq5IMah30KXT1nJ8lA+ctbiEPm78 hi5Rwl6irHR3zMKmrHgWUGhiTqphCcude8Svd536zTuBA4KccDZVQrQ3EqSmfQdwlkRK kU4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678830094; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=up5T5Xk+YmfCIHwBlYsx5TOgRGiscGSLNmWNp1dp/iU=; b=upewB0Awe0ojEwFRXUla9qxjL6353wgvN8koohZIfMMWr/7xSRgIsPVGkoZKeyPxON WXakuHh6TF06Tn8GDG64zpj3Cij2Amhn6nM0Ax6UFs5uKzpSTJh1ziZE6SpXrK7jvtw9 Mgn6oLBzNXlhH0oVaXPe3JjcxZtPzvXlNEpFWtamSzX4CQWYbMrGCcTT/mNsosoNZNMn UkvVadIRfjZdPbBKUI7aARTyRgiMaWqO7TosmOxTo8VyDHO63u/K89CX/WTsWa/bxkHP 7A3Tmcs5SGMX/2jJfiWjs9xuoas4lbSLRTP8OoFZP9Tgf/rx7BeCnemJYJLCtU3zhI/y jdtg== X-Gm-Message-State: AO0yUKUgO+5mVOtA28gZ70U/tKfsg233FTyKfqWNCoBbJDLrkuTorhVK oBwuuYVA/kAPZRJdezHRWXavfA== X-Google-Smtp-Source: AK7set9uni6K8IzUfrOsP3YF4DKzHbHw8w5kHY6hkf3Pjw7MdAt6MoCvC6GpAvJBToYWdwZJKU5HEg== X-Received: by 2002:a17:906:3518:b0:87e:9441:4c6c with SMTP id r24-20020a170906351800b0087e94414c6cmr4134109eja.49.1678830094332; Tue, 14 Mar 2023 14:41:34 -0700 (PDT) Received: from localhost.localdomain (p50992f7c.dip0.t-ipconnect.de. [80.153.47.124]) by smtp.gmail.com with ESMTPSA id qb8-20020a1709077e8800b0092ed6b8cd5bsm4227ejc.158.2023.03.14.14.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Mar 2023 14:41:34 -0700 (PDT) Message-ID: <784863d0cce3f14dcb41252fe90c11de1e8da902.camel@cybertec.at> Subject: Re: multicolumn partitioning help From: Laurenz Albe To: James Robertson , pgsql-performance@postgresql.org Date: Tue, 14 Mar 2023 22:41:32 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, 2023-03-12 at 13:59 -0400, James Robertson wrote: > I am having issues with multicolumn partitioning. For reference I am usin= g the following link as my guide: > https://www.postgresql.org/docs/devel/sql-createtable.html >=20 > To demonstrate=C2=A0my problem, I created a simple table called humans. I= want to partition by the year > of the human birth and then the first character=C2=A0of the hash. So for = each year I'll have year*16 partitions. (hex) >=20 > CREATE TABLE humans ( > =C2=A0 =C2=A0 hash bytea, > =C2=A0 =C2=A0 fname text, > =C2=A0 =C2=A0 dob date > =C2=A0 =C2=A0 )PARTITION BY RANGE (EXTRACT(YEAR FROM dob),substring(hash:= :text, 1, 1)); > =C2=A0 =C2=A0=20 > Reading the documentation:=C2=A0 =C2=A0"When creating a range partition, = the lower bound specified with > FROM is an inclusive bound, whereas the upper bound specified with TO is = an exclusive bound". >=20 > However I can't insert any of the following after the first one, because = it says it overlaps. > Do I need to do anything different when defining multi-column partitions? >=20 >=20 > This works: > CREATE TABLE humans_1968_0 PARTITION OF humans FOR VALUES FROM (1968, '0'= ) TO (1969, '1'); >=20 >=20 > These fail:=C2=A0 > CREATE TABLE humans_1968_1 PARTITION OF humans FOR VALUES FROM (1968, '1'= ) TO (1969, '2'); Justin has explained what the problem is, let me supply a solution. I think you want subpartitioning, like CREATE TABLE humans ( hash bytea, fname text, dob date ) PARTITION BY LIST (EXTRACT (YEAR FROM dob)); CREATE TABLE humans_2002 PARTITION OF humans FOR VALUES IN (2002) PARTITION BY HASH (hash); CREATE TABLE humans_2002_0 PARTITION OF humans_2002 FOR VALUES WITH (MODULUS 26, REMAINDER 0); [...] CREATE TABLE humans_2002_25 PARTITION OF humans_2002 FOR VALUES WITH (MODULUS 26, REMAINDER 25); and so on for the other years. Yours, Laurenz Albe