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.96) (envelope-from ) id 1vnLTz-005V4U-1V for pgsql-general@arkaria.postgresql.org; Tue, 03 Feb 2026 18:50:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vnLTy-006rWK-0A for pgsql-general@arkaria.postgresql.org; Tue, 03 Feb 2026 18:50:37 +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.96) (envelope-from ) id 1vnLTx-006rWB-22 for pgsql-general@lists.postgresql.org; Tue, 03 Feb 2026 18:50:37 +0000 Received: from mail-ed1-x534.google.com ([2a00:1450:4864:20::534]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vnLTu-00000000trB-3z4K for pgsql-general@lists.postgresql.org; Tue, 03 Feb 2026 18:50:37 +0000 Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-653780e9eb3so8207695a12.1 for ; Tue, 03 Feb 2026 10:50:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1770144633; cv=none; d=google.com; s=arc-20240605; b=JRtlfw5G5XW4ZwsSAIv7nyNRWLhiUQGNBfj2EPQFrcX97VlmwjKbWgWLToWYbbFmOG eSf3T1esOvyosuHzxMy2cD6dB9xdBXDaxGl8ZD5Cto+uHb6UNsPSGax/Au06CSdlAR73 6VrrYrvvtw+eP8apYfbfxF+mGd9fWPwowY0pwVYKBJWSQNf+ihBKISxrVlmDfANrExMP 4lnWCfgYh5zR8u0blcYYMgHZbJC9CkMITnZRYYOFqWrBTGm4PLIUBBZNgUB2+ytDVAeX mKF260DPqawTXxMz20ha0rcSGjVsZvuGzVsy3MJ2y5EdMG2h3vKXeqpl6sysVRZyYS0z Y1TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=WOYpewVx3Fj3whv+X9h1klIqQ5Q+PmS8wVT6p+WUiK4=; fh=8hZSVWtiOOU6RqByweItlXFqPjph1vawDPUKDI9ljZ8=; b=P29WWzbgXZbN6Ll3sU9WTB6BPuojVssTwlnapOnn4z4FwnCeMcCEtM8f/wjD3X3RWW EtymKqGw7ZfRkigmbD+ymNaLCzE5i1TnNmOvq28qFsK1a4ye/8QHCe2+LDjaKop6hz6B xDTJTRFTa7oN+hpfTtQqZpDSDgxLnlKv7lveVA9EmiabPKUneBqjAJFYpnQClLMY7jUe u72+z9DcHDBWZAzVx1oy2K2S6Mn2uXRM2/njBNNPx9PrHnrDkHaPhpNoeF0zdJnO7wxD 7fozgLlbvXrdArRzFT1LOUv2QGL21X3SnbnKo74rHRblf1yQl65u2XCrCF2uAFnmK6ef KWxw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770144633; x=1770749433; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=WOYpewVx3Fj3whv+X9h1klIqQ5Q+PmS8wVT6p+WUiK4=; b=TaW9zlIxAejB/yfvVX+kERJ9rftMyYdHLjZHRIofhApBglw9nQchK+PhFF1Q/8+RNf PQrWIt+O2lx2GN0HWRGt4doGyie57XK3smvZFMWgCXs6T8GrJ8ripHJHG1jEuQe7QARY gdQuf4G7KuYbXBSiGLBMuMofISVbAVvVnb/COOkwgiPa4D32hUNI0TBzBth/ilV1zsGz csj3ceNVxvWw81Qo56x6kjQ3h+hq/RHt6s3kNI40mADHD/N76UtDH2b75x77sfqzCjsj Byv+VjqobL1LlLtlBys2wvAHvdZiUG9yeaoikb2dEBG59cR2pKXBZQ7q+gatNDPjvKS3 kc/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770144633; x=1770749433; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WOYpewVx3Fj3whv+X9h1klIqQ5Q+PmS8wVT6p+WUiK4=; b=PJ7DjPEpu27/YhFyjGCh8s0XTvz4/OthAMQ4WLDcIcD3O0q8fuiegeUYfiVicFv2yb wqdgIs5MZaeQeLtPtP1bDr3CHy0nV0owBh01Cb5z1urWYLucpSg1+0oMS09kwBDzxwoi cKgeS3++a5cKkmc4O3ahwJ7UsWF7mQwV8r5VhmcgM9cghyJkiDOf9525Kpjm+tb71zHF Jua0xqIh2Jw6TtmCW3nlns8IrW+YjiZXMYzSLNV2mLXz+Mc3dP2s2GEHTL5yf76tIbUT m6lQ7qSPcTc9e7fxVup0RZyRFeorVzRGtzb5AlKd6i4FtaRsI3y5Cub8t2l/JdKUCY7L JEPQ== X-Forwarded-Encrypted: i=1; AJvYcCWIv2npse1TgJ6/Gm/dasJtchp72c8nKwMlm3fPjJnHcahZyQ8RyxUzPKpFZfyX/byGqJKQRyusw3WFNM8K@lists.postgresql.org X-Gm-Message-State: AOJu0Yyxza8thC1xJRBa8bPUSSrs9mBDXWcIDQ8DzCYvKokdD31JYLp2 +6Hz6lRoDD/RmHvGuaXMRqHKt52YSbs7uHQpqJpjIxSUI1eEHUXKlnhUBp3qzKF2Z4aNgi1HziH LmDmkTuvnfjclU+cpfLX1Oc1woig2oes= X-Gm-Gg: AZuq6aLlNprLmuPTO+K8xJw1Jwfroha9mfx8Z1/y2y1KYVugJbhm35guTnGJzMYMbo7 LHRhujTSlEM9D/6L91tTBFkegWFUwSM5XMN0z0RNEgPQq+6mVXZ6ZDXn0e6PDrn1mKqz+ThT+Yd Ed7N35rbymsdWN4N78iZDk+qeN4Ek1JD5DurO7OKuTDuXlSNKC5wFHHdzm6ZCi8wum8MFI9C20F AbDlAtXGV2zbkqWYl4oPg+Tcijnth0t389r0dlJgHmCzWpU1hKTAntcKyc5AoHex9OLalbSksJP Z+44PnbkCJm9 X-Received: by 2002:a05:6402:5242:b0:659:36de:6d20 with SMTP id 4fb4d7f45d1cf-65949abf082mr411512a12.14.1770144633185; Tue, 03 Feb 2026 10:50:33 -0800 (PST) MIME-Version: 1.0 References: <55d333e9-5172-4ece-9723-a64d6137acee@aklaver.com> In-Reply-To: <55d333e9-5172-4ece-9723-a64d6137acee@aklaver.com> From: yudhi s Date: Wed, 4 Feb 2026 00:20:20 +0530 X-Gm-Features: AZwV_QhVR7TKKgwAYQX_XGWb8-w87tV35dWPw6c_oRfIGN9Yr2DrYUVC2C7Rg9U Message-ID: Subject: Re: Top -N Query performance issue and high CPU usage To: Adrian Klaver Cc: Ron Johnson , "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000000feb250649efea68" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000000feb250649efea68 Content-Type: text/plain; charset="UTF-8" On Tue, 3 Feb, 2026, 9:37 pm Adrian Klaver, wrote: > On 2/3/26 07:59, Ron Johnson wrote: > > > > > > > There is no VARCHAR or CHAR; there is only TEXT. Thus, this is 100% > > expected and normal. > > What Ron is saying is that there are varchar and char types, but they > boil down to text per: > > https://www.postgresql.org/docs/current/datatype-character.html > > "text is PostgreSQL's native string data type, in that most built-in > functions operating on strings are declared to take or return text not > character varying. For many purposes, character varying acts as though > it were a domain over text." > > As to performance see: > > " > Tip > > There is no performance difference among these three types, apart from > increased storage space when using the blank-padded type, and a few > extra CPU cycles to check the length when storing into a > length-constrained column. While character(n) has performance advantages > in some other database systems, there is no such advantage in > PostgreSQL; in fact character(n) is usually the slowest of the three > because of its additional storage costs. In most situations text or > character varying should be used instead. > " > Thank you. I was looking into those casting(::text) in the explain plan output in similar way (as it was happening for int8 to numeric join scenario) and was thinking, may be it's spending some cpu cycles on doing these ::text casting behind the scenes for that column and if there is someway(data type change) to stop those. But from your explanation, it looks like those representation in the query plan is normal and have no performance overhead as such. Thanks again. In regards to the below, "nested loop" having response time of 100ms. I understand, here the casting function us now removed after changing the data type of columns to match in both side of the join. So, is this expected to do a nested loop on 500k rows to take 100ms? -> Nested Loop (cost=262.77..1342550.91 rows=579149 width=20) (*actual time=6.406..107.946* rows=1049 loops=1) Join Filter: (*df.ent_id = m.ent_id*) Rows Removed by Join Filter: 514648 Buffers: shared hit=1972 Regards Yudhi --0000000000000feb250649efea68 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Tue, 3 Feb, 2026, 9:37 pm Adrian Klaver, <adrian.klaver@aklaver.com> wrote:
On 2/3/26 07:59, Ron Johnson wrote:

>
>
> There is no VARCHAR or CHAR; there is only TEXT.=C2=A0 Thus, this is 1= 00%
> expected and normal.

What Ron is saying is that there are varchar and char types, but they
boil down to text per:

https://www.pos= tgresql.org/docs/current/datatype-character.html

"text is PostgreSQL's native string data type, in that most built-= in
functions operating on strings are declared to take or return text not
character varying. For many purposes, character varying acts as though
it were a domain over text."

As to performance see:

"
Tip

There is no performance difference among these three types, apart from
increased storage space when using the blank-padded type, and a few
extra CPU cycles to check the length when storing into a
length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in
PostgreSQL; in fact character(n) is usually the slowest of the three
because of its additional storage costs. In most situations text or
character varying should be used instead.
"

Thank you. I was looking into those casting(::text) in the explain pl= an output in similar way (as it was happening for int8 to numeric join scen= ario) and was thinking, may be it's spending some cpu cycles on doing t= hese ::text casting behind the scenes for that column and if there is somew= ay(data type change) to stop those. But from your explanation, it looks lik= e those representation in the query plan is normal and have no performance = overhead as such. Thanks again.=C2=A0

In regards to the below, "nested loop" having respo= nse time of 100ms. I understand, here the casting function us now removed a= fter changing the data type of columns to match in both side of the join.

So, is this expected to d= o a nested loop on 500k rows to take 100ms?

-> =C2=A0Nested Loop =C2=A0(cost=3D262.77..1342550.91 rows= =3D579149 width=3D20) (actual time=3D6.406..107.946=C2=A0rows=3D1049 loops=3D1)
=C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Join Filter: (df.ent_id =3D m.ent_id)

=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 Rows Removed by Join Filter: 514648
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 Buffers: shared hit=3D1972

Regards
Yudhi<= /div>



--0000000000000feb250649efea68--