1 # Test to ensure we get a consistent result set wether or not we use the
2 # prefetch option in combination rows (LIMIT).
10 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 3);
12 my $schema = DBICTest->init_schema();
13 my $no_prefetch = $schema->resultset('Artist')->search(
18 my $use_prefetch = $schema->resultset('Artist')->search(
26 my $no_prefetch_count = 0;
27 my $use_prefetch_count = 0;
29 is($no_prefetch->count, $use_prefetch->count, '$no_prefetch->count == $use_prefetch->count');
31 $no_prefetch_count++ while $no_prefetch->next;
32 $use_prefetch_count++ while $use_prefetch->next;
36 "manual row count confirms consistency"
37 . " (\$no_prefetch_count == $no_prefetch_count, "
38 . " \$use_prefetch_count == $use_prefetch_count)"
41 $no_prefetch = $schema->resultset('Artist')->search(
46 $use_prefetch = $schema->resultset('Artist')->search(
54 my $prefetch_artist = $use_prefetch->first;
55 my $normal_artist = $no_prefetch->first;
58 $prefetch_artist->cds->count,
59 $normal_artist->cds->count,
60 "Count of child rel with prefetch + rows => 1 is right"
64 The fix is to, when using prefetch, take the query and put it into a subquery
65 joined to the tables we're prefetching from. This might result in the same
66 table being joined once in the main subquery and once in the main query. This
67 may actually resolve other, unknown edgecase bugs. It is also the right way
68 to do prefetching. Optimizations can come later.
80 my $temp = $foo_rs->search(
87 $foo_rs->storage->schema->resultset('foo')->search(
91 { me => $temp->as_query },
98 * The prefetch->join change needs to happen ONLY IF there are conditions
99 that depend on bar being joined.
100 * Count of child rel.
101 * How will this work when the $rs is further searched on? Those clauses
102 need to be added to the subquery, not the outer one. This is particularly
103 true if rows is added in the attribute later per the Pager.