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 1l8FDN-0004cl-IV for pgsql-admin@arkaria.postgresql.org; Sat, 06 Feb 2021 04:28:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l8FCo-0007vE-Js for pgsql-admin@arkaria.postgresql.org; Sat, 06 Feb 2021 04:28:22 +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 1l8FCo-0007v6-7j for pgsql-admin@lists.postgresql.org; Sat, 06 Feb 2021 04:28:22 +0000 Received: from mail-ej1-x636.google.com ([2a00:1450:4864:20::636]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1l8FCk-0005QG-EF for pgsql-admin@lists.postgresql.org; Sat, 06 Feb 2021 04:28:20 +0000 Received: by mail-ej1-x636.google.com with SMTP id r12so15729897ejb.9 for ; Fri, 05 Feb 2021 20:28:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=RHMsdXYxIw7lOLwUfjTDzJXUyDkIaZnq1Ma2fSqYFnU=; b=Y50ciFTlcvAxN5hS3+1ozeplUeIAr+g27oet2d2HNTePtUAuxgfIdd1rv0Z4P5vmdo QEjKCm+QCLQ8ruFxt6nTFCGA0ZK9mmlSkJrzxrCjGJ3p0sXmZKZzXtrnnTaUUnC9N41S ozzxlKaBliN6GYyg0gCas0RV1BPLJHr9W4R03K9pSa4/J+MWms2yrQ4ERkUAws0zuODS wr0lqpwKFZOESr57IPq+57OtbRY/qUNAJhUqPucbyep57e/apUpFX2hVAGWRdAS5JY53 XDLHY4/ghu6NvIVETUnGKSGpTxS009Cvyy5Z/QKSa0UuB1XH8LpxXcoi+31KTZmU270I Ek+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=RHMsdXYxIw7lOLwUfjTDzJXUyDkIaZnq1Ma2fSqYFnU=; b=m7CBRm+TT5X+9EmqROLxaB1/QD2CGDhx9ZOtCGsvFDbVzwpHkBF3Tg2VNuh3zjCPz7 K/YH1DIw/+KcP0BMpI3lm/sx401CsY7PIYtk9BTJbtF7GrdMES4YfqqDTwz45hvwS3yW IDmtB421VJmAhuZMuDbvKtgLvTQ/errw2k5fiQtmmbJNCoNSKreyoA+EBoyKdcHgO22v KzdEZmicJM6bkKkeE4eR+B0C3hirpoIlt6ocjFqnEPDW2dupgUTHlYkKyliLEBgh/qjn 89MipN5MDLEbU4N+EremuUPSHD21sOpQ2xAgD0mKe8KGPYNEUM7uXc+qGj67+uen9Sxa ieFw== X-Gm-Message-State: AOAM531rN7sRfAq+ovooHAcsKvvo8O+i15KaLSX1IxUaTZKs5t2FAjqb at1+G2WuGEhvjrzPla9F+k/Q4g== X-Google-Smtp-Source: ABdhPJx5esqUSMaJ3g/unDA3VH1ivWp4c2DFRfQLVtlQbQ9HJtDBXrwhGSb897hCzkVsJecgx4crGw== X-Received: by 2002:a17:906:538c:: with SMTP id g12mr7148276ejo.248.1612585695472; Fri, 05 Feb 2021 20:28:15 -0800 (PST) Received: from localhost.localdomain (91-115-145-8.adsl.highway.telekom.at. [91.115.145.8]) by smtp.gmail.com with ESMTPSA id kb25sm351258ejc.19.2021.02.05.20.28.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 20:28:15 -0800 (PST) Message-ID: <0fbb3e14e792b85057441739053a2c608bf74318.camel@cybertec.at> Subject: Re: Partitioning Tables From: Laurenz Albe To: "Campbell, Lance" , "pgsql-admin@lists.postgresql.org" Date: Sat, 06 Feb 2021 05:28:14 +0100 In-Reply-To: <248F0103-EA30-4536-963B-73BD7477AF08@illinois.edu> References: <248F0103-EA30-4536-963B-73BD7477AF08@illinois.edu> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, 2021-02-05 at 18:27 +0000, Campbell, Lance wrote: > I have a challenge. I have two tables, group and group_member. A group table has a > type indicator telling me which of three ways the table can be used. The group member > table is made up of 50 million records that have a foreign key to the group table. > > I really need the queries to be fast for one particular type of group. This type has > less than a million members in it. So my first thought was to create a separate > group_member table just for members of this type of group. But I have to change a lot of SQL. > > The other idea I thought of is there a way to use table partitions? If the query goes > against a group of type A then it would pull from the small partition but if it is a group > of some other type it would query against the other partition. If you want to partition "group_member", the partitioning key cannot be in "group". So you would have to (redundantly) add "group.type" to "group_member". You could ensure consistency by including that column in the foreign key. If you want partition pruning to take effect, you will have to include a condition on "group_member.type" in the WHERE condition. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com