File: cancel_big_fetch.pl

package info (click to toggle)
libdbd-odbc-perl 1.61-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,424 kB
  • sloc: perl: 8,928; ansic: 6,456; makefile: 33; sql: 8
file content (54 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# $Id$
# demonstrates that not fetching all of a result-set makes can make
# a difference. More recent MS SQL Server drivers are better at this so don't
# be surprised if this shows no difference between the 2 variations.
# However, in the past, cancelling a big select when you have not selected
# all rows has made a huge difference as MS SQL Server sees the cancel and
# stops sending the result-set.
use DBI;
use strict;
use warnings;
use Benchmark;
use Data::Dumper;

my $h = DBI->connect();

if (@ARGV) {
    local $h->{PrintError} = 0;
    eval {
        $h->do(q/drop table mjebig/);
    };
    $h->do(q/create table mjebig(a varchar(255))/);
    $h->begin_work;             # quicker than autocommit
    my $val = 'a' x 255;
    my $s = $h->prepare(q/insert into mjebig values(?)/);
    foreach (1..100000) {
        $s->execute($val);
    }
    $h->commit;
}

sub one
{
    my $s = $h->prepare(q/select * from mjebig/);
    $s->execute;
    $s->fetch;
    $s = undef;
}

sub two
{
    my $s = $h->prepare(q/select * from mjebig/);
    $s->execute;
    $s->fetch;
    my $x = $s->cancel;
    #print Dumper(\$x), "\n";
    $s = undef;
}

timethese(1000, {
    'without_cancel' => sub{one()},
    'with_cancel' => sub{two()}
   });