Skip to content

Commit ffc109d

Browse files
author
Deepa Dixit
committed
Merge branch 'mysql-5.6' into mysql-5.7
2 parents 57665e1 + d65dae2 commit ffc109d

12 files changed

+171
-180
lines changed

mysql-test/include/explain_utils.inc

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,11 @@ if ($innodb) {
7474
}
7575
}
7676
--eval EXPLAIN FORMAT=JSON $query;
77-
if ($validation) {
78-
--disable_query_log
79-
--replace_result $MASTER_MYSOCK MASTER_MYSOCK
77+
--disable_result_log
8078
--exec $MYSQL -S $MASTER_MYSOCK -u root -r test -e "EXPLAIN FORMAT=JSON $query;" > $MYSQLTEST_VARDIR/tmp/explain.json
81-
--replace_regex /[-]*// /FILE.[\/\\:_\.0-9A-Za-z]*/Validation:/
82-
--exec python $MYSQL_TEST_DIR/suite/opt_trace/validate_json.py $MYSQLTEST_VARDIR/tmp/explain.json
79+
--exec perl $MYSQL_TEST_DIR/suite/opt_trace/validate_json.pl $MYSQLTEST_VARDIR/tmp/explain.json
8380
--remove_file '$MYSQLTEST_VARDIR/tmp/explain.json'
84-
--enable_query_log
85-
}
81+
--enable_result_log
8682
}
8783

8884
if ($select) {
@@ -111,15 +107,11 @@ if ($innodb) {
111107
}
112108
}
113109
--eval EXPLAIN FORMAT=JSON $select;
114-
if ($validation) {
115-
--disable_query_log
116-
--replace_result $MASTER_MYSOCK MASTER_MYSOCK
110+
--disable_result_log
117111
--exec $MYSQL -S $MASTER_MYSOCK -u root -r test -e "EXPLAIN FORMAT=JSON $select;" > $MYSQLTEST_VARDIR/tmp/explain.json
118-
--replace_regex /[-]*// /FILE.[\/\\:_\.0-9A-Za-z]*/Validation:/
119-
--exec python $MYSQL_TEST_DIR/suite/opt_trace/validate_json.py $MYSQLTEST_VARDIR/tmp/explain.json
112+
--exec perl $MYSQL_TEST_DIR/suite/opt_trace/validate_json.pl $MYSQLTEST_VARDIR/tmp/explain.json
120113
--remove_file '$MYSQLTEST_VARDIR/tmp/explain.json'
121-
--enable_query_log
122-
}
114+
--enable_result_log
123115
}
124116
}
125117

mysql-test/include/python_with_json.inc

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#!/usr/bin/perl
2+
use strict;
3+
use JSON;
4+
use File::Spec::Functions qw/ canonpath /;
5+
my $usage = "This is from WL#5257 \"first API for optimizer trace\".
6+
7+
Usage:
8+
%s [-q] <a_file> <another_file> <etc>
9+
10+
-q quiet mode: only display errors and warnings.
11+
12+
It will verify that all optimizer traces of files (usually a_file
13+
is a .result or .reject file which contains
14+
SELECT * FROM OPTIMIZER_TRACE; ) are JSON-compliant, and that
15+
they contain no duplicates keys.
16+
Exit code is 0 if all ok.";
17+
my $retcode = 0;
18+
my @ignored;
19+
my @input = @ARGV;
20+
21+
# Filter out "-q" options
22+
@input = grep {!/-q/} @input;
23+
24+
if (!@input)
25+
{
26+
print "$usage\n";
27+
exit 1;
28+
}
29+
30+
# If command line contains at least one "-q" option, it is quiet mode
31+
my $quiet= scalar(@input) <= scalar(@ARGV) -1;
32+
# On Windows, command line arguments specified using wildcards need to be evaluated.
33+
# On Unix too if the arguments are passed with single quotes.
34+
my $need_parse = grep(/\*/,@input);
35+
if ($need_parse)
36+
{
37+
my $platform_independent_dir;
38+
$platform_independent_dir= canonpath "@input";
39+
@input= glob "$platform_independent_dir";
40+
}
41+
42+
foreach my $input_file (@input)
43+
{
44+
handle_one_file($input_file);
45+
print "\n";
46+
}
47+
48+
if ( @ignored )
49+
{
50+
print STDERR "These files have been ignored:\n";
51+
foreach my $ig ( @ignored )
52+
{
53+
print "$ig\n";
54+
}
55+
print "\n";
56+
}
57+
if ( $retcode )
58+
{
59+
print STDERR "There are errors\n";
60+
}
61+
62+
else
63+
{
64+
print "\n";
65+
print "ALL OK\n";
66+
}
67+
68+
exit $retcode;
69+
70+
sub handle_one_file {
71+
72+
my ( $input_file ) = @_;
73+
if ( $input_file =~ /^.*(ctype_.*|mysqldump)\.result/ )
74+
{
75+
push @ignored ,$input_file;
76+
return;
77+
}
78+
print "FILE $input_file\n";
79+
print "\n";
80+
open(DATA,"<$input_file") or die "Can't open file";
81+
my @lines = <DATA>;
82+
close(DATA);
83+
my $first_trace_line = 0;
84+
my $trace_line = 0;
85+
my @trace = undef;
86+
label_to: foreach my $i ( @lines )
87+
{
88+
$trace_line = $trace_line + 1;
89+
if (( grep(/^.*(\t)?{\n/,$i) ) and ( $first_trace_line == 0 ))
90+
{
91+
@trace = undef;
92+
$first_trace_line = $trace_line;
93+
push @trace, "{\n";
94+
next label_to;
95+
}
96+
if (( $i =~ /^}/ ) and ( $first_trace_line != 0))
97+
{
98+
push @trace, "}";
99+
check($first_trace_line,@trace);
100+
$first_trace_line = 0;
101+
}
102+
if ( $first_trace_line != 0 )
103+
{
104+
# Eliminate /* */ from end_marker=on (not valid JSON)
105+
$i =~ s/\/\*.*\*\// /g;
106+
push @trace, $i;
107+
}
108+
109+
}
110+
}
111+
112+
113+
sub check {
114+
115+
my ( $first_trace_line, @trace ) = @_;
116+
my $string = join("", @trace);
117+
my $parsed;
118+
eval { $parsed = decode_json($string); };
119+
unless ( $parsed )
120+
{
121+
print "Parse error at line: $first_trace_line\n";
122+
my $error = $@;
123+
print "Error: $@\n";
124+
# If there is a character position specified, put a mark ('&') in front of this character
125+
if ($error =~ /invalid character.*at character offset (\d+)/)
126+
{
127+
substr($string,$1,0) = "&";
128+
print "$string\n";
129+
}
130+
else
131+
{
132+
print "$string\n";
133+
}
134+
$retcode = 1;
135+
print "\n";
136+
return;
137+
}
138+
# Detect non-unique keys in one object, by counting
139+
# number of quote symbols ("): the json module outputs only
140+
# one of the non-unique keys, making the number of "
141+
# smaller compared to the input string.
142+
143+
my $before = $string =~ tr/'"'//;
144+
my $re_json;
145+
$re_json= to_json($parsed);
146+
my $after = $re_json =~ tr/'"'//;
147+
if ( $before != $after )
148+
{
149+
print "Non-unique keys at line $first_trace_line ( $before vs $after )\n";
150+
print "$string\n";
151+
$retcode = 1;
152+
print "\n";
153+
return;
154+
}
155+
if ( !$quiet )
156+
{
157+
print "OK at line $first_trace_line\n";
158+
}
159+
}

mysql-test/suite/opt_trace/validate_json.py

Lines changed: 0 additions & 123 deletions
This file was deleted.

mysql-test/t/innodb_explain_json_non_select_all.test

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ set @save_storage_engine= @@session.default_storage_engine;
2121
set session default_storage_engine = InnoDB;
2222
--let $innodb = 1
2323

24-
# Next 2 variables control the JSON format output and validation in explain_utils.
24+
# Next variable controls the JSON format output in explain_utils.
2525
# 1 = enable, 0 = disable
2626
--let $json = 1
27-
# Validation disabled due to not having Python with JSON on all PB machines.
28-
--let $validation = 0
29-
--file_exists $MYSQL_TEST_DIR/suite/opt_trace/validate_json.py
27+
--file_exists $MYSQL_TEST_DIR/suite/opt_trace/validate_json.pl
3028

3129
--source include/explain_non_select.inc
3230
set default_storage_engine= @save_storage_engine;

mysql-test/t/innodb_explain_json_non_select_none.test

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ if (`select locate('mrr', @@optimizer_switch) > 0`)
2929
set @save_storage_engine= @@session.default_storage_engine;
3030
set session default_storage_engine = InnoDB;
3131
--let $innodb = 1
32-
# Next 2 variables control the JSON format output and validation in explain_utils.
32+
# Next variable controls the JSON format output in explain_utils.
3333
# 1 = enable, 0 = disable
3434
--let $json = 1
35-
# Validation disabled due to not having Python with JSON on all PB machines.
36-
--let $validation = 0
3735
--source include/explain_non_select.inc
3836
set default_storage_engine= @save_storage_engine;
3937

mysql-test/t/innodb_explain_non_select_all.test

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ set @save_storage_engine= @@session.default_storage_engine;
1818
set session default_storage_engine = InnoDB;
1919
--let $innodb = 1
2020

21-
# json validation in explain_util.inc can be switched off by setting to zero.
21+
# json format in explain_util.inc can be switched off by setting to zero.
2222
--let $json = 0
23-
--let $validation = 0
2423

2524
--source include/explain_non_select.inc
2625
set default_storage_engine= @save_storage_engine;

mysql-test/t/innodb_explain_non_select_none.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ set @save_storage_engine= @@session.default_storage_engine;
2828
set session default_storage_engine = InnoDB;
2929
--let $innodb = 1
3030
--let $json = 0
31-
--let $validation = 0
3231
--source include/explain_non_select.inc
3332
set default_storage_engine= @save_storage_engine;
3433

0 commit comments

Comments
 (0)