Skip to content

Commit 164acbe

Browse files
committed
Fix indentation of JOIN clauses in rule/view dumps.
The code attempted to outdent JOIN clauses further left than the parent FROM keyword, which was odd in any case, and led to inconsistent formatting since in simple cases the clauses couldn't be moved any further left than that. And it left a permanent decrement of the indentation level, causing subsequent lines to be much further left than they should be (again, this couldn't be seen in simple cases for lack of indentation to give up). After a little experimentation I chose to make it indent JOIN keywords two spaces from the parent FROM, which is one space more than the join's lefthand input in cases where that appears on a different line from FROM. Back-patch to 9.3. This is a purely cosmetic change, and the bug is quite old, so that may seem arbitrary; but we are going to be making some other changes to the indentation behavior in both HEAD and 9.3, so it seems reasonable to include this in 9.3 too. I committed this one first because its effects are more visible in the regression test results as they currently stand than they will be later.
1 parent 8a90a39 commit 164acbe

File tree

3 files changed

+384
-382
lines changed

3 files changed

+384
-382
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666

6767
/* Indent counts */
6868
#define PRETTYINDENT_STD 8
69-
#define PRETTYINDENT_JOIN 13
70-
#define PRETTYINDENT_JOIN_ON (PRETTYINDENT_JOIN-PRETTYINDENT_STD)
69+
#define PRETTYINDENT_JOIN 4
7170
#define PRETTYINDENT_VAR 4
7271

7372
/* Pretty flags */
@@ -8122,27 +8121,32 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
81228121
case JOIN_INNER:
81238122
if (j->quals)
81248123
appendContextKeyword(context, " JOIN ",
8125-
-PRETTYINDENT_JOIN,
8126-
PRETTYINDENT_JOIN, 2);
8124+
-PRETTYINDENT_STD,
8125+
PRETTYINDENT_STD,
8126+
PRETTYINDENT_JOIN);
81278127
else
81288128
appendContextKeyword(context, " CROSS JOIN ",
8129-
-PRETTYINDENT_JOIN,
8130-
PRETTYINDENT_JOIN, 1);
8129+
-PRETTYINDENT_STD,
8130+
PRETTYINDENT_STD,
8131+
PRETTYINDENT_JOIN);
81318132
break;
81328133
case JOIN_LEFT:
81338134
appendContextKeyword(context, " LEFT JOIN ",
8134-
-PRETTYINDENT_JOIN,
8135-
PRETTYINDENT_JOIN, 2);
8135+
-PRETTYINDENT_STD,
8136+
PRETTYINDENT_STD,
8137+
PRETTYINDENT_JOIN);
81368138
break;
81378139
case JOIN_FULL:
81388140
appendContextKeyword(context, " FULL JOIN ",
8139-
-PRETTYINDENT_JOIN,
8140-
PRETTYINDENT_JOIN, 2);
8141+
-PRETTYINDENT_STD,
8142+
PRETTYINDENT_STD,
8143+
PRETTYINDENT_JOIN);
81418144
break;
81428145
case JOIN_RIGHT:
81438146
appendContextKeyword(context, " RIGHT JOIN ",
8144-
-PRETTYINDENT_JOIN,
8145-
PRETTYINDENT_JOIN, 2);
8147+
-PRETTYINDENT_STD,
8148+
PRETTYINDENT_STD,
8149+
PRETTYINDENT_JOIN);
81468150
break;
81478151
default:
81488152
elog(ERROR, "unrecognized join type: %d",
@@ -8155,8 +8159,6 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
81558159
if (need_paren_on_right)
81568160
appendStringInfoChar(buf, ')');
81578161

8158-
context->indentLevel -= PRETTYINDENT_JOIN_ON;
8159-
81608162
if (j->usingClause)
81618163
{
81628164
ListCell *lc;

0 commit comments

Comments
 (0)