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 1tk7nd-000Gdn-4Z for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2025 20:33:05 +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 1tk7nb-002vvA-Bd for pgsql-general@arkaria.postgresql.org; Mon, 17 Feb 2025 20:33:03 +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 1tk7nb-002vv1-0I for pgsql-general@lists.postgresql.org; Mon, 17 Feb 2025 20:33:03 +0000 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tk7nY-001Q9Q-2l for pgsql-general@postgresql.org; Mon, 17 Feb 2025 20:33:02 +0000 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-2b8f09669bdso1281388fac.0 for ; Mon, 17 Feb 2025 12:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1739824379; x=1740429179; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=aLTx/E8HaGBieLSU7j4XM0UMw/mt70dNJ13+01yMFCI=; b=PHnKv/2tWctoPzADhBhVgwJPmvUFAP83p0/XdFnrXB224RYmJzyk8T/Thf8WdZD9bo /R4cWoDMC2/jCVIIJKLlYPjdW+DZqRmDddq6KzIdhBFD/2X5T0TuMWqrym/riRy+XecY rv9bfhtAPniNY9QRQD07xCsX9yHv/iSE0ARf5VVcLxlbZyFVFr8NgPZy1GbOaoEbGECp MDypsdObR6P81v82sxobPuUwPVQEv3YBZduu1zTEM6TLbtVmOeTEwkvq2dqSgylap/sY IZj21/xioF20ZIyXMkp8xsF6N/KVs0wGzTHuglFMOIqWgmx5sk3SvHu2HhxtmXdY6i0i 4U7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739824379; x=1740429179; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aLTx/E8HaGBieLSU7j4XM0UMw/mt70dNJ13+01yMFCI=; b=s/7DwHIRCEoDQc+g+Wd/Ggi2VPlE0xdDtMcNQm5tneLf7vyIVuugg629cWEKl9L9QV i+KJzaQZCC/DWL6khWWbHQDWOXGhX6VdPx+bD1Tr8wsyWPXjS0GO2XpDT/+hF9MJDOLt aKrJ3cj6CcrhvdF7rr3kkpoQAzv2xTjP52Pl0p0iAsj3Zc3uCpOL4PT54tGh+hZTmq4E FlFFU9sBnSNUeGt/d/a11fqOFPo129+c/2ZJBPzl2iOjLQc9gY2zG8mNaYY/SQ26f1qs 9N29ZiD6a1utmIfz7vmGyqEDUr0nyI7dpxqrG4nhiaU71yGMj4Z8FdQbATlF8tYldJRO 2+6w== X-Gm-Message-State: AOJu0YzE9M14sSctxJMfaQywuEy9VD8EfqD/zqLLO0n0ZHMhLuP4+URP QCwEURvnXI1JfmrEvNKF6KsOAPER7mFi1W9v9THa0XA92SPBPiMpoGaLPUyO/ECLLP9bKNe9EkL y0uuDLmWhIxgop6HRvuCTe3jQj206kiMR X-Gm-Gg: ASbGncv8fUsjXAutd9qgXTSx4+ccpquRX+jRQbtb+BrSuqWVvqW55upyZ+DnewjS7wG 8oxwHHwxeW27Hc1XpZ1fKNXZxyMSQS6+V00aOU6hi9vw967WNIjxfZN+SjGObDm+psOhHsVxd6w == X-Google-Smtp-Source: AGHT+IFlVnTTlsEpw3YxeMihlVt7vI1F46cIBJLA6rZruAx+B54P5X/1hsQk8CsQFPD8u2LGTa+FMFQnm0oUHuCVQfQ= X-Received: by 2002:a05:6871:4b88:b0:2bb:15b1:55b4 with SMTP id 586e51a60fabf-2bc99d673demr6517869fac.31.1739824378755; Mon, 17 Feb 2025 12:32:58 -0800 (PST) MIME-Version: 1.0 From: Ron Johnson Date: Mon, 17 Feb 2025 15:32:47 -0500 X-Gm-Features: AWEUYZmrWYs73EIgo9FrrVsacGUdd26566rbt_gvWgsMvkyXZt9nuJmbDm7NVr0 Message-ID: Subject: Loading the latest N rows into the cache seems way too fast. To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000114180062e5c6e15" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000114180062e5c6e15 Content-Type: text/plain; charset="UTF-8" PG 9.6.24 and PG 14.15, if it matters. (Yes, 9.6 is really EOL. I don't control that.) (I could use pg_prewarm, but the table is much bigger than RAM, and last_block value only has the newest record if data has never been deleted. The oldest records regularly get deleted, and then the table is vacuumed; thus, new records can be anywhere in the table.) Thus, roll my own cache-loading statement. The bigint "id" column in "mytbl" is populated from a sequence, and so is monotonically increasing: the newest records will have the biggest id values. The table also has a bytea column that averages about 100KB. Loading 200K rows is more than 200MB. I expected this "prewarm" statement to take much longer than 1/2 second. Am I still in the dark ages of computer speed, or is this statement not doing what I hope it's doing? $ time psql -h foo bar -Xc "DO \$\$ BEGIN PERFORM * FROM mytbl ORDER BY id DESC LIMIT 200000 ; END \$\$;" DO real 0m0.457s user 0m0.005s sys 0m0.004s -- Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --000000000000114180062e5c6e15 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
PG 9.6.24 and PG 14.15, if it matters.
(Yes= , 9.6 is really EOL.=C2=A0 I don't control that.)

<= div>(I could use pg_prewarm, but the table is much=C2=A0bigger than RAM, an= d last_block value only has the newest record if data has never been delete= d.=C2=A0 The oldest records regularly get deleted, and then the table is va= cuumed; thus, new records can be anywhere in the table.)

Thus, roll my own cache-loading statement.

= The bigint "id" column in "mytbl" is populated from a s= equence, and so is monotonically increasing: the newest records will have t= he biggest id values.
The table also has a bytea column that aver= ages about 100KB.

Loading 200K rows is more than 2= 00MB.=C2=A0 I expected this "prewarm" statement to take much long= er than 1/2 second.=C2=A0 Am I still in the dark ages of computer speed, or= is this statement not doing what I hope it's doing?

$ time psql -h foo bar -Xc "DO \$\$ BEGIN PERFORM * FROM mytbl = ORDER BY id DESC LIMIT 200000 ; END \$\$;"
DO

real =C2=A0 = =C2=A00m0.457s
user =C2=A0 =C2=A00m0.005s
sys =C2=A0 =C2=A0 0m0.004s<= /div>

--
Death to <Redacted>, and butter sauce.
Don'= t boil me, I'm still alive.
<Redacted> lobster!
--000000000000114180062e5c6e15--