未验证 提交 d89fef52 编写于 作者: J Jacob Champion 提交者: GitHub

atmsort: try to find the end of \d tables correctly

Several \d variants don't put a row count at the end of their tables,
which means that atmsort doesn't stop sorting output until it finds a
row count somewhere later. Some tests are having their diff output
horribly mangled because of this, which makes debugging difficult.

When we see a \d command, try to apply more heuristics for finding the
end of a table. In addition to ending at a row count, end table sorting
whenever we find a line that doesn't have the same number of column
separators as the table header. If we don't have a table header, still
attempt to end table sorting at a blank line.

extprotocol's test output order must be fixed as a result. Put the
"External options" line where psql actually prints it, after "Format
options".
上级 f9f6d2fd
......@@ -689,9 +689,9 @@ Type: readable
Encoding: UTF8
Format type: text
Format options: delimiter ' ' null '\N' escape '\'
External options: {}
External location: demoprot://exttabtest.txt
Execute on: all segments
External options: {}
select count(*) from pg_class where relname = 'exttabtest_r_newname';
count
......
......@@ -1102,6 +1102,7 @@ sub atmsort_bigloop
my $getstatement = 0;
my $has_order = 0;
my $copy_to_stdout_result = 0;
my $describe_mode = 0;
my $directive = {};
my $big_ignore = 0;
my %define_match_expression;
......@@ -1218,12 +1219,41 @@ sub atmsort_bigloop
goto reprocess_row;
}
my $end_of_table = 0;
if ($describe_mode)
{
# \d tables don't always end with a row count, and there may be
# more than one of them per command. So we allow any of the
# following to end the table:
# - a blank line
# - a row that doesn't have the same number of column separators
# as the header line
# - a row count (checked below)
if ($ini =~ m/^$/)
{
$end_of_table = 1;
}
elsif (exists($directive->{firstline}))
{
# Count the number of column separators in the table header
# and our current line.
my $headerSeparators = ($directive->{firstline} =~ tr/\|//);
my $lineSeparators = ($ini =~ tr/\|//);
if ($headerSeparators != $lineSeparators)
{
$end_of_table = 1;
}
}
# Don't reset describe_mode at the end of the table; there may
# be more tables still to go.
}
# regex example: (5 rows)
if ($ini =~ m/^\s*\(\d+\s+row(?:s)*\)\s*$/)
{
format_query_output($glob_fqo,
$has_order, \@outarr, $directive);
# Always ignore the rowcount for explain plan out as the
# skeleton plans might be the same even if the row counts
# differ because of session level GUCs.
......@@ -1232,6 +1262,14 @@ sub atmsort_bigloop
$ini = 'GP_IGNORE:' . $ini;
}
$end_of_table = 1;
}
if ($end_of_table)
{
format_query_output($glob_fqo,
$has_order, \@outarr, $directive);
$directive = {};
@outarr = ();
$getrows = 0;
......@@ -1272,7 +1310,7 @@ sub atmsort_bigloop
}
# Note: \d is for the psql "describe"
if ($ini =~ m/(?:insert|update|delete|select|\\d|copy|execute)/i)
if ($ini =~ m/(?:insert|update|delete|select|^\s*\\d|copy|execute)/i)
{
$copy_to_stdout_result = 0;
$has_order = 0;
......@@ -1282,6 +1320,10 @@ sub atmsort_bigloop
{
$directive->{explain} = 'normal';
}
# Should we apply more heuristics to try to find the end of \d
# output?
$describe_mode = ($ini =~ m/^\s*\\d/);
}
# Catching multiple commands and capturing the parens matches
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册