Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/mysqltest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12549,6 +12549,7 @@ void init_re(void)
"^("
"[[:space:]]*PREPARE[[:space:]]|"
"[[:space:]]*EXECUTE[[:space:]]|"
"[[:space:]]*EXPLAIN[[:space:]]+EXTENDED[[:space:]]|"
"[[:space:]]*DEALLOCATE[[:space:]]+PREPARE[[:space:]]|"
"[[:space:]]*DROP[[:space:]]+PREPARE[[:space:]]|"
"(SET[[:space:]]+STATEMENT[[:space:]]+.+[[:space:]]+FOR[[:space:]]+)?"
Expand Down
57 changes: 57 additions & 0 deletions mysql-test/include/evw_capture.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Capture one execution method of $EVW_QRY into the file $EVW_OUT.
#
# Used by main/execute_various_ways.inc to cross-check that a query run
# several different ways returns the same rows.
#
# The statements are piped through a fresh mysql client session (so the
# real PREPARE/EXECUTE and CALL paths are exercised, unlike a backtick
# capture which only returns the first row, or a CREATE/INSERT ... SELECT
# sink which would change sql_command away from SQLCOM_SELECT).
#
# A marker row is emitted immediately before the row-producing statement;
# only the lines after the LAST marker are kept. For the prepared
# statement and stored procedure methods this isolates the *2nd* execution
# (the one MDEV-35673 is about). Kept rows are sorted, so row order does
# not need to be deterministic in $EVW_QRY.
#
# In (environment variables, set with `--let NAME= value`):
# MYSQL - the mysql client command (exported by mtr)
# EVW_DB - database to run in
# EVW_QRY - the query under test. It is interpolated into SQL built
# here (e.g. prepare s from '$q'), so it must contain no
# interior ';' and no single quote (').
# EVW_METHOD - 0..5, selects the execution method
# EVW_MARKER - marker string separating discarded from kept output
# EVW_OUT - output file for the normalised rows

perl;
my ($mysql,$db,$q,$m,$mark,$out) =
@ENV{qw(MYSQL EVW_DB EVW_QRY EVW_METHOD EVW_MARKER EVW_OUT)};

my $sel;
if ($m==0){ $sel="select '$mark'; $q"; }
elsif ($m==1){ $sel="prepare s from '$q'; execute s; select '$mark'; execute s; deallocate prepare s"; }
elsif ($m==2){ $sel="select '$mark'; select * from ($q) dt"; }
elsif ($m==3){ $sel="create view evw_v as $q; select '$mark'; select * from evw_v; drop view evw_v"; }
elsif ($m==4){ $sel="select '$mark'; with cte as ($q) select * from cte"; }
elsif ($m==5){ $sel="create procedure evw_p() $q; call evw_p(); select '$mark'; call evw_p(); drop procedure evw_p"; }
else { die "evw_capture.inc: bad EVW_METHOD '$m'"; }

my $raw="$out.raw";
# stderr is folded into the capture (2>&1); a method that errors *before*
# the marker would yield empty output, so this relies on the visible
# section of execute_various_ways.inc running first and aborting the test
# on any unexpected error.
open(P,"| $mysql --batch --skip-column-names $db > $raw 2>&1")
or die "evw_capture.inc: pipe to mysql: $!";
print P "$sel;\n" or die "evw_capture.inc: write to mysql: $!";
close(P) or die "evw_capture.inc: mysql client failed (exit $?) for method $m";

open(R,"<",$raw) or die "evw_capture.inc: read $raw: $!";
my @l=<R>; close(R); unlink $raw;
my $start=0;
for my $i (0..$#l){ $start=$i+1 if $l[$i]=~/\Q$mark\E/; }
my @rows= sort @l[$start..$#l];
open(W,">",$out) or die "evw_capture.inc: write $out: $!";
print W @rows; close(W);
EOF
2 changes: 0 additions & 2 deletions mysql-test/main/derived_cond_pushdown.test
Original file line number Diff line number Diff line change
Expand Up @@ -1896,9 +1896,7 @@ DELIMITER ;$$
CALL p1('a');
DROP PROCEDURE p1;

--disable_ps2_protocol
SELECT a FROM (SELECT "aa" a) t WHERE REGEXP_INSTR(t.a, (SELECT MAX('aa') FROM DUAL LIMIT 1));
--enable_ps2_protocol

DELIMITER $$;
CREATE OR REPLACE FUNCTION f1(a VARCHAR(10), b VARCHAR(10)) RETURNS INT
Expand Down
53 changes: 53 additions & 0 deletions mysql-test/main/execute_various_ways.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Run $qry six different ways, echo each to the result log (as before),
# then capture each method's result set and assert they are all
# row-for-row identical. See include/evw_capture.inc for how/why the
# capture is done through the mysql client rather than backticks or a
# table sink.
#
# In: $ver - label for this group
# $qry - the query under test (no interior ';')

# ---- visible executions: unchanged, still populate the .result file ----
echo test $ver.0;
eval $qry;
echo test $ver.1;
eval prepare s from '$qry';
execute s;
execute s;
deallocate prepare s;
echo test $ver.2;
eval select * from ($qry) dt;
echo test $ver.3;
eval create view v as $qry;
select * from v;
select * from v;
drop view v;
echo test $ver.4;
eval with cte as ($qry) select * from cte;
echo test $ver.5;
eval create procedure p() $qry;
call p();
call p();
drop procedure p;

# ---- cross-check: every method must return the same rows as method 0 ----
--let EVW_MARKER= __EVW_ROWS__
--let EVW_QRY= $qry
--let EVW_DB= `select database()`

--let $m= 0
while ($m <= 5)
{
--let EVW_METHOD= $m
--let EVW_OUT= $MYSQLTEST_VARDIR/tmp/evw_$m.tsv
--source include/evw_capture.inc
--inc $m
}

--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_1.tsv
--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_2.tsv
--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_3.tsv
--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_4.tsv
--diff_files $MYSQLTEST_VARDIR/tmp/evw_0.tsv $MYSQLTEST_VARDIR/tmp/evw_5.tsv

echo "END GROUP";
2 changes: 1 addition & 1 deletion mysql-test/main/features.test
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ create table t1 (a int);
insert into t1 values (2);
select (select a from t1 where t1.a=t2.a), a from t1 as t2;
drop table t1;
--replace_result 8 4
--replace_result 8 5
show status like "feature_subquery";

--echo #
Expand Down
4 changes: 1 addition & 3 deletions mysql-test/main/having_cond_pushdown.test
Original file line number Diff line number Diff line change
Expand Up @@ -1451,11 +1451,9 @@ DROP TABLE t1,t2;

CREATE TABLE t1 (i int NOT NULL);
SELECT * FROM t1 GROUP BY i HAVING i IN ( i IS NULL);
#dublicate warning
--disable_view_protocol
#duplicate warning
SELECT * FROM t1 GROUP BY i HAVING i IN ( i IS NULL AND 'x' = 0);
SELECT * FROM t1 GROUP BY i HAVING i='1' IN ( i IS NULL AND 'x' = 0);
--enable_view_protocol
DROP TABLE t1;

--echo #
Expand Down
Loading