Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvwSL-008hoa-An for pgsql-general@arkaria.postgresql.org; Thu, 26 Oct 2023 09:15:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qvwSJ-00F1ku-TC for pgsql-general@arkaria.postgresql.org; Thu, 26 Oct 2023 09:15:07 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvwSJ-00F1kl-Hh for pgsql-general@lists.postgresql.org; Thu, 26 Oct 2023 09:15:07 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qvwSE-002toa-Qm for pgsql-general@lists.postgresql.org; Thu, 26 Oct 2023 09:15:06 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id F12B68E43; Thu, 26 Oct 2023 11:15:00 +0200 (CEST) Date: Thu, 26 Oct 2023 11:15:00 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Very newbie question Message-ID: <20231026091500.5g5iwjadoljcxbot@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <50F00665-2AB4-409C-9445-5E32482C0FA4@ya.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="enp7jf4xcnoo7wry" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --enp7jf4xcnoo7wry Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2023-10-25 17:48:46 +0200, Olivier Gautherot wrote: > El mi=C3=A9, 25 oct 2023 16:58, =D0=9E=D0=BB=D0=B5=D0=B3 =D0=A1=D0=B0=D0= =BC=D0=BE=D0=B9=D0=BB=D0=BE=D0=B2 escribi=C3=B3: > Okey, I see no one was be able to solve this problem. But I could. Ma= y be > for someone this will be useful too. There is solution. [...] > Now query is: >=20 > SELECT generate_series(min(id)/10000000, max(id)/10000000) AS n FROM > delivery) as part_numbers > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0WHERE (SELECT max(created_at) from = delivery where n*10000000 <=3Did > and id < (n+1)*10000000) > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 < CURRENT_DATE-'3 month'::i= nterval; >=20 > Return the same (number of partition need to archive), accelerated by= two > btree index: on id and created_at. Works very quick, less then second. [...] > Your fast solution will work as long as you don't have missing sequences = (like > deleted rows). Why do you think this would break with missing sequence numbers? hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --enp7jf4xcnoo7wry Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmU6LhAACgkQ8g5IURL+ KF15kw//aK3amr06U4/NIlHRvbi6d2NRfqCHQmGM0BufRj3gy7WuwJYcm9CnUaIs IQthWtcxibwpR2VFrquLylkCTg6Lm4PEbvjoWYS4xaqKhmYTwXwSfNmf3oHOCa2i vyhPPaw0ZvT7+bUQMP5RaA0P6kmavhjfw+L9HGuQEZCaLzLDlERzlt5Np3B8nIMK mbZY+SQV4KOgJ+ROTU1EQ9EuIqr7J1vrlXtR8wulfcdO+0EWT+jP64da/y8Hp2TR ZAxHU8QZCns7AF8NEeKa9R4VwNXy60tT/G86Mh1oc7W/r8VyRm+Vh6vnI6brxkw+ /10yVaTfrWWoiGK7/hymVhFbRIFYDZbKTjm8GtY4uSiWBhQDh3Z67gs3qQ8Dq3cR q9Fg8gFTmTGpdXke6+kqn8B8mLg4jBogfskczeUa4bztLM1JH9AEoZ6guozYwPI5 uYGUXHuKjCwjCbtrvHgQhoDi+lLeZkDKXAVoP2nWNfaiieWR0IpnSyu/BCC4jm1u 7PicjR7OmciPeqM1apqLuCIIM8sUByqrIJNtb8i2MtWqGVCZVca65ecufQ+QghHQ sgW3SDOVYHLgOP6Gq48x8duBxjdsKaDSA2slh472f3RumU/g2Qc+jSrwGJZhuL+w /2ui8ZwYQ+RXJ71Hw3fxkmFV2FxGuoagZU+17mhHs7hth4llju8= =qC9R -----END PGP SIGNATURE----- --enp7jf4xcnoo7wry--