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

Commit1852aea

Browse files
Don't convert to and from floats in pg_dump.
Commit8f42718 improved performance by remembering relation statsas native types rather than issuing a new query for each relation.Using native types is fine for integers like relpages; but reltuplesis floating point. The commit controllled for that complexity by usingsetlocale(LC_NUMERIC, "C"). After that, Alexander Lakhin found aproblem in pg_strtof(), fixed in00d61a0.While we aren't aware of any more problems with that approach, itseems wise to just use a string the whole way for floating pointvalues, as Corey's original patch did, and get rid of thesetlocale(). Integers are still converted to native types to avoidwasting memory.Co-authored-by: Corey Huinker <corey.huinker@gmail.com>Discussion:https://postgr.es/m/3049348.1740855411@sss.pgh.pa.usDiscussion:https://postgr.es/m/560cca3781740bd69881bb07e26eb8f65b09792c.camel%40j-davis.com
1 parent7fb8801 commit1852aea

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

‎src/bin/pg_dump/pg_dump.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,6 @@ main(int argc, char **argv)
525525
pg_logging_set_level(PG_LOG_WARNING);
526526
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_dump"));
527527

528-
/* ensure that locale does not affect floating point interpretation */
529-
setlocale(LC_NUMERIC, "C");
530-
531528
/*
532529
* Initialize what we need for parallel execution, especially for thread
533530
* support on Windows.
@@ -6816,10 +6813,12 @@ getFuncs(Archive *fout)
68166813
* getRelationStatistics
68176814
* register the statistics object as a dependent of the relation.
68186815
*
6816+
* reltuples is passed as a string to avoid complexities in converting from/to
6817+
* floating point.
68196818
*/
68206819
static RelStatsInfo *
68216820
getRelationStatistics(Archive *fout, DumpableObject *rel, int32 relpages,
6822-
floatreltuples, int32 relallvisible, char relkind,
6821+
char *reltuples, int32 relallvisible, char relkind,
68236822
char **indAttNames, int nindAttNames)
68246823
{
68256824
if (!fout->dopt->dumpStatistics)
@@ -6846,7 +6845,7 @@ getRelationStatistics(Archive *fout, DumpableObject *rel, int32 relpages,
68466845
dobj->name = pg_strdup(rel->name);
68476846
dobj->namespace = rel->namespace;
68486847
info->relpages = relpages;
6849-
info->reltuples = reltuples;
6848+
info->reltuples =pstrdup(reltuples);
68506849
info->relallvisible = relallvisible;
68516850
info->relkind = relkind;
68526851
info->indAttNames = indAttNames;
@@ -7149,7 +7148,6 @@ getTables(Archive *fout, int *numTables)
71497148

71507149
for (i = 0; i < ntups; i++)
71517150
{
7152-
floatreltuples = strtof(PQgetvalue(res, i, i_reltuples), NULL);
71537151
int32relallvisible = atoi(PQgetvalue(res, i, i_relallvisible));
71547152

71557153
tblinfo[i].dobj.objType = DO_TABLE;
@@ -7252,8 +7250,8 @@ getTables(Archive *fout, int *numTables)
72527250
/* Add statistics */
72537251
if (tblinfo[i].interesting)
72547252
getRelationStatistics(fout, &tblinfo[i].dobj, tblinfo[i].relpages,
7255-
reltuples, relallvisible, tblinfo[i].relkind,
7256-
NULL, 0);
7253+
PQgetvalue(res, i, i_reltuples),
7254+
relallvisible, tblinfo[i].relkind,NULL, 0);
72577255

72587256
/*
72597257
* Read-lock target tables to make sure they aren't DROPPED or altered
@@ -7762,7 +7760,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
77627760
charindexkind;
77637761
RelStatsInfo *relstats;
77647762
int32relpages = atoi(PQgetvalue(res, j, i_relpages));
7765-
floatreltuples = strtof(PQgetvalue(res, j, i_reltuples), NULL);
77667763
int32relallvisible = atoi(PQgetvalue(res, j, i_relallvisible));
77677764

77687765
indxinfo[j].dobj.objType = DO_INDEX;
@@ -7805,7 +7802,8 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
78057802
}
78067803

78077804
relstats = getRelationStatistics(fout, &indxinfo[j].dobj, relpages,
7808-
reltuples, relallvisible, indexkind,
7805+
PQgetvalue(res, j, i_reltuples),
7806+
relallvisible, indexkind,
78097807
indAttNames, nindAttNames);
78107808

78117809
contype = *(PQgetvalue(res, j, i_contype));
@@ -10493,7 +10491,6 @@ dumpRelationStats(Archive *fout, const RelStatsInfo *rsinfo)
1049310491
DumpId *deps = NULL;
1049410492
intndeps = 0;
1049510493
char *qualified_name;
10496-
charreltuples_str[FLOAT_SHORTEST_DECIMAL_LEN];
1049710494
inti_attname;
1049810495
inti_inherited;
1049910496
inti_null_frac;
@@ -10568,8 +10565,7 @@ dumpRelationStats(Archive *fout, const RelStatsInfo *rsinfo)
1056810565
appendStringLiteralAH(out, qualified_name, fout);
1056910566
appendPQExpBufferStr(out, "::regclass,\n");
1057010567
appendPQExpBuffer(out, "\t'relpages', '%d'::integer,\n", rsinfo->relpages);
10571-
float_to_shortest_decimal_buf(rsinfo->reltuples, reltuples_str);
10572-
appendPQExpBuffer(out, "\t'reltuples', '%s'::real,\n", reltuples_str);
10568+
appendPQExpBuffer(out, "\t'reltuples', '%s'::real,\n", rsinfo->reltuples);
1057310569
appendPQExpBuffer(out, "\t'relallvisible', '%d'::integer\n);\n",
1057410570
rsinfo->relallvisible);
1057510571

‎src/bin/pg_dump/pg_dump.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ typedef struct _relStatsInfo
439439
{
440440
DumpableObjectdobj;
441441
int32relpages;
442-
floatreltuples;
442+
char*reltuples;
443443
int32relallvisible;
444444
charrelkind;/* 'r', 'm', 'i', etc */
445445

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp