Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6ebeeae

Browse files
Cache typarray for fast lookups in binary upgrade mode
When upgrading a large schema it adds significant overhead to performindividual catalog lookups per relation in order to retrieve Oid forpreserving Oid calls. This instead adds the typarray to the TypeInfocache which then allows for fast lookups using the existing API. A35% reduction of pg_dump runtime in binary upgrade mode was observedwith this change.Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>Discussion:https://postgr.es/m/8F1F1E1D-D17B-4B33-B014-EDBCD15F3F0B@yesql.se
1 parent4d5111b commit6ebeeae

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5412,23 +5412,15 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout,
54125412
Oidpg_type_array_oid;
54135413
Oidpg_type_multirange_oid;
54145414
Oidpg_type_multirange_array_oid;
5415+
TypeInfo *tinfo;
54155416

54165417
appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
54175418
appendPQExpBuffer(upgrade_buffer,
54185419
"SELECT pg_catalog.binary_upgrade_set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
54195420
pg_type_oid);
54205421

5421-
appendPQExpBuffer(upgrade_query,
5422-
"SELECT typarray "
5423-
"FROM pg_catalog.pg_type "
5424-
"WHERE oid = '%u'::pg_catalog.oid;",
5425-
pg_type_oid);
5426-
5427-
res = ExecuteSqlQueryForSingleRow(fout, upgrade_query->data);
5428-
5429-
pg_type_array_oid = atooid(PQgetvalue(res, 0, PQfnumber(res, "typarray")));
5430-
5431-
PQclear(res);
5422+
tinfo = findTypeByOid(pg_type_oid);
5423+
pg_type_array_oid = tinfo->typarray;
54325424

54335425
if (!OidIsValid(pg_type_array_oid) && force_array_type)
54345426
pg_type_array_oid = get_next_possible_free_pg_type_oid(fout, upgrade_query);
@@ -5910,6 +5902,7 @@ getTypes(Archive *fout)
59105902
inti_typtype;
59115903
inti_typisdefined;
59125904
inti_isarray;
5905+
inti_typarray;
59135906

59145907
/*
59155908
* we include even the built-in types because those may be used as array
@@ -5930,7 +5923,7 @@ getTypes(Archive *fout)
59305923
"typnamespace, typacl, "
59315924
"acldefault('T', typowner) AS acldefault, "
59325925
"typowner, "
5933-
"typelem, typrelid, "
5926+
"typelem, typrelid,typarray,"
59345927
"CASE WHEN typrelid = 0 THEN ' '::\"char\" "
59355928
"ELSE (SELECT relkind FROM pg_class WHERE oid = typrelid) END AS typrelkind, "
59365929
"typtype, typisdefined, "
@@ -5957,6 +5950,7 @@ getTypes(Archive *fout)
59575950
i_typtype = PQfnumber(res, "typtype");
59585951
i_typisdefined = PQfnumber(res, "typisdefined");
59595952
i_isarray = PQfnumber(res, "isarray");
5953+
i_typarray = PQfnumber(res, "typarray");
59605954

59615955
for (i = 0; i < ntups; i++)
59625956
{
@@ -5989,6 +5983,8 @@ getTypes(Archive *fout)
59895983
else
59905984
tyinfo[i].isArray = false;
59915985

5986+
tyinfo[i].typarray = atooid(PQgetvalue(res, i, i_typarray));
5987+
59925988
if (tyinfo[i].typtype == TYPTYPE_MULTIRANGE)
59935989
tyinfo[i].isMultirange = true;
59945990
else

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ typedef struct _typeInfo
200200
constchar*rolname;
201201
Oidtypelem;
202202
Oidtyprelid;
203+
Oidtyparray;
203204
chartyprelkind;/* 'r', 'v', 'c', etc */
204205
chartyptype;/* 'b', 'c', etc */
205206
boolisArray;/* true if auto-generated array type */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp