trouble converting several serial queries into a parallel query - Mailing list pgsql-general

From Jonathan Vanasco
Subject trouble converting several serial queries into a parallel query
Date
Msg-id FE3E351A-04EF-4777-B248-A29425D290AC@2xlp.com
Whole thread Raw
Responses Re: trouble converting several serial queries into a parallel query
List pgsql-general
I have a very simple query that is giving me some issues due to the size of the database and the number of requests I
maketo it in order to compile the report I need: 

A dumbed down version of the table and query:

    CREATE TABLE a_to_b (
        id_a INT NOT NULL REFERENCES table_a(id),
        id_b INT NOT NULL REFERENCES table_b(id),
        PRIMARY KEY (id_a, id_b)
    );
    SELECT id_a, id_b FROM a_2_b WHERE id_a = 1 LIMIT 5;

The problem is that the table has a few million records and I need to query it 30+ times in a row.

I'd like to improve this with a parallel search using `IN()`

    SELECT id_a, id_b FROM a_2_b WHERE id_a = IN
(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26.27,28,29,30);

That technique has generally fixed a lot of bottlenecks for us.

However I can't wrap my head around structuring it so that I can apply a limit based on the column -- so that I only
get5 records per id_a. 

The table has columns that I would use for ordering in the future, but I'm fine with just getting random values right
now. 

Can anyone offer some suggestions?  Thanks in advance.

pgsql-general by date:

Previous
From: "Joshua D. Drake"
Date:
Subject: Re: could not fork new process for connection: Resource temporarily unavailable
Next
From: Filipe Pina
Date:
Subject: Re: database-level lockdown