~percona-toolkit-dev/percona-toolkit/fix-1156867-pt-stalk-show-function-name

« back to all changes in this revision

Viewing changes to t/lib/QueryReview.t

  • Committer: Daniel Nichter
  • Date: 2013-03-09 17:24:56 UTC
  • mfrom: (530.3.18 clean-up-pqd-2.2)
  • Revision ID: daniel@percona.com-20130309172456-h0xhi9as8y1hsc0t
Merge clean-up-pqd-2.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
use TableParser;
18
18
use Quoter;
19
19
use SlowLogParser;
20
 
use OptionParser;
21
20
use DSNParser;
22
21
use Sandbox;
23
22
use PerconaTest;
29
28
if ( !$dbh ) {
30
29
   plan skip_all => "Cannot connect to sandbox master";
31
30
}
32
 
else {
33
 
   plan tests => 9;
34
 
}
35
31
 
36
32
$sb->create_dbs($dbh, ['test']);
37
33
$sb->load_file('master', "t/lib/samples/query_review.sql");
40
36
my $lp = new SlowLogParser;
41
37
my $q  = new Quoter();
42
38
my $tp = new TableParser(Quoter => $q);
43
 
my $opt_parser = new OptionParser( description => 'hi' );
 
39
 
44
40
my $tbl_struct = $tp->parse(
45
41
   $tp->get_create_table($dbh, 'test', 'query_review'));
46
42
 
146
142
   [qw(first_seen last_seen reviewed_by reviewed_on comments)],
147
143
   'review columns');
148
144
 
149
 
# ##############################################################################
150
 
# Test review history stuff
151
 
# ##############################################################################
152
 
my $pat = $opt_parser->read_para_after("$trunk/bin/pt-query-digest",
153
 
   qr/MAGIC_history_cols/);
154
 
$pat =~ s/\s+//g;
155
 
my $create_table = $opt_parser->read_para_after(
156
 
   "$trunk/bin/pt-query-digest", qr/MAGIC_create_review_history/);
157
 
$create_table =~ s/query_review_history/test.query_review_history/;
158
 
$dbh->do($create_table);
159
 
my $hist_struct = $tp->parse(
160
 
   $tp->get_create_table($dbh, 'test', 'query_review_history'));
161
 
 
162
 
$qv->set_history_options(
163
 
   table      => 'test.query_review_history',
164
 
   quoter     => $q,
165
 
   tbl_struct => $hist_struct,
166
 
   col_pat    => qr/^(.*?)_($pat)$/,
167
 
);
168
 
 
169
 
$qv->set_review_history(
170
 
   'foo',
171
 
   'foo sample',
172
 
   Query_time => {
173
 
      pct    => 1/3,
174
 
      sum    => '0.000682',
175
 
      cnt    => 1,
176
 
      min    => '0.000682',
177
 
      max    => '0.000682',
178
 
      avg    => '0.000682',
179
 
      median => '0.000682',
180
 
      stddev => 0,
181
 
      pct_95 => '0.000682',
182
 
   },
183
 
   ts => {
184
 
      min => '090101 12:39:12',
185
 
      max => '090101 13:19:12',
186
 
      cnt => 1,
187
 
   },
188
 
);
189
 
 
190
 
$res = $dbh->selectall_arrayref(
191
 
   'SELECT Lock_time_median, Lock_time_stddev, Query_time_sum, checksum, Rows_examined_stddev, ts_cnt, sample, Rows_examined_median, Rows_sent_min, Rows_examined_min, Rows_sent_sum,  Query_time_min, Query_time_pct_95, Rows_examined_sum, Rows_sent_stddev, Rows_sent_pct_95, Query_time_max, Rows_examined_max, Query_time_stddev, Rows_sent_median, Lock_time_pct_95, ts_min, Lock_time_min, Lock_time_max, ts_max, Rows_examined_pct_95 ,Rows_sent_max, Query_time_median, Lock_time_sum
192
 
   FROM test.query_review_history',
193
 
   { Slice => {} });
194
 
is_deeply(
195
 
   $res,
196
 
   [  {  checksum          => '17145033699835028696',
197
 
         sample            => 'foo sample',
198
 
         ts_min            => '2009-01-01 12:39:12',
199
 
         ts_max            => '2009-01-01 13:19:12',
200
 
         ts_cnt            => 1,
201
 
         Query_time_sum    => '0.000682',
202
 
         Query_time_min    => '0.000682',
203
 
         Query_time_max    => '0.000682',
204
 
         Query_time_median => '0.000682',
205
 
         Query_time_stddev => 0,
206
 
         Query_time_pct_95 => '0.000682',
207
 
         Lock_time_sum        => undef,
208
 
         Lock_time_min        => undef,
209
 
         Lock_time_max        => undef,
210
 
         Lock_time_pct_95     => undef,
211
 
         Lock_time_stddev     => undef,
212
 
         Lock_time_median     => undef,
213
 
         Rows_sent_sum        => undef,
214
 
         Rows_sent_min        => undef,
215
 
         Rows_sent_max        => undef,
216
 
         Rows_sent_pct_95     => undef,
217
 
         Rows_sent_stddev     => undef,
218
 
         Rows_sent_median     => undef,
219
 
         Rows_examined_sum    => undef,
220
 
         Rows_examined_min    => undef,
221
 
         Rows_examined_max    => undef,
222
 
         Rows_examined_pct_95 => undef,
223
 
         Rows_examined_stddev => undef,
224
 
         Rows_examined_median => undef,
225
 
      },
226
 
   ],
227
 
   'Review history information is in the DB',
228
 
);
229
 
 
230
 
eval {
231
 
   $qv->set_review_history(
232
 
      'foo',
233
 
      'foo sample',
234
 
      ts => {
235
 
         min => undef,
236
 
         max => undef,
237
 
         cnt => 1,
238
 
      },
239
 
   );
240
 
};
241
 
is($EVAL_ERROR, '', 'No error on undef ts_min and ts_max');
242
 
 
243
 
# #############################################################################
244
 
# Issue 1265: mk-query-digest --review-history table with minimum 2 columns
245
 
# #############################################################################
246
 
$dbh->do('truncate table test.query_review');
247
 
$dbh->do('drop table test.query_review_history');
248
 
# mqd says "The table must have at least the following columns:"
249
 
my $min_tbl = "CREATE TABLE query_review_history (
250
 
  checksum     BIGINT UNSIGNED NOT NULL,
251
 
  sample       TEXT NOT NULL
252
 
)";
253
 
$dbh->do($min_tbl);
254
 
 
255
 
$hist_struct = $tp->parse(
256
 
   $tp->get_create_table($dbh, 'test', 'query_review_history'));
257
 
$qv->set_history_options(
258
 
   table      => 'test.query_review_history',
259
 
   quoter     => $q,
260
 
   tbl_struct => $hist_struct,
261
 
   col_pat    => qr/^(.*?)_($pat)$/,
262
 
);
263
 
eval {
264
 
   $qv->set_review_history(
265
 
      'foo',
266
 
      'foo sample',
267
 
      Query_time => {
268
 
         pct    => 1/3,
269
 
         sum    => '0.000682',
270
 
         cnt    => 1,
271
 
         min    => '0.000682',
272
 
         max    => '0.000682',
273
 
         avg    => '0.000682',
274
 
         median => '0.000682',
275
 
         stddev => 0,
276
 
         pct_95 => '0.000682',
277
 
      },
278
 
      ts => {
279
 
         min => '090101 12:39:12',
280
 
         max => '090101 13:19:12',
281
 
         cnt => 1,
282
 
      },
283
 
   );
284
 
};
285
 
is(
286
 
   $EVAL_ERROR,
287
 
   "",
288
 
   "Minimum 2-column review history table (issue 1265)"
289
 
);
290
 
 
291
145
# #############################################################################
292
146
# Done.
293
147
# #############################################################################
303
157
);
304
158
$sb->wipe_clean($dbh);
305
159
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
 
160
done_testing;
306
161
exit;