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

Commitde6c439

Browse files
committed
Limit overall indentation in rule/view dumps.
Continuing to indent no matter how deeply nested we get doesn't reallydo anything for readability; what's worse, it results in O(N^2) totalwhitespace, which can become a performance and memory-consumption issue.To address this, once we get past 40 characters of indentation, reducethe indentation step distance 4x, and also limit the maximum indentationby reducing it modulo 40. This latter choice is a bit weird at firstglance, but it seems to preserve readability better than a simple capwould do.Back-patch to 9.3, because since commit62e6664 the performance issueis a hazard for pg_dump.Greg Stark and Tom Lane
1 parent164acbe commitde6c439

File tree

2 files changed

+140
-116
lines changed

2 files changed

+140
-116
lines changed

‎src/backend/utils/adt/ruleutils.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
#definePRETTYINDENT_JOIN4
7070
#definePRETTYINDENT_VAR4
7171

72+
#definePRETTYINDENT_LIMIT40/* wrap limit */
73+
7274
/* Pretty flags */
7375
#definePRETTYFLAG_PAREN1
7476
#definePRETTYFLAG_INDENT2
@@ -6258,14 +6260,36 @@ appendContextKeyword(deparse_context *context, const char *str,
62586260

62596261
if (PRETTY_INDENT(context))
62606262
{
6263+
intindentAmount;
6264+
62616265
context->indentLevel+=indentBefore;
62626266

62636267
/* remove any trailing spaces currently in the buffer ... */
62646268
removeStringInfoSpaces(buf);
62656269
/* ... then add a newline and some spaces */
62666270
appendStringInfoChar(buf,'\n');
6267-
appendStringInfoSpaces(buf,
6268-
Max(context->indentLevel,0)+indentPlus);
6271+
6272+
if (context->indentLevel<PRETTYINDENT_LIMIT)
6273+
indentAmount=Max(context->indentLevel,0)+indentPlus;
6274+
else
6275+
{
6276+
/*
6277+
* If we're indented more than PRETTYINDENT_LIMIT characters, try
6278+
* to conserve horizontal space by reducing the per-level
6279+
* indentation. For best results the scale factor here should
6280+
* divide all the indent amounts that get added to indentLevel
6281+
* (PRETTYINDENT_STD, etc). It's important that the indentation
6282+
* not grow unboundedly, else deeply-nested trees use O(N^2)
6283+
* whitespace; so we also wrap modulo PRETTYINDENT_LIMIT.
6284+
*/
6285+
indentAmount=PRETTYINDENT_LIMIT+
6286+
(context->indentLevel-PRETTYINDENT_LIMIT) /
6287+
(PRETTYINDENT_STD /2);
6288+
indentAmount %=PRETTYINDENT_LIMIT;
6289+
/* scale/wrap logic affects indentLevel, but not indentPlus */
6290+
indentAmount+=indentPlus;
6291+
}
6292+
appendStringInfoSpaces(buf,indentAmount);
62696293

62706294
appendStringInfoString(buf,str);
62716295

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp