Why would order_by interfere with has many fetch?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why would order_by interfere with has many fetch?

Matija Grabnar
I have a hierarchical bunch of tables.
A has many B has many C.

I wanted to do a search of the form

   my $h = $hosts->search
     ({},
      {
       order_by => ['me.field_in_a'],
       join => {'bs' => 'cs'},
       prefetch => {'bs' => 'cs'},
      },
     );

But I get a warning:

DBIx::Class::ResultSet::_construct_results(): Unable to properly
collapse has_many results in iterator mode due to order criteria -
performed an eager cursor slurp underneath. Consider using ->all() instead

(The warning goes away if I comment out the prefetch).

Why? Surely, as long as the order of keys is the same as the hierarchy,
(i.e. A.field, B.field, C.field or even A.field1, A.field2, C.field) the
select with the sort should work just as well as the one without?

Am I missing something?





_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Why would order_by interfere with has many fetch?

Peter Rabbitson-2
On 08/08/2014 09:29 AM, Matija Grabnar wrote:

> I have a hierarchical bunch of tables.
> A has many B has many C.
>
> I wanted to do a search of the form
>
>    my $h = $hosts->search
>      ({},
>       {
>        order_by => ['me.field_in_a'],
>        join => {'bs' => 'cs'},
>        prefetch => {'bs' => 'cs'},
>       },
>      );
>
> But I get a warning:
>
> DBIx::Class::ResultSet::_construct_results(): Unable to properly
> collapse has_many results in iterator mode due to order criteria -
> performed an eager cursor slurp underneath. Consider using ->all() instead
>
> (The warning goes away if I comment out the prefetch).
>
> Why? Surely, as long as the order of keys is the same as the hierarchy,
> (i.e. A.field, B.field, C.field or even A.field1, A.field2, C.field) the
> select with the sort should work just as well as the one without?
>
> Am I missing something?
>

Please try the latest trial release (suitable to run in production), as
the problem above seems like an addressed bug:
https://metacpan.org/changes/release/RIBASUSHI/DBIx-Class-0.082700_05#L30

The 0.082700_05 is supposed to become stable in 20h or so, baring any
reports of issues by users like you.

You can get the dev version using any of the following methods:

HARNESS_OPTIONS=j4 cpan R/RI/RIBASUSHI/DBIx-Class-0.082700_05.tar.gz
   or
HARNESS_OPTIONS=j4 cpanm -v DBIx::Class@0.082700_05
   or by grabbing the tarball
http://cpan.metacpan.org/authors/id/R/RI/RIBASUSHI/DBIx-Class-0.082700_05.tar.gz

Cheers

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...