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 1l8643-0001V7-Pf for pgsql-admin@arkaria.postgresql.org; Fri, 05 Feb 2021 18:42:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l8642-0001B5-D6 for pgsql-admin@arkaria.postgresql.org; Fri, 05 Feb 2021 18:42:42 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8642-0001Ax-5E for pgsql-admin@lists.postgresql.org; Fri, 05 Feb 2021 18:42:42 +0000 Received: from mailout.easymail.ca ([64.68.200.34]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l863v-00014G-LP for pgsql-admin@lists.postgresql.org; Fri, 05 Feb 2021 18:42:40 +0000 Received: from localhost (localhost [127.0.0.1]) by mailout.easymail.ca (Postfix) with ESMTP id 68AB6A0396; Fri, 5 Feb 2021 18:42:33 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at emo05-pco.easydns.vpn Received: from mailout.easymail.ca ([127.0.0.1]) by localhost (emo05-pco.easydns.vpn [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fjuONJJXoMqX; Fri, 5 Feb 2021 18:42:33 +0000 (UTC) Received: from [192.168.2.127] (unknown [4.28.96.150]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mailout.easymail.ca (Postfix) with ESMTPSA id B9247A2C65; Fri, 5 Feb 2021 18:42:31 +0000 (UTC) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.4\)) Subject: Re: Partitioning Tables From: Scott Ribe In-Reply-To: <248F0103-EA30-4536-963B-73BD7477AF08@illinois.edu> Date: Fri, 5 Feb 2021 11:42:26 -0700 Cc: "pgsql-admin@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: <248F0103-EA30-4536-963B-73BD7477AF08@illinois.edu> To: "Campbell, Lance" X-Mailer: Apple Mail (2.3608.120.23.2.4) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Feb 5, 2021, at 11:27 AM, Campbell, Lance = wrote: >=20 > So if I do a query like the below it would ideally pull from partition = group_member_a rather than group_member_other. However, how would = PostgreSQL know on insert a group_member into the proper partition?=20 > =20 > Select group_member.* from group, group_member WHERE = group.type=3D=E2=80=99A=E2=80=99 and group.id=3Dgroup_member.user=3D=E2=80= =99bob smith=E2=80=99; When you define the partition, you declare what values go into it. With = PG 12, you can insert into the parent and the row will get redirected = into the right place. Some older versions (I don't remember how old) = required you to insert into the right table, or some voodoo with rewrite = rules or triggers. In other words, smarts about which partitions to scan in your example = pre-dates smarts about inserting. I don't remember for sure, but I think maybe PG 13 adds the feature = where if you update the group type, the row gets moved. Prior, you'd = have to delete and re-insert. Someone correct me? > Also, what happens if I did a query like this. Will it know to scan = both group_member_a and group_member_other: > =20 > Select group_member.* from group_member where group_member.user=3D=E2=80= =99bob smith=E2=80=99; Yes. Anyway, you are on the right track, in that what you're describing could = work. There are less invasive things you could try, which wouldn't give as = much benefit--like partial indexes for instance create index ... on group_member(user) where type =3D 'A' that gets you fast location of a single user, but if you looked for a = range of users, reading the index would be fast, but you'd still wind up = with the matching rows scattered all over the single big tablee