pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
parallel-processing multiple similar query tasks - any example?
9+ messages / 3 participants
[nested] [flat]

* parallel-processing multiple similar query tasks - any example?
@ 2022-04-27 23:34  Shaozhong SHI <shishaozhong@gmail.com>
  0 siblings, 2 replies; 9+ messages in thread

From: Shaozhong SHI @ 2022-04-27 23:34 UTC (permalink / raw)
  To: pgsql-general <pgsql-general@lists.postgresql.org>

multiple similar query tasks are as follows:

select * from a_table where country ='UK'
select * from a_table where country='France'
and so on

How best to parallel-processing such types of multiple similar query tasks?

Any example available?

Regards,

David

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-27 23:44  David G. Johnston <david.g.johnston@gmail.com>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  1 sibling, 1 reply; 9+ messages in thread

From: David G. Johnston @ 2022-04-27 23:44 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On Wed, Apr 27, 2022 at 4:34 PM Shaozhong SHI <shishaozhong@gmail.com>
wrote:

> multiple similar query tasks are as follows:
>
> select * from a_table where country ='UK'
> select * from a_table where country='France'
> and so on
>
> How best to parallel-processing such types of multiple similar query tasks?
>
> Any example available?
>
>
You should search for how to run processes/commands in parallel in whatever
client-side execution environment you want to use.  There isn't anything
specific to PostgreSQL here.

David J.

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-28 01:18  David G. Johnston <david.g.johnston@gmail.com>
  parent: David G. Johnston <david.g.johnston@gmail.com>
  0 siblings, 0 replies; 9+ messages in thread

From: David G. Johnston @ 2022-04-28 01:18 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On Wed, Apr 27, 2022 at 4:44 PM David G. Johnston <
david.g.johnston@gmail.com> wrote:

> On Wed, Apr 27, 2022 at 4:34 PM Shaozhong SHI <shishaozhong@gmail.com>
> wrote:
>
>> multiple similar query tasks are as follows:
>>
>> select * from a_table where country ='UK'
>> select * from a_table where country='France'
>> and so on
>>
>> How best to parallel-processing such types of multiple similar query
>> tasks?
>>
>> Any example available?
>>
>>
> You should search for how to run processes/commands in parallel in
> whatever client-side execution environment you want to use.  There isn't
> anything specific to PostgreSQL here.
>
>
You should also read:

https://www.postgresql.org/docs/current/parallel-query.html

If you want to see when a single query can be executed using parallel
workers.

David J.

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-28 15:17  Alvaro Herrera <alvherre@alvh.no-ip.org>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  1 sibling, 1 reply; 9+ messages in thread

From: Alvaro Herrera @ 2022-04-28 15:17 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On 2022-Apr-28, Shaozhong SHI wrote:

> multiple similar query tasks are as follows:
> 
> select * from a_table where country ='UK'
> select * from a_table where country='France'
> and so on
> 
> How best to parallel-processing such types of multiple similar query tasks?
> 
> Any example available?

for country in UK France Germany Ireland; do
  echo "select pg_sleep(1); select * from a_table where country = '${country//\'/''/}'"
done | \
  xargs -d"\n" -P10 -n1 psql -X -c

Note the ${country/} stuff is a bash-ism.

-- 
Álvaro Herrera





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-28 15:54  Shaozhong SHI <shishaozhong@gmail.com>
  parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 1 reply; 9+ messages in thread

From: Shaozhong SHI @ 2022-04-28 15:54 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

No, No.

Why sleep(1)?

It should be all active - doing work concurrently.

Regards,

David

On Thu, 28 Apr 2022 at 16:17, Alvaro Herrera <alvherre@alvh.no-ip.org>
wrote:

> On 2022-Apr-28, Shaozhong SHI wrote:
>
> > multiple similar query tasks are as follows:
> >
> > select * from a_table where country ='UK'
> > select * from a_table where country='France'
> > and so on
> >
> > How best to parallel-processing such types of multiple similar query
> tasks?
> >
> > Any example available?
>
> for country in UK France Germany Ireland; do
>   echo "select pg_sleep(1); select * from a_table where country =
> '${country//\'/''/}'"
> done | \
>   xargs -d"\n" -P10 -n1 psql -X -c
>
> Note the ${country/} stuff is a bash-ism.
>
> --
> Álvaro Herrera
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-28 16:10  Alvaro Herrera <alvherre@alvh.no-ip.org>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Alvaro Herrera @ 2022-04-28 16:10 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On 2022-Apr-28, Shaozhong SHI wrote:

> Why sleep(1)?

It is sleeping to show that they are running concurrently.  If it runs
five sleeps of one second each and the whole command lasts one second,
then all sleeps ran in parallel.  Had the whole command taken five
seconds, you would know that the queries ran serially.

> It should be all active - doing work concurrently.

They are all active simultaneously.  You just need to supply your own
query, without any sleeps.

-- 
Álvaro Herrera





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-28 16:17  Shaozhong SHI <shishaozhong@gmail.com>
  parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 1 reply; 9+ messages in thread

From: Shaozhong SHI @ 2022-04-28 16:17 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Expand and explain please.
Regards,
David

On Thursday, 28 April 2022, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

> On 2022-Apr-28, Shaozhong SHI wrote:
>
> > Why sleep(1)?
>
> It is sleeping to show that they are running concurrently.  If it runs
> five sleeps of one second each and the whole command lasts one second,
> then all sleeps ran in parallel.  Had the whole command taken five
> seconds, you would know that the queries ran serially.
>
> > It should be all active - doing work concurrently.
>
> They are all active simultaneously.  You just need to supply your own
> query, without any sleeps.
>
> --
> Álvaro Herrera
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-28 16:20  Alvaro Herrera <alvherre@alvh.no-ip.org>
  parent: Shaozhong SHI <shishaozhong@gmail.com>
  0 siblings, 1 reply; 9+ messages in thread

From: Alvaro Herrera @ 2022-04-28 16:20 UTC (permalink / raw)
  To: Shaozhong SHI <shishaozhong@gmail.com>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

On 2022-Apr-28, Shaozhong SHI wrote:

> Expand and explain please.

No, thanks.

-- 
Álvaro Herrera





^ permalink  raw  reply  [nested|flat] 9+ messages in thread

* Re: parallel-processing multiple similar query tasks - any example?
@ 2022-04-28 16:26  Shaozhong SHI <shishaozhong@gmail.com>
  parent: Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 0 replies; 9+ messages in thread

From: Shaozhong SHI @ 2022-04-28 16:26 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-general <pgsql-general@lists.postgresql.org>

Well, I guess that does not work.
Never mind.

Regards,
David


On Thursday, 28 April 2022, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:

> On 2022-Apr-28, Shaozhong SHI wrote:
>
> > Expand and explain please.
>
> No, thanks.
>
> --
> Álvaro Herrera
>

^ permalink  raw  reply  [nested|flat] 9+ messages in thread


end of thread, other threads:[~2022-04-28 16:26 UTC | newest]

Thread overview: 9+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 23:34 parallel-processing multiple similar query tasks - any example? Shaozhong SHI <shishaozhong@gmail.com>
2022-04-27 23:44 ` David G. Johnston <david.g.johnston@gmail.com>
2022-04-28 01:18   ` David G. Johnston <david.g.johnston@gmail.com>
2022-04-28 15:17 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-04-28 15:54   ` Shaozhong SHI <shishaozhong@gmail.com>
2022-04-28 16:10     ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-04-28 16:17       ` Shaozhong SHI <shishaozhong@gmail.com>
2022-04-28 16:20         ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2022-04-28 16:26           ` Shaozhong SHI <shishaozhong@gmail.com>

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