PQresultMemorySize of ResultSet larger than expected

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: PQresultMemorySize of ResultSet larger than expected
Date: 2022-03-10 14:09:58
Message-ID: CAFCRh--zw3aZbJVKsRUqJGfPCjkGtcJ2_AmbVoNw3WhDzEztnQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I've instrumented by libpq code, to show the byte size of the result-set.
And I'm suprised that it's never smaller than 2,264 bytes, then the next
size I see is 3,288, etc... Even when receiving no rows at all, in fact.

I've trimmed-out the SQL, but these are all SELECT statements.
The output below is from Windows, if that matters.
The two larger ones at the bottom are fetching bytea blobs.

So, is this expected? I'm surprised 2KB+ is used to return no rows basically.
Where's the space going?

Is the reported space the same or similar to the actual bytes returned
on the wire?
Or they somehow add up local allocations client-side?
Any way to actually know how many bytes were returned on the wire?

I'm basically curious, and would appreciate pointers to better understand this.

Thanks, --DD

Running 1 test case...
...
`-> got 1 rows x 16 cols, 3,288 bytes (2.7 MB/s) in 1.159ms
...
`-> got 1 rows x 18 cols, 3,288 bytes (2.2 MB/s) in 1.417ms
...
`-> got 1 rows x 18 cols, 3,288 bytes (4.1 MB/s) in 0.771ms
...
`-> got 0 rows x 15 cols, 2,264 bytes (2.1 MB/s) in 1.041ms
...
`-> got 0 rows x 3 cols, 2,264 bytes (2.2 MB/s) in 0.991ms
...
`-> got 0 rows x 15 cols, 2,264 bytes (3.3 MB/s) in 0.662ms
...
`-> got 0 rows x 3 cols, 2,264 bytes (4.3 MB/s) in 0.503ms
...
`-> got 1 rows x 14 cols, 3,288 bytes (3.6 MB/s) in 0.863ms
...
`-> got 1 rows x 16 cols, 3,288 bytes (5.0 MB/s) in 0.623ms
...
`-> got 0 rows x 15 cols, 2,264 bytes (3.6 MB/s) in 0.602ms
...
`-> got 0 rows x 3 cols, 2,264 bytes (4.4 MB/s) in 0.494ms
...
`-> got 0 rows x 15 cols, 2,264 bytes (3.7 MB/s) in 0.591ms
...
`-> got 0 rows x 3 cols, 2,264 bytes (3.9 MB/s) in 0.548ms
...
`-> got 1 rows x 1 cols, 818,441 bytes (78.1 MB/s) in 9.996ms
...
`-> got 1 rows x 1 cols, 3,288 bytes (7.9 MB/s) in 0.396ms
...
`-> got 1 rows x 1 cols, 36,345 bytes (33.4 MB/s) in 1.038ms

*** No errors detected
*** tests_acme_foo in 2.926s (user: 0.219s) 38 MB

Press any key to continue . . .

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bharath Rupireddy 2022-03-10 14:27:23 Re: primary_conninfo and restore_command ?
Previous Message Julien Rouhaud 2022-03-10 14:04:46 Re: primary_conninfo and restore_command ?