2
# This program is free software; you can redistribute it and/or modify
3
# it under the terms of the GNU General Public License as published by
4
# the Free Software Foundation; version 2 of the License.
6
# This program is distributed in the hope that it will be useful, but
7
# WITHOUT ANY WARRANTY; without even the implied warranty of
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9
# General Public License for more details.
11
# You should have received a copy of the GNU General Public License
12
# along with this program; if not, write to the Free Software
13
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
17
package GenTest::Validator::DML;
20
@ISA = qw(GenTest::Validator GenTest);
25
use GenTest::Comparator;
26
use GenTest::Constants;
28
use GenTest::Validator;
31
my $matched_rows_count = 0;
34
my ($validator, $executors, $results) = @_;
35
my $executor = $executors->[0];
36
my $dbh = $executor->dbh();
37
my $orig_result = $results->[0];
38
my $orig_query = $orig_result->query();
40
return STATUS_WONT_HANDLE if $orig_query !~ m{INSERT|UPDATE|DELETE}sio;
41
return STATUS_WONT_HANDLE if $orig_result->status() != STATUS_OK;
44
my $join_cache_level = $dbh->selectrow_array('SELECT @@join_cache_level');
45
my $optimizer_switch = $dbh->selectrow_array('SELECT @@optimizer_switch');
46
my $optimizer_use_mrr = $dbh->selectrow_array('SELECT @@optimizer_use_mrr');
48
$dbh->do("SET SESSION join_cache_level = 0");
49
$dbh->do("SET SESSION optimizer_switch = 'index_merge=off,index_merge_union=off,index_merge_sort_union=off,index_merge_intersection=off,index_merge_sort_intersection=off,index_condition_pushdown=off,firstmatch=off,loosescan=off,materialization=off,semijoin=off,partial_match_rowid_merge=off,partial_match_table_scan=off,subquery_cache=off,mrr_sort_keys=off,join_cache_incremental=off,join_cache_hashed=off,join_cache_bka=off,table_elimination=off'");
50
$dbh->do("SET SESSION optimizer_use_mrr = 'disable'");
52
$dbh->do("START TRANSACTION");
53
my $oracle_result = $executor->execute($orig_query);
56
$dbh->do("SET SESSION join_cache_level = $join_cache_level");
57
$dbh->do("SET SESSION optimizer_switch = '$optimizer_switch'");
58
$dbh->do("SET SESSION optimizer_use_mrr = '$optimizer_use_mrr'");
60
$matched_rows_count = $matched_rows_count + $oracle_result->matchedRows();
62
if ($orig_result->status() != $oracle_result->status()) {
63
say("Query: $orig_query; had a different STATUS when executed without optimizations ('".$orig_result->errstr()."' vs. '".$oracle_result->errstr()."').");
64
return STATUS_ERROR_MISMATCH;
65
} elsif (int($orig_result->affectedRows()) != int($oracle_result->affectedRows())) {
66
say("Query: $orig_query; affected a different number of rows when run with no optimizations (".$orig_result->affectedRows()." vs. ".$oracle_result->affectedRows().").");
67
return STATUS_LENGTH_MISMATCH;
68
} elsif ($orig_result->matchedRows() != $oracle_result->matchedRows()) {
69
say("Query: $orig_query; matched a different number of rows when run with no optimizations (".$orig_result->matchedRows()." vs. ".$oracle_result->matchedRows().").");
70
return STATUS_LENGTH_MISMATCH;
71
} elsif ($orig_result->changedRows() != $oracle_result->changedRows()) {
72
say("Query: $orig_query; changed a different number of rows when run with no optimizations (".$orig_result->changedRows()." vs. ".$oracle_result->changedRows().").");
73
return STATUS_LENGTH_MISMATCH;
80
say("Total matched_rows reported by the DML statements: $matched_rows_count.");