From 4df1400e9a42e3e19f143151de2c8ba5865cb553 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson Date: Sat, 9 Mar 2013 19:41:41 +0100 Subject: [PATCH] There is no point of ordering the insides of a complex prefetch without a limit --- Changes | 2 ++ lib/DBIx/Class/Storage/DBIHacks.pm | 8 ++++++-- t/prefetch/grouped.t | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index 995dc25b4..24dd469b0 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,8 @@ Revision history for DBIx::Class invalid relationship graph - Warn in case of iterative collapse being upgraded to an eager cursor slurp + - No longer order the insides of a complex prefetch subquery, + unless required to satisfy a limit * Fixes - Properly consider unselected order_by criteria during complex diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index e5a0d83f4..75a8fb287 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -85,8 +85,12 @@ sub _adjust_select_args_for_complex_prefetch { my $inner_attrs = { %$attrs }; delete $inner_attrs->{$_} for qw/for collapse _prefetch_selector_range select as/; - # if the user did not request it, there is no point using it inside - delete $inner_attrs->{order_by} if delete $inner_attrs->{_order_is_artificial}; + # there is no point of ordering the insides if there is no limit + delete $inner_attrs->{order_by} if ( + delete $inner_attrs->{_order_is_artificial} + or + ! $inner_attrs->{rows} + ); # generate the inner/outer select lists # for inside we consider only stuff *not* brought in by the prefetch diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 40ac9238b..f5d56bbf0 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -224,7 +224,6 @@ for ($cd_rs->all) { SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track - ORDER BY cdid ) me LEFT JOIN tags tags ON tags.cd = me.cdid ORDER BY cdid