summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/pg_plan_advice/pgpa_output.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/contrib/pg_plan_advice/pgpa_output.c b/contrib/pg_plan_advice/pgpa_output.c
index 1aca7fd679..1b660791ba 100644
--- a/contrib/pg_plan_advice/pgpa_output.c
+++ b/contrib/pg_plan_advice/pgpa_output.c
@@ -55,10 +55,22 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker,
ListCell *lc;
pgpa_output_context context;
+ /*
+ * If the user chooses to use EXPLAIN (PLAN_ADVICE) in an 80-column window
+ * from a psql client with default settings, psql will add one space to the
+ * left of the output and EXPLAIN will add two more to the left of the
+ * advice. Thus, lines of more than 77 characters will wrap. We set the
+ * wrap limit to 76 here so that the output won't reach all the way to the
+ * very last column of the terminal.
+ *
+ * Of course, this is fairly arbitrary set of assumptions, and one could
+ * well make an argument for a different wrap limit, or for a configurable
+ * one.
+ */
memset(&context, 0, sizeof(pgpa_output_context));
context.rt_identifiers = rt_identifiers;
context.buf = buf;
- context.wrap_column = 79; /* XXX */
+ context.wrap_column = 76;
/*
* Put all the top-level scans for each strategy into a single list.
@@ -94,6 +106,7 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker,
appendStringInfo(context.buf, "JOIN_ORDER(");
pgpa_output_unrolled_join(&context, ujoin);
appendStringInfoChar(context.buf, ')');
+ pgpa_maybe_linebreak(context.buf, context.wrap_column);
}
/*
@@ -134,6 +147,7 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker,
}
}
appendStringInfoChar(buf, ')');
+ pgpa_maybe_linebreak(context.buf, context.wrap_column);
}
/*
@@ -178,6 +192,7 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker,
}
}
appendStringInfoChar(buf, ')');
+ pgpa_maybe_linebreak(context.buf, context.wrap_column);
}
/* Sort query features into one list per query feature type. */
@@ -241,6 +256,7 @@ pgpa_output_advice(StringInfo buf, pgpa_plan_walker_context *walker,
}
}
appendStringInfoChar(buf, ')');
+ pgpa_maybe_linebreak(context.buf, context.wrap_column);
}
}
@@ -458,6 +474,7 @@ pgpa_maybe_linebreak(StringInfo buf, int wrap_column)
enlargeStringInfo(buf, 1);
memmove(&buf->data[save_cursor] + 1, &buf->data[save_cursor],
buf->len - save_cursor);
- buf->len++;
+ ++buf->cursor;
+ buf->data[++buf->len] = '\0';
buf->data[save_cursor] = '\n';
}