~percona-dev/percona-server/5.1.56-expand_pass_corrupt_table

« back to all changes in this revision

Viewing changes to HandlerSocket-Plugin-for-MySQL/regtest/test_01_lib/test19.pl

  • Committer: Alexey Kopytov
  • Date: 2011-04-20 08:52:35 UTC
  • mfrom: (222.1.3 5.1.56-tmp)
  • Revision ID: akopytov@gmail.com-20110420085235-vh7g8vx04y4m6cno
MergeĀ fromĀ lp:percona-server

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
# vim:sw=2:ai
 
4
 
 
5
# test for filters
 
6
 
 
7
BEGIN {
 
8
        push @INC, "../common/";
 
9
};
 
10
 
 
11
use strict;
 
12
use warnings;
 
13
use bigint;
 
14
use hstest;
 
15
 
 
16
my $numeric_types = [
 
17
        [ 'TINYINT', -128, 127 ],
 
18
        [ 'TINYINT UNSIGNED', 0, 255 ],
 
19
        [ 'SMALLINT', -32768, 32768 ],
 
20
        [ 'SMALLINT UNSIGNED', 0, 65535 ],
 
21
        [ 'MEDIUMINT', -8388608, 8388607 ],
 
22
        [ 'MEDIUMINT UNSIGNED', 0, 16777215 ],
 
23
        [ 'INT', -2147483648, 2147483647 ],
 
24
        [ 'INT UNSIGNED', 0, 4294967295 ],
 
25
        [ 'BIGINT', -9223372036854775808, 9223372036854775807 ],
 
26
        [ 'BIGINT UNSIGNED', 0, 18446744073709551615 ],
 
27
        [ 'FLOAT', -32768, 32768 ],
 
28
        [ 'DOUBLE', -2147483648, 2147483647 ],
 
29
];
 
30
my $datetime_types = [
 
31
        [ 'DATE', '0000-00-00', '2011-01-01', '9999-12-31' ],
 
32
        [ 'DATETIME', 0, '2011-01-01 18:30:25' ],
 
33
        [ 'TIME', 0, '18:30:25' ],
 
34
        [ 'YEAR(4)', 1901, 2011, 2155 ],
 
35
        # [ 'TIMESTAMP', 0, 999999999 ],   # DOES NOT WORK YET
 
36
];
 
37
my $string_types = [
 
38
        [ 'CHAR(10)', undef, 1, 2, 5, 10 ],
 
39
        [ 'VARCHAR(10)', undef, 1, 2, 5, 10 ],
 
40
        [ 'BINARY(10)', undef, 1, 2, 5, 10 ],
 
41
        [ 'VARBINARY(10)', undef, 1, 2, 5, 10 ],
 
42
        [ 'CHAR(255)', undef, 1, 2, 5, 10, 100, 200, 255 ],
 
43
        [ 'VARCHAR(255)', undef, 1, 2, 5, 10, 100, 200, 255 ],
 
44
        [ 'VARCHAR(511)', undef, 1, 2, 5, 10, 100, 200, 511 ],
 
45
        [ 'LONGTEXT', 500, 1, 2, 5, 10, 100, 200, 511 ], # NOT SUPPORTED YET
 
46
        [ 'LONGBLOB', 500, 1, 2, 5, 10, 100, 200, 511 ], # NOT SUPPORTED YET
 
47
#       [ 'VARCHAR(4096)', 500, 1, 2, 5, 10, 100, 200, 255, 256, 4095 ],
 
48
#       [ 'VARCHAR(16383)', 500, 1, 2, 5, 10, 100, 200, 255, 256, 4095, 4096, 16383 ],
 
49
#       [ 'VARBINARY(16383)', 500, 1, 2, 5, 10, 100, 200, 255, 256, 4095, 4096, 16383 ],
 
50
];
 
51
 
 
52
for my $rec (@$numeric_types) {
 
53
  my ($typ, $minval, $maxval) = @$rec;
 
54
  my @vals = ();
 
55
  push(@vals, 0);
 
56
  push(@vals, $maxval);
 
57
  if ($minval != 0) {
 
58
    push(@vals, $minval);
 
59
  }
 
60
  my $v1 = $minval;
 
61
  my $v2 = $maxval;
 
62
  for (my $i = 0; $i < 3; ++$i) {
 
63
    $v1 /= 3;
 
64
    $v2 /= 3;
 
65
    push(@vals, int($v1));
 
66
    push(@vals, int($v2));
 
67
  }
 
68
  my %vm = map { $_ => 1 } @vals;
 
69
  @vals = sort { $a <=> $b } keys %vm;
 
70
  push(@vals, undef);
 
71
  test_one($typ, undef, \@vals);
 
72
}
 
73
 
 
74
for my $rec (@$datetime_types) {
 
75
  my ($typ, @vals) = @$rec;
 
76
  push(@vals, undef);
 
77
  test_one($typ, undef, \@vals);
 
78
}
 
79
 
 
80
for my $rec (@$string_types) {
 
81
  my ($typ, $keylen, @vs) = @$rec;
 
82
  my @vals = ();
 
83
  srand(999);
 
84
  for my $len (@vs) {
 
85
    my $s = '';
 
86
    my @arr = ();
 
87
    # print "$len 1\n";
 
88
    for (my $i = 0; $i < $len; ++$i) {
 
89
      my $v = int(rand(10));
 
90
      $arr[$i] = chr(65 + $v);
 
91
    }
 
92
    # print "2\n";
 
93
    push(@vals, join('', @arr));
 
94
  }
 
95
  push(@vals, undef);
 
96
  test_one($typ, $keylen, \@vals);
 
97
}
 
98
 
 
99
my $hs;
 
100
 
 
101
sub test_one {
 
102
  my ($typ, $keylen, $values) = @_;
 
103
  print "\n$typ -------------------------------------------------\n\n";
 
104
  my $keylen_str = '';
 
105
  if (defined($keylen)) {
 
106
    $keylen_str = "($keylen)";
 
107
  }
 
108
  my $dbh = hstest::init_testdb();
 
109
  my $table = 'hstesttbl';
 
110
  my $tablesize = 3;
 
111
  $dbh->do(
 
112
    "create table $table " .
 
113
    "(k1 int not null, k2 int not null, " .
 
114
    "v1 int not null, v2 $typ default null, " .
 
115
    "primary key (k1, k2) ) engine = innodb");
 
116
  my $sth = $dbh->prepare("insert into $table values (?,?,?,?)");
 
117
  for (my $i = 0; $i < $tablesize; ++$i) {
 
118
    my $j = 0;
 
119
    for my $v (@$values) {
 
120
      $sth->execute($i, $j, $i, $v);
 
121
      ++$j;
 
122
    }
 
123
  }
 
124
  $hs = hstest::get_hs_connection(undef, 9999);
 
125
  my $dbname = $hstest::conf{dbname};
 
126
  $hs->open_index(1, $dbname, $table, '', 'k1,k2,v1,v2', 'v2');
 
127
  my $minval = $values->[0];
 
128
  # select * ... where (k1, k2) >= ('', $minval)
 
129
  exec_multi(
 
130
    4, "FILTER($typ) NO FILTER",
 
131
    [ 1, '>=', [ '', $minval ], 1000, 0 ]
 
132
  );
 
133
  for my $v (@$values) {
 
134
    my $vstr = defined($v) ? $v : 'NULL';
 
135
    # select * ... where (k1, k2) >= ('', $minval) and v2 = $v
 
136
    exec_multi(
 
137
      4, "FILTER($typ) v2 = $vstr",
 
138
      [ 1, '>=', [ '', $minval ], 1000, 0, undef, undef, [ [ 'F', '=', 0, $v ] ] ]
 
139
    );
 
140
    # select * ... where (k1, k2) >= ('', $minval) and v2 != $v
 
141
    exec_multi(
 
142
      4, "FILTER($typ) v2 != $vstr",
 
143
      [ 1, '>=', [ '', $minval ], 1000, 0, undef, undef, [ [ 'F', '!=', 0, $v ] ] ]
 
144
    );
 
145
    # select * ... where (k1, k2) >= ('', $minval) and v2 >= $v
 
146
    exec_multi(
 
147
      4, "FILTER($typ) v2 >= $vstr",
 
148
      [ 1, '>=', [ '', $minval ], 1000, 0, undef, undef, [ [ 'F', '>=', 0, $v ] ] ]
 
149
    );
 
150
    # select * ... where (k1, k2) >= ('', $minval) and v2 < $v
 
151
    exec_multi(
 
152
      4, "FILTER($typ) v2 < $vstr",
 
153
      [ 1, '>=', [ '', $minval ], 1000, 0, undef, undef, [ [ 'F', '<', 0, $v ] ] ]
 
154
    );
 
155
    # select * ... where (k1, k2) >= ('', $minval) and v2 > $v
 
156
    exec_multi(
 
157
      4, "FILTER($typ) v2 > $vstr",
 
158
      [ 1, '>=', [ '', $minval ], 1000, 0, undef, undef, [ [ 'F', '>', 0, $v ] ] ]
 
159
    );
 
160
    # select * ... where (k1, k2) >= ('', $minval) and v2 <= $v
 
161
    exec_multi(
 
162
      4, "FILTER($typ) v2 <= $vstr",
 
163
      [ 1, '>=', [ '', $minval ], 1000, 0, undef, undef, [ [ 'F', '<=', 0, $v ] ] ]
 
164
    );
 
165
  }
 
166
  undef $hs;
 
167
}
 
168
 
 
169
sub exec_multi {
 
170
  my $width = shift(@_);
 
171
  my $mess = shift(@_);
 
172
  print "$mess\n";
 
173
  my $mres = $hs->execute_multi(\@_);
 
174
  for my $res (@$mres) {
 
175
    my $code = shift(@$res);
 
176
    my $nrows = $code == 0 ? scalar(@$res) / $width : 0;
 
177
    print "code=$code rows=$nrows\n";
 
178
    my $i = 0;
 
179
    for my $fld (@$res) {
 
180
      $fld = 'NULL' if !defined($fld);
 
181
      print "[$fld]";
 
182
      if (++$i >= $width) {
 
183
        print "\n";
 
184
        $i = 0;
 
185
      }
 
186
    }
 
187
    print "\n";
 
188
  }
 
189
}
 
190