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 => 2);
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');
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;
38 "manual row count confirms consistency"
39 . " (\$no_prefetch_count == $no_prefetch_count, "
40 . " \$use_prefetch_count == $use_prefetch_count)"
44 my $rs1 = $schema->resultset('Artist')->search(
49 warn ${$rs1->as_query}->[0], $/;
50 { my @x = $rs1->all; warn "$#x\n"; }
52 my $rs2 = $schema->resultset('Artist')->search(
61 warn ${$rs2->as_query}->[0], $/;
62 { my @x = $rs2->all; warn "$#x\n"; }
65 The fix is to, when using prefetch, take the query and put it into a subquery
66 joined to the tables we're prefetching from. This might result in the same
67 table being joined once in the main subquery and once in the main query. This
68 may actually resolve other, unknown edgecase bugs. It is also the right way
69 to do prefetching. Optimizations can come later.
81 my $temp = $foo_rs->search(
88 $foo_rs->storage->schema->resultset('foo')->search(
92 { me => $temp->as_query },
99 * The prefetch->join change needs to happen ONLY IF there are conditions
100 that depend on bar being joined.
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.