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 1spBbf-00HGh0-Ik for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2024 19:05:24 +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 1spBbf-009p4T-9P for pgsql-general@arkaria.postgresql.org; Fri, 13 Sep 2024 19:05:23 +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 1spBbe-009p31-TR for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2024 19:05:22 +0000 Received: from mail-lj1-x236.google.com ([2a00:1450:4864:20::236]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1spBba-0012AP-O3 for pgsql-general@lists.postgresql.org; Fri, 13 Sep 2024 19:05:22 +0000 Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2f752d9ab62so14696291fa.3 for ; Fri, 13 Sep 2024 12:05:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726254318; x=1726859118; 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=qCOf+WoUkkOm7Nza+ou2Dj45Ryc1g6X0DsO+A615SZo=; b=g0ehG4kdsPuncN2s5/gxtQ/KgEIpkdmltlDcOx0Q5yqq80E/7oNvwg/6AxWSHHmNiy 7BNrj4MZl8CKdR5aM0aw+j8sVomc6LRDftSs/R2lwz+248ow9WhY5N9ujqQHK0tC4DeF wUsieqVAhHxP1mdcqFn7IKDvsRiLLVejzq2kjHC/U6frM5jD3iAvwqlhlpd1jj2t888N HD25k9OxXtjzcf118s0daD38dp6oKASfEwY9Gcpaz4aa6vJadY+JKz2HVIkYNxxkZJKr 01XrJloZQhmDhEkkVq+nby7jGgggX4WEz7vDJol30lb0lA5RDN7LFZjKIZ9HNU8jpRvj R6Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726254318; x=1726859118; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qCOf+WoUkkOm7Nza+ou2Dj45Ryc1g6X0DsO+A615SZo=; b=d4N/Imu+HrEZQdYjEObxI9A7BzzO2Am1esnGWOxik7cjMzJLvSJnFbH+xyZdP5bhJB E2pfUGS1062bcnd2r8d9Qf/2kpVUcl3i1WNd4iEzwnm4lN5n+phq770h/i19hKetbWfx 7b98efRaXGS0eT8jjnRCfSGM3xthAb71TMb7GQNwdOYchLQvtPiHA06pTGbgPDZCcT9I SYgVG69kv9PomsGwmbiPr+2M2CN+X6R/rcg8RwVVGE2mmLr2hPy1n0k5gVxd0gAV1LrI pgFnh0nMHhl3NhJXVFduWVIlGQOuuyn9vDgarDqTTwY7GURcfQfNxq3omNymdhFsAGR5 vXxQ== X-Gm-Message-State: AOJu0Yy89oIyybpsxTwINn/z9rJHG9c4PCMAYOU6OMSMILQ4niDiuSjm gjhLfDbMwseWaHW8PBOAraRtY/OO+2su4IhvKK3u3gHDzsHF4o+3UndVufCmJWLkZLjGrTC9WZq PzPT6TYHU3fU4WD6kUrx+bE3fV6Q= X-Google-Smtp-Source: AGHT+IExYM0vw24lhHHSOYrjozYVWNM7SsrnBgZP/4bgtN+phTVYoUIz9F0qEGXOOZeNL8FmnxDztlMKZPoh5B6nAGc= X-Received: by 2002:a2e:be8a:0:b0:2ef:2472:300a with SMTP id 38308e7fff4ca-2f7918e0954mr23432311fa.2.1726254316688; Fri, 13 Sep 2024 12:05:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Greg Sabino Mullane Date: Fri, 13 Sep 2024 15:04:40 -0400 Message-ID: Subject: Re: Will hundred of thousands of this type of query cause Parsing issue To: "Wong, Kam Fook (TR Technology)" Cc: pgsql-general Content-Type: multipart/alternative; boundary="00000000000056a67d062204e75f" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000056a67d062204e75f Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 13, 2024 at 11:35=E2=80=AFAM Wong, Kam Fook (TR Technology) < kamfook.wong@thomsonreuters.com> wrote: > 1) Where does query parsing occur? > > Always on the server side, although your driver may do something as well. 2) Will this cause extra parsing to the posgress DB? > Yes > Any pg system table to measure parsing? > No You want to send an array of values to the same query, so it can be prepared once, like so: SELECT abc, efg FROM docloc a JOIN collection b USING (collection_name) WHERE a.column1 =3D ANY($1) AND a.stage_id =3D ( select max(stage_id) from collection_pit c where c.collection_name =3D a.collection_name and c.pid_id < $2 and c.stage_code =3D $3 ); Then you can always pass in three arguments, the first being an array of all the column1 values you want. You might also want to get familiar with plan_cache_mode: https://www.postgresql.org/docs/current/sql-prepare.html Cheers, Greg --00000000000056a67d062204e75f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Sep 13, 2024 at 11:35=E2=80=AFAM = Wong, Kam Fook (TR Technology) <kamfook.wong@thomsonreuters.com> wrote:

1) Where does query p= arsing occur?


Always on the= server side, although your driver may do something as well.

=
=

2) Will this cause extra parsing to the posgress= DB?


Yes
=
=C2=A0

=C2=A0 Any pg system table to measure= parsing?


No

You want to send an array of values to the same que= ry, so it can be prepared once, like so:

SELECT abc, efg
FROM=C2=A0docloc a
JOIN collection b US= ING (collection_name)
WHERE a.column1 =3D ANY($1)
AND a= .stage_id =3D (
=C2=A0 select max(stage_id) from collection_pit c=
=C2=A0 where c.collection_name =3D a.collection_name
= =C2=A0 and c.pid_id < $2 and c.stage_code =3D $3
);
=
Then you can always pass in three arguments, the first being= an array of all the column1 values you want.

You = might also want to get familiar with plan_cache_mode:=C2=A0https://www.postgresql= .org/docs/current/sql-prepare.html

Cheers,
Greg

--00000000000056a67d062204e75f--