1
# Copyright (c) 2008, 2011 Oracle and/or its affiliates. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::Transform::InlineVirtualColumns;
21
@ISA = qw(GenTest GenTest::Transform);
26
use GenTest::Transform;
27
use GenTest::Constants;
29
my $global_inlines = 0;
32
my ($class, $query, $executor) = @_;
34
return STATUS_WONT_HANDLE if $query !~ m{\s*SELECT}sio;
38
my $dbh = $executor->dbh();
39
my ($table_name) = $query =~ m{FROM (.*?)[ ^]}sio;
41
my ($foo, $table_create) = $dbh->selectrow_array("SHOW CREATE TABLE $table_name");
43
foreach my $create_row (split("\n", $table_create)) {
44
next if $create_row !~ m{ VIRTUAL}sio;
45
my ($column_name, $column_def) = $create_row =~ m{`(.*)` [^ ]*? AS (.*) VIRTUAL}sio;
46
$virtual_columns{$column_name} = $column_def;
49
foreach my $virtual_column (keys %virtual_columns) {
50
my $inlines = $query =~ s{$virtual_column}{$virtual_columns{$virtual_column}}sgi;
51
$global_inlines = $global_inlines + $inlines;
54
return $query." /* TRANSFORM_OUTCOME_UNORDERED_MATCH */";
58
say("[Statistics]: InlineVirtualColumns Transformer inlined $global_inlines expressions") if rqg_debug();