From: Peter Rabbitson Date: Sat, 25 Dec 2010 03:10:45 +0000 (+0100) Subject: Only add a group_by to a complex prefetch if a non-selecting multi-join is detected X-Git-Tag: v0.08125~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=887a0aefb7a00e6b1ad3265747a1af0d1fd64e5d Only add a group_by to a complex prefetch if a non-selecting multi-join is detected --- diff --git a/Changes b/Changes index d1bd079..132c4e5 100644 --- a/Changes +++ b/Changes @@ -33,6 +33,7 @@ Revision history for DBIx::Class - Missing dependency check in t/60core.t (RT#62635) - Fix regressions in IC::DT registration logic - Fix regression in select-associated bind value handling (RT#61025) + - Simplify SQL generated by some LIMITed prefetching queries - Fix infinite loops on old perls with a recent Try::Tiny - Improve "fork()" on Win32 by reimplementing a more robust DBIC thread support (still problematic, pending a DBI fix) diff --git a/lib/DBIx/Class/Storage/DBIHacks.pm b/lib/DBIx/Class/Storage/DBIHacks.pm index fd1bde5..41ca371 100644 --- a/lib/DBIx/Class/Storage/DBIHacks.pm +++ b/lib/DBIx/Class/Storage/DBIHacks.pm @@ -115,12 +115,19 @@ sub _adjust_select_args_for_complex_prefetch { group_by => ['dummy'], %$inner_attrs, }); - # if a multi-type join was needed in the subquery - add a group_by to simulate the - # collapse in the subq + my $inner_aliastypes = + $self->_resolve_aliastypes_from_select_args( $inner_from, $inner_select, $where, $inner_attrs ); + + # if a multi-type non-selecting (only restricting) join was needed in the subquery + # add a group_by to simulate the collapse in the subq if ( ! $inner_attrs->{group_by} and - first { ! $_->[0]{-is_single} } (@{$inner_from}[1 .. $#$inner_from]) + first { + $inner_aliastypes->{restricting}{$_} + and + ! $inner_aliastypes->{selecting}{$_} + } ( keys %{$inner_aliastypes->{multiplying}||{}} ) ) { $inner_attrs->{group_by} = $self->_group_over_selection ( $inner_from, $inner_select, $inner_attrs->{order_by} diff --git a/t/prefetch/o2m_o2m_order_by_with_limit.t b/t/prefetch/o2m_o2m_order_by_with_limit.t index c77530a..4aead92 100644 --- a/t/prefetch/o2m_o2m_order_by_with_limit.t +++ b/t/prefetch/o2m_o2m_order_by_with_limit.t @@ -34,7 +34,6 @@ is_same_sql_bind( JOIN cd cds_unordered ON cds_unordered.artist = me.artistid WHERE ( me.rank = ? ) - GROUP BY cds_unordered.cdid, cds_unordered.artist, cds_unordered.title, cds_unordered.year, cds_unordered.genreid, cds_unordered.single_track, me.name, me.artistid ORDER BY me.name ASC, me.artistid DESC LIMIT 3 OFFSET 3