Re: Fetching multiple rows in single round trip

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Fetching multiple rows in single round trip
Дата
Msg-id E6AFE68A-FF40-4348-A061-4942DEA79CEF@yahoo.com
обсуждение исходный текст
Ответ на Fetching multiple rows in single round trip  (Jon Smark <jon.smark@yahoo.com>)
Ответы Re: Fetching multiple rows in single round trip  (Jon Smark <jon.smark@yahoo.com>)
Список pgsql-general
On May 18, 2012, at 13:46, Jon Smark <jon.smark@yahoo.com> wrote:

> Dear postgresql-general,
>
> What would be the best way to fetch in a single round trip a set of table rows?
> To clarify, suppose I have a 'widgets' table with columns 'wid' and 'data',
> and I wish to retrieve all rows that belong to the client side array $targets.
> Obviously one solution would be to loop on the client-side, with each iteration
> fetching one row.  This however entails many round trips in the client <->
> postmaster communication, which is undesirable for performance reasons.
> Therefore, I would rather tell the PostgreSQL server to give me all rows
> whose wid belongs in a given set.
>
> I can think of two solutions:
>
> 1) "SELECT wid, data FROM widgets WHERE wid IN $targets"
> 2) "SELECT wid, data FROM widgets WHERE ARRAY [wid] <@ $targets"
>
> Is there another (better) approach I'm missing?  Also, is there any significant
> performance difference for PostgreSQL between solutions 1 and 2? (Solution
> 1 seems more efficient, though solution 2 is actually a better fit for the
> client-side bindings I'm using).
>
> Thanks in advance!
> Jon
>
>

...WHERE wid = ANY(string_to_array(?,';'))

where the ? is a parameter that you replace with a semi-colon delimited listing of widget IDs

Performance depends on specifics you have not provided, especially the expected number of widgets you are going to be
filteringone. 

David J.




В списке pgsql-general по дате отправления:

Предыдущее
От: Steve Crawford
Дата:
Сообщение: Re: odd intermittent query hanging issue
Следующее
От: "J.V."
Дата:
Сообщение: varchar for loops possible?