Avoid repeated PQfnumber() in pg_dump - Mailing list pgsql-hackers

From houzj.fnst@fujitsu.com
Subject Avoid repeated PQfnumber() in pg_dump
Date
Msg-id OS0PR01MB57164C392783F29F6D0ECA0B94139@OS0PR01MB5716.jpnprd01.prod.outlook.com
Whole thread Raw
Responses Re: Avoid repeated PQfnumber() in pg_dump  (Justin Pryzby <pryzby@telsasoft.com>)
Re: Avoid repeated PQfnumber() in pg_dump  (Daniel Gustafsson <daniel@yesql.se>)
List pgsql-hackers
Hi,

When reviewing some pg_dump related code, I found some existsing code
(getTableAttrs() and dumpEnumType()) invoke PQfnumber() repeatedly which seems
unnecessary.

Example
-----
        for (int j = 0; j < ntups; j++)
        {
            if (j + 1 != atoi(PQgetvalue(res, j, PQfnumber(res, "attnum"))))
-----

Since PQfnumber() is not a cheap function, I think we'd better invoke
PQfnumber() out of the loop like the attatched patch.

After applying this change, I can see about 8% performance gain in my test environment
when dump table definitions which have many columns.

Best regards,
Hou zhijie

Attachment

pgsql-hackers by date:

Previous
From: Peter Smith
Date:
Subject: Re: [HACKERS] logical decoding of two-phase transactions
Next
From: Magnus Hagander
Date:
Subject: Re: Feature improvement: can we add queryId for pg_catalog.pg_stat_activity view?