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 1lOLjS-0007Bk-Rp for pgsql-general@arkaria.postgresql.org; Mon, 22 Mar 2021 14:40:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lOLjR-0007Fs-QJ for pgsql-general@arkaria.postgresql.org; Mon, 22 Mar 2021 14:40:37 +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 1lOLjR-0007Fl-6s for pgsql-general@lists.postgresql.org; Mon, 22 Mar 2021 14:40:37 +0000 Received: from srvimsva2.dst.dk ([91.208.143.64]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lOLjP-0001sQ-1O for pgsql-general@lists.postgresql.org; Mon, 22 Mar 2021 14:40:36 +0000 Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1E05104075 for ; Mon, 22 Mar 2021 15:40:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=dst.dk; s=dmz20180119; t=1616424032; bh=TcrlNWhNnlWXztZJWH6lod03w+vPuPykYM7KepbZua0=; h=From:To:Date; b=hhLy8KVF181WZCD0rh31Mnd2atkFvNukQ4IfCr+4TQhEopBv+kiey6T6DKjHplJpk lJcZwQiep9XBy6fNVZXS1VWUjB3czYVvJCgXfDOczR2ZFfTp2f1g6s6zwFr5K3/8Xe z/gsSW+/gRlKcOxpkaEuZRISqCGVGTcWTa1UuM9w= Received: from srvimsva2.dst.dk (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9CC31104074 for ; Mon, 22 Mar 2021 15:40:32 +0100 (CET) Received: from Sepo.dst.dk (unknown [192.168.64.12]) by srvimsva2.dst.dk (Postfix) with ESMTP for ; Mon, 22 Mar 2021 15:40:32 +0100 (CET) Received: from srvexc8.dst.local ([172.30.32.48]) by Sepo.dst.dk (JAMES SMTP Server 2.3.2-1) with SMTP ID 402 for ; Mon, 22 Mar 2021 15:40:32 +0100 (CET) Received: from srvexc8.dst.local (172.30.32.48) by srvexc8.dst.local (172.30.32.48) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2106.2; Mon, 22 Mar 2021 15:40:32 +0100 Received: from srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b]) by srvexc8.dst.local ([fe80::9df8:5de5:1bf2:8b3b%2]) with mapi id 15.01.2106.013; Mon, 22 Mar 2021 15:40:32 +0100 From: Niels Jespersen To: "pgsql-general@lists.postgresql.org" Subject: design partioning scheme for selecting from latest partition Thread-Topic: design partioning scheme for selecting from latest partition Thread-Index: AdcfKHhRukZSyaRZTAGz88Q+HWqijw== Date: Mon, 22 Mar 2021 14:40:32 +0000 Message-ID: <5de5c8b614544d7ba782b15ffb12e5da@dst.dk> Accept-Language: da-DK, en-US Content-Language: da-DK X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.30.33.38] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-TM-AS-GCONF: 00 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hello I have a table partitioned like this drop table if exists s cascade; create table s ( version int not null, a int, b int ) partition by list (version); -- Add tens of partitions -- Load millions of rows in each partition -- Then I want to be able to do this wothout scanning all partitions for th= e highest version number.=20 select s.* from s where s.version =3D (select max(version) from s); I could add an index on the version column. But the only use would be to th= e newest partition, so that seems a bit like overkill, indexing 100 of mill= iomns of rows. =20 Is there another way to do this in a cheaper way.=20 For now I have created a materialized view based on the select above, thus = only scanning for max partition only once.=20 Niels Jespersen