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.
This commit is contained in:
Tom Lane 2014-04-30 12:01:19 -04:00
parent 5358bfdc98
commit d166eed302
4 changed files with 404 additions and 402 deletions

View File

@ -68,8 +68,7 @@
/* Indent counts */
#define PRETTYINDENT_STD 8
#define PRETTYINDENT_JOIN 13
#define PRETTYINDENT_JOIN_ON (PRETTYINDENT_JOIN-PRETTYINDENT_STD)
#define PRETTYINDENT_JOIN 4
#define PRETTYINDENT_VAR 4
/* Pretty flags */
@ -8378,27 +8377,32 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
case JOIN_INNER:
if (j->quals)
appendContextKeyword(context, " JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
else
appendContextKeyword(context, " CROSS JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 1);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
case JOIN_LEFT:
appendContextKeyword(context, " LEFT JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
case JOIN_FULL:
appendContextKeyword(context, " FULL JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
case JOIN_RIGHT:
appendContextKeyword(context, " RIGHT JOIN ",
-PRETTYINDENT_JOIN,
PRETTYINDENT_JOIN, 2);
-PRETTYINDENT_STD,
PRETTYINDENT_STD,
PRETTYINDENT_JOIN);
break;
default:
elog(ERROR, "unrecognized join type: %d",
@ -8411,8 +8415,6 @@ get_from_clause_item(Node *jtnode, Query *query, deparse_context *context)
if (need_paren_on_right)
appendStringInfoChar(buf, ')');
context->indentLevel -= PRETTYINDENT_JOIN_ON;
if (j->usingClause)
{
ListCell *lc;

View File

@ -707,7 +707,7 @@ create view v2a as select * from (tt2 join tt3 using (b,c) join tt4 using (b)) j
create view v3 as select * from tt2 join tt3 using (b,c) full join tt4 using (b);
select pg_get_viewdef('v1', true);
pg_get_viewdef
---------------------------
-----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -718,7 +718,7 @@ select pg_get_viewdef('v1', true);
select pg_get_viewdef('v1a', true);
pg_get_viewdef
------------------------------
--------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -729,7 +729,7 @@ select pg_get_viewdef('v1a', true);
select pg_get_viewdef('v2', true);
pg_get_viewdef
--------------------------
----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -743,7 +743,7 @@ select pg_get_viewdef('v2', true);
select pg_get_viewdef('v2a', true);
pg_get_viewdef
---------------------------
-----------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -757,7 +757,7 @@ select pg_get_viewdef('v2a', true);
select pg_get_viewdef('v3', true);
pg_get_viewdef
-----------------------------
-------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
@ -773,7 +773,7 @@ alter table tt2 add column d int;
alter table tt2 add column e int;
select pg_get_viewdef('v1', true);
pg_get_viewdef
---------------------------
-----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -784,7 +784,7 @@ select pg_get_viewdef('v1', true);
select pg_get_viewdef('v1a', true);
pg_get_viewdef
------------------------------
--------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -795,7 +795,7 @@ select pg_get_viewdef('v1a', true);
select pg_get_viewdef('v2', true);
pg_get_viewdef
--------------------------
----------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -809,7 +809,7 @@ select pg_get_viewdef('v2', true);
select pg_get_viewdef('v2a', true);
pg_get_viewdef
---------------------------
-----------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -823,7 +823,7 @@ select pg_get_viewdef('v2a', true);
select pg_get_viewdef('v3', true);
pg_get_viewdef
-----------------------------
-------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
@ -838,7 +838,7 @@ select pg_get_viewdef('v3', true);
alter table tt3 rename c to d;
select pg_get_viewdef('v1', true);
pg_get_viewdef
-----------------------------------------
-------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -849,7 +849,7 @@ select pg_get_viewdef('v1', true);
select pg_get_viewdef('v1a', true);
pg_get_viewdef
--------------------------------------------
----------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -860,7 +860,7 @@ select pg_get_viewdef('v1a', true);
select pg_get_viewdef('v2', true);
pg_get_viewdef
----------------------------------------
------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -874,7 +874,7 @@ select pg_get_viewdef('v2', true);
select pg_get_viewdef('v2a', true);
pg_get_viewdef
----------------------------------------
------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -888,7 +888,7 @@ select pg_get_viewdef('v2a', true);
select pg_get_viewdef('v3', true);
pg_get_viewdef
----------------------------------------
------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
@ -904,7 +904,7 @@ alter table tt3 add column c int;
alter table tt3 add column e int;
select pg_get_viewdef('v1', true);
pg_get_viewdef
-------------------------------------------------
---------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -915,7 +915,7 @@ select pg_get_viewdef('v1', true);
select pg_get_viewdef('v1a', true);
pg_get_viewdef
---------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -926,7 +926,7 @@ select pg_get_viewdef('v1a', true);
select pg_get_viewdef('v2', true);
pg_get_viewdef
------------------------------------------------
--------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -940,7 +940,7 @@ select pg_get_viewdef('v2', true);
select pg_get_viewdef('v2a', true);
pg_get_viewdef
---------------------------------------------------------------
-----------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -954,7 +954,7 @@ select pg_get_viewdef('v2a', true);
select pg_get_viewdef('v3', true);
pg_get_viewdef
------------------------------------------------
--------------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
@ -969,7 +969,7 @@ select pg_get_viewdef('v3', true);
alter table tt2 drop column d;
select pg_get_viewdef('v1', true);
pg_get_viewdef
-------------------------------------------------
---------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -980,7 +980,7 @@ select pg_get_viewdef('v1', true);
select pg_get_viewdef('v1a', true);
pg_get_viewdef
------------------------------------------------------------------------------
--------------------------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -991,7 +991,7 @@ select pg_get_viewdef('v1a', true);
select pg_get_viewdef('v2', true);
pg_get_viewdef
------------------------------------------------
--------------------------------------------------
SELECT tt2.b, +
tt3.c, +
tt2.a, +
@ -1005,7 +1005,7 @@ select pg_get_viewdef('v2', true);
select pg_get_viewdef('v2a', true);
pg_get_viewdef
------------------------------------------------------------
--------------------------------------------------------------
SELECT j.b, +
j.c, +
j.a, +
@ -1019,7 +1019,7 @@ select pg_get_viewdef('v2a', true);
select pg_get_viewdef('v3', true);
pg_get_viewdef
------------------------------------------------
--------------------------------------------------
SELECT b, +
tt3.c, +
tt2.a, +
@ -1036,7 +1036,7 @@ create table tt6 (c int, d int);
create view vv1 as select * from (tt5 cross join tt6) j(aa,bb,cc,dd);
select pg_get_viewdef('vv1', true);
pg_get_viewdef
--------------------------------------
-----------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
@ -1048,7 +1048,7 @@ select pg_get_viewdef('vv1', true);
alter table tt5 add column c int;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
-----------------------------------------
--------------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
@ -1060,7 +1060,7 @@ select pg_get_viewdef('vv1', true);
alter table tt5 add column cc int;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
-----------------------------------------------
--------------------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
@ -1072,7 +1072,7 @@ select pg_get_viewdef('vv1', true);
alter table tt5 drop column c;
select pg_get_viewdef('vv1', true);
pg_get_viewdef
--------------------------------------------
-----------------------------------------------
SELECT j.aa, +
j.bb, +
j.cc, +
@ -1279,7 +1279,7 @@ create table tt10 (x int, z int);
create view vv5 as select x,y,z from tt9 join tt10 using(x);
select pg_get_viewdef('vv5', true);
pg_get_viewdef
-------------------------
---------------------------
SELECT tt9.x, +
tt9.y, +
tt10.z +
@ -1290,7 +1290,7 @@ select pg_get_viewdef('vv5', true);
alter table tt9 drop column xx;
select pg_get_viewdef('vv5', true);
pg_get_viewdef
-------------------------
---------------------------
SELECT tt9.x, +
tt9.y, +
tt10.z +

View File

@ -86,7 +86,7 @@ select * from vw_ord;
select definition from pg_views where viewname='vw_ord';
definition
-------------------------------------------------------------------
---------------------------------------------------------------------
SELECT v.n, +
z.a, +
z.b, +
@ -113,7 +113,7 @@ select * from vw_ord;
select definition from pg_views where viewname='vw_ord';
definition
---------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------
SELECT v.n, +
z.a, +
z.b, +