From: Peter Rabbitson Date: Thu, 21 May 2009 07:59:50 +0000 (+0000) Subject: Duh, no point of having ordered subqueries while counting, Debolaz++ X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6bf3e3b3fa88b45f33ff21ae38239c69bd14335c;p=dbsrgits%2FDBIx-Class-Historic.git Duh, no point of having ordered subqueries while counting, Debolaz++ --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index cf85311..7e59438 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1162,8 +1162,8 @@ sub _count_subq { # copy for the subquery, we need to do some adjustments to it too my $sub_attrs = { %$attrs }; - # these can not go in the subquery either - delete $sub_attrs->{$_} for qw/prefetch collapse select +select as +as columns +columns/; + # these can not go in the subquery, and there is no point of ordering it + delete $sub_attrs->{$_} for qw/prefetch collapse select +select as +as columns +columns order_by/; # force a group_by and the same set of columns (most databases require this) $sub_attrs->{columns} = $sub_attrs->{group_by} ||= [ map { "$attrs->{alias}.$_" } ($self->result_source->primary_columns) ]; diff --git a/t/count/prefetch.t b/t/count/prefetch.t index 7c9bf95..54f6c05 100644 --- a/t/count/prefetch.t +++ b/t/count/prefetch.t @@ -32,7 +32,7 @@ my $schema = DBICTest->init_schema(); is_same_sql_bind ( $sql, \@bind, - 'SELECT COUNT( * ) FROM (SELECT cds.cdid FROM artist me LEFT JOIN cd cds ON cds.artist = me.artistid LEFT JOIN track tracks ON tracks.cd = cds.cdid JOIN artist artist ON artist.artistid = cds.artist WHERE tracks.position = ? OR tracks.position = ? GROUP BY cds.cdid ORDER BY tracks.cd) count_subq', + 'SELECT COUNT( * ) FROM (SELECT cds.cdid FROM artist me LEFT JOIN cd cds ON cds.artist = me.artistid LEFT JOIN track tracks ON tracks.cd = cds.cdid JOIN artist artist ON artist.artistid = cds.artist WHERE tracks.position = ? OR tracks.position = ? GROUP BY cds.cdid) count_subq', [ qw/'1' '2'/ ], ); }