agora inbox for pgsql-admin@postgresql.org  
help / color / mirror / Atom feed
From: shammat@gmx.net
To: pgsql-admin@lists.postgresql.org
Subject: Re: fast way to run a query with 7 thousand constant values
Date: Sat, 1 Mar 2025 20:20:59 +0100
Message-ID: <af3bdbaf-3c88-48da-bf25-141cb88b8cd2@gmx.net> (raw)
In-Reply-To: <6f8ec837-86ad-43e0-9416-d0a86009e28c@quadratum-braccas.com>
References: <6f8ec837-86ad-43e0-9416-d0a86009e28c@quadratum-braccas.com>

Am 01.03.25 um 19:23 schrieb Sbob:
> I have a client that wants to pass in as an IN clause a list of
> 7,000 values. The value set changes for each query and it ranges
> from 5,000 to 8,000 values.
>
> The planning time is too long for the requirements. (250 - 300ms)
>
> I got it to work in 50ms end to end by creating a temp table and
> doing a copy from STDIN into the temp table
>
> However this is a Java based app and getting it to do a copy is
> becoming way more complex than it should be.
>
> Anyone know of an alternate way to run a query where an id is one of
> X values where X is a list of 5 - 8 thousand values that will not
> force the planner to spend 200+ms prepping the plan?

Use "where the_column = any(?)" and pass all the values as a single parameter
of type java.sql.Array using a PreparedStatement.







view thread (3+ messages)

Message-ID: <af3bdbaf-3c88-48da-bf25-141cb88b8cd2@gmx.net>
Permalink:  ../af3bdbaf-3c88-48da-bf25-141cb88b8cd2@gmx.net/
Also on:    postgresql.org/message-id/af3bdbaf-3c88-48da-bf25-141cb88b8cd2@gmx.net

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: shammat@gmx.net, pgsql-admin@lists.postgresql.org
  Subject: Re: fast way to run a query with 7 thousand constant values
  In-Reply-To: <af3bdbaf-3c88-48da-bf25-141cb88b8cd2@gmx.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox