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 1q6AYl-0001B8-Uf for pgsql-novice@arkaria.postgresql.org; Mon, 05 Jun 2023 13:47:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1q6AYk-0000vC-HO for pgsql-novice@arkaria.postgresql.org; Mon, 05 Jun 2023 13:47:46 +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 1q6AYk-0000rX-81 for pgsql-novice@lists.postgresql.org; Mon, 05 Jun 2023 13:47:46 +0000 Received: from sender11-op-o11.zoho.eu ([31.186.226.225]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q6AYg-000LnP-KL for pgsql-novice@lists.postgresql.org; Mon, 05 Jun 2023 13:47:44 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1685972856; cv=none; d=zohomail.eu; s=zohoarc; b=YC/AE05Zpqqi5g+nL/yJIRS6+EiXfZptIg9QszPa7IhsIp8G12xKFn7zCoHOaeCcg1cTF2EHcfBW47WnZ/q2BPZgVML1pFimmB7c4yD7qRVYKdDufUm08483WUBK29Uj9A/p5xXtnwjwSvQ4CgN8iRYjhC4LutfrR/PfIqN3GbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1685972856; h=Content-Type:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=H3wYkyJGoUnEPzBO+tDKt4sN6taAGSpyMXlyqyzfL+Q=; b=Km17vdsandW/FashOdFnH/96hWSOaEweBGguEGMs9UC+1mv+WrrPvbRaELOked1Qp3h4c1V1PxDlUfvaXiMzK+rC24x/g7OWxxxuZVzN7XBygQuu0iy3WUHjt7KHrJ50Qu+uwJT1wMJR6lmvpsLNBCKpp6rCjSOjOoLy3T/+8+U= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=trallnag.com; spf=pass smtp.mailfrom=tim@trallnag.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1685972856; s=zmail; d=trallnag.com; i=tim@trallnag.com; h=Date:Date:From:From:To:To:Cc:Cc:Message-Id:Message-Id:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Reply-To; bh=H3wYkyJGoUnEPzBO+tDKt4sN6taAGSpyMXlyqyzfL+Q=; b=DbWs/bEu23dF4RfuvEOuOBaMbq9VG/7Q8UIA0TomMlxNQgG6TpS3M25KIScZNtw7 qnkZx78fWn0wEfvPrVZGMXfc/q5joN/DNi0/w1LI1pmwaZ27V3h2OoCndd5+jzTWqSK ETD8oDjrxLzqADrhJR5a2mtFj8ht/jiRwREDmzrw= Received: from mail.zoho.eu by mx.zoho.eu with SMTP id 1685972854889845.9389912871933; Mon, 5 Jun 2023 15:47:34 +0200 (CEST) Date: Mon, 05 Jun 2023 15:47:34 +0200 From: Tim Schwenke To: "David G. Johnston" Cc: "Pgsql Novice" Message-Id: <1888bd0285f.c47bd298692167.399116048841887836@trallnag.com> In-Reply-To: <1888bb46d75.c27dbb7f688001.5044215935079224344@trallnag.com> References: <1888b7bb7fa.112313046679561.2788161417267896332@trallnag.com> <1888bb46d75.c27dbb7f688001.5044215935079224344@trallnag.com> Subject: Re: Does PostgreSQL cache all columns of a table after SELECT? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_1996878_1350139321.1685972854879" Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------=_Part_1996878_1350139321.1685972854879 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello, I just tested it and it indeed works this way. 1. Created new table with only relevant columns. 2. Stopped PostgreSQL DB. 3. Dropped page cache. 4. Started again. 5. Run query against new table 6. Way less cache used, query is faster, less data is being read into cache= . ---- On Mon, 05 Jun 2023 15:17:17 +0200 Tim Schwenke wro= te --- Hello David,=20 =20 from what I understand, in PostgreSQL, tables are stored in one or more fil= es called segments. There is no separation by columns.=20 =20 https://www.postgresql.org/docs/8.1/storage.html=20 =20 This means if I select a single column from a table the first time, the ful= l file / segment is read and put into page cache if there is enough space. = This means a table with only one large column large_a takes up less page ca= che compared to a table with many large columns large_a and large_b, even t= hough in both cases only large_a is selected.=20 =20 Is that more or less correct? Ignoring toast?=20 =20 Tim S.=20 =20 ---- On Mon, 05 Jun 2023 14:58:21 +0200 David G. Johnston wrote ---=20 =20 >=20 >=20 > On Monday, June 5, 2023, Tim Schwenke mailto:tim@trallnag.com> wrote:=20 >=20 >=20 > Does the cache also contain large_b? Or is only large_a cached? Assumpti= on is that memory is large enough to fit everything.=20 >=20 >=20 > Shared buffers is a page cache.=20 >=20 > David J.=C2=A0=20 > ------=_Part_1996878_1350139321.1685972854879 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable =
Hello,

I just tested = it and it indeed works this way.

1. Created ne= w table with only relevant columns.
2. Stopped PostgreSQL DB.=
3. Dropped page cache.
4. Started again.
5. Run query against new table
6. Way less cache use= d, query is faster, less data is being read into cache.

<= /div>


---- On Mon, 05 Jun 2023 15:17:17= +0200 Tim Schwenke <tim@trallnag.com> wrote ---

= Hello David,

from what I understand, in PostgreSQL, tables are sto= red in one or more files called segments. There is no separation by columns= .

https://www.postgresql.org/docs/8.1/storage.html
This means if I select a single column from a table the first time, the f= ull file / segment is read and put into page cache if there is enough space= . This means a table with only one large column large_a takes up less page = cache compared to a table with many large columns large_a and large_b, even= though in both cases only large_a is selected.

Is that more or le= ss correct? Ignoring toast?

Tim S.

---- On Mon, 05 Jun 20= 23 14:58:21 +0200 David G. Johnston wrote ---

>
> > On Monday, June 5, 2023, Tim Schwenke tim@trallnag.com> wrote:
>
>=
> Does the cache also contain large_b? Or is only large_a cached? = Assumption is that memory is large enough to fit everything.
>
= >
> Shared buffers is a page cache.
>
> David J= . 
>


------=_Part_1996878_1350139321.1685972854879--