Commit d166eed3 authored by Tom Lane's avatar Tom Lane

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.
parent 5358bfdc
...@@ -68,8 +68,7 @@ ...@@ -68,8 +68,7 @@
/* Indent counts */ /* Indent counts */
#define PRETTYINDENT_STD 8 #define PRETTYINDENT_STD 8
#define PRETTYINDENT_JOIN 13 #define PRETTYINDENT_JOIN 4
#define PRETTYINDENT_JOIN_ON (PRETTYINDENT_JOIN-PRETTYINDENT_STD)
#define PRETTYINDENT_VAR 4 #define PRETTYINDENT_VAR 4
/* Pretty flags */ /* Pretty flags */
...@@ -8378,27 +8377,32 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) ...@@ -8378,27 +8377,32 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
case JOIN_INNER: case JOIN_INNER:
if (j->quals) if (j->quals)
appendContextKeyword(context, " JOIN ", appendContextKeyword(context, " JOIN ",
-PRETTYINDENT_JOIN, -PRETTYINDENT_STD,
PRETTYINDENT_JOIN, 2); PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
else else
appendContextKeyword(context, " CROSS JOIN ", appendContextKeyword(context, " CROSS JOIN ",
-PRETTYINDENT_JOIN, -PRETTYINDENT_STD,
PRETTYINDENT_JOIN, 1); PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break; break;
case JOIN_LEFT: case JOIN_LEFT:
appendContextKeyword(context, " LEFT JOIN ", appendContextKeyword(context, " LEFT JOIN ",
-PRETTYINDENT_JOIN, -PRETTYINDENT_STD,
PRETTYINDENT_JOIN, 2); PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break; break;
case JOIN_FULL: case JOIN_FULL:
appendContextKeyword(context, " FULL JOIN ", appendContextKeyword(context, " FULL JOIN ",
-PRETTYINDENT_JOIN, -PRETTYINDENT_STD,
PRETTYINDENT_JOIN, 2); PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break; break;
case JOIN_RIGHT: case JOIN_RIGHT:
appendContextKeyword(context, " RIGHT JOIN ", appendContextKeyword(context, " RIGHT JOIN ",
-PRETTYINDENT_JOIN, -PRETTYINDENT_STD,
PRETTYINDENT_JOIN, 2); PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break; break;
default: default:
elog(ERROR, "unrecognized join type: %d", elog(ERROR, "unrecognized join type: %d",
...@@ -8411,8 +8415,6 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context) ...@@ -8411,8 +8415,6 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
if (need_paren_on_right) if (need_paren_on_right)
appendStringInfoChar(buf, ')'); appendStringInfoChar(buf, ')');
context->indentLevel -= PRETTYINDENT_JOIN_ON;
if (j->usingClause) if (j->usingClause)
{ {
ListCell *lc; ListCell *lc;
......
This diff is collapsed.
...@@ -85,14 +85,14 @@ select * from vw_ord; ...@@ -85,14 +85,14 @@ select * from vw_ord;
(1 row) (1 row)
select definition from pg_views where viewname='vw_ord'; select definition from pg_views where viewname='vw_ord';
definition definition
------------------------------------------------------------------- ---------------------------------------------------------------------
SELECT v.n, + SELECT v.n, +
z.a, + z.a, +
z.b, + z.b, +
z.ord + z.ord +
FROM (( VALUES (1)) v(n) + FROM (( VALUES (1)) v(n) +
JOIN foot(1) WITH ORDINALITY z(a, b, ord) ON ((v.n = z.ord))); JOIN foot(1) WITH ORDINALITY z(a, b, ord) ON ((v.n = z.ord)));
(1 row) (1 row)
drop view vw_ord; drop view vw_ord;
...@@ -112,16 +112,16 @@ select * from vw_ord; ...@@ -112,16 +112,16 @@ select * from vw_ord;
(1 row) (1 row)
select definition from pg_views where viewname='vw_ord'; select definition from pg_views where viewname='vw_ord';
definition definition
--------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
SELECT v.n, + SELECT v.n, +
z.a, + z.a, +
z.b, + z.b, +
z.c, + z.c, +
z.d, + z.d, +
z.ord + z.ord +
FROM (( VALUES (1)) v(n) + FROM (( VALUES (1)) v(n) +
JOIN ROWS FROM(foot(1), foot(2)) WITH ORDINALITY z(a, b, c, d, ord) ON ((v.n = z.ord))); JOIN ROWS FROM(foot(1), foot(2)) WITH ORDINALITY z(a, b, c, d, ord) ON ((v.n = z.ord)));
(1 row) (1 row)
drop view vw_ord; drop view vw_ord;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment