Added comment to describe the proposed fix in the test
[dbsrgits/DBIx-Class.git] / t / 98rows_prefetch.t
CommitLineData
a04af85f 1# Test to ensure we get a consistent result set wether or not we use the
2# prefetch option in combination rows (LIMIT).
3use strict;
4use warnings;
5
6use Test::More;
7use lib qw(t/lib);
8use DBICTest;
9
10plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 2);
11
12my $schema = DBICTest->init_schema();
ff57f45b 13$schema->storage->debug(1);
a04af85f 14my $no_prefetch = $schema->resultset('Artist')->search(
15 undef,
16 { rows => 3 }
17);
18
19my $use_prefetch = $schema->resultset('Artist')->search(
20 undef,
21 {
22 prefetch => 'cds',
23 rows => 3
24 }
25);
26
27my $no_prefetch_count = 0;
28my $use_prefetch_count = 0;
29
30is($no_prefetch->count, $use_prefetch->count, '$no_prefetch->count == $use_prefetch->count');
31
ff57f45b 32# The fix is to, when using prefetch, take the query and put it into a subquery
33# joined to the tables we're prefetching from. This might result in the same
34# table being joined once in the main subquery and once in the main query. This
35# may actually resolve other, unknown edgecase bugs. It is also the right way
36# to do prefetching. Optimizations can come later.
37
a04af85f 38TODO: {
39 local $TODO = "This is a difficult bug to fix, workaround is not to use prefetch with rows";
40 $no_prefetch_count++ while $no_prefetch->next;
41 $use_prefetch_count++ while $use_prefetch->next;
42 is(
43 $no_prefetch_count,
44 $use_prefetch_count,
45 "manual row count confirms consistency"
46 . " (\$no_prefetch_count == $no_prefetch_count, "
47 . " \$use_prefetch_count == $use_prefetch_count)"
48 );
49}