Broke up the prefetch tests into their own directory
[dbsrgits/DBIx-Class.git] / t / prefetch / rows_bug.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();
13my $no_prefetch = $schema->resultset('Artist')->search(
25cac750 14 undef,
15 { rows => 3 }
a04af85f 16);
17
18my $use_prefetch = $schema->resultset('Artist')->search(
25cac750 19 undef,
20 {
21 prefetch => 'cds',
22 rows => 3
23 }
a04af85f 24);
25
26my $no_prefetch_count = 0;
27my $use_prefetch_count = 0;
28
29is($no_prefetch->count, $use_prefetch->count, '$no_prefetch->count == $use_prefetch->count');
30
31TODO: {
25cac750 32 local $TODO = "This is a difficult bug to fix, workaround is not to use prefetch with rows";
33 $no_prefetch_count++ while $no_prefetch->next;
34 $use_prefetch_count++ while $use_prefetch->next;
35 is(
36 $no_prefetch_count,
37 $use_prefetch_count,
38 "manual row count confirms consistency"
39 . " (\$no_prefetch_count == $no_prefetch_count, "
40 . " \$use_prefetch_count == $use_prefetch_count)"
41 );
a04af85f 42}
25cac750 43
44__END__
45The fix is to, when using prefetch, take the query and put it into a subquery
46joined to the tables we're prefetching from. This might result in the same
47table being joined once in the main subquery and once in the main query. This
48may actually resolve other, unknown edgecase bugs. It is also the right way
49to do prefetching. Optimizations can come later.
50
51This means that:
52 $foo_rs->search(
53 { ... },
54 {
55 prefetch => 'bar',
56 ...
57 },
58 );
59
60becomes:
61 my $temp = $foo_rs->search(
62 { ... },
63 {
64 join => 'bar',
65 ...
66 },
67 );
68 $foo_rs->storage->schema->resultset('foo')->search(
69 undef,
70 {
71 from => [
72 { me => $temp->as_query },
73 ],
74 prefetch => 'bar',
75 },
76 );
77
78Problem:
79 * The prefetch->join change needs to happen ONLY IF there are conditions
80 that depend on bar being joined.