X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSQLAHacks.pm;h=ba892644f637a6a455768f81ee577c252f6a129a;hb=64c7c000587e6e6dccb9fc6330a66dcebd1f3695;hp=f99e0f7c2c4f03a855ec82c27c3b6514fcd8e826;hpb=618a0fe35811c50a6309d51b97765dede00b80e2;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index f99e0f7..ba89264 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -216,6 +216,16 @@ sub _Top { my ( $order_by_inner, $order_by_outer ) = $self->_order_directions($limit_order); my $order_by_requested = $self->_order_by ($req_order); + # generate the rest + delete $order->{$_} for qw/order_by _virtual_order_by/; + my $grpby_having = $self->_order_by ($order); + + # short circuit for counts - the ordering complexity is needless + if ($self->{_dbic_rs_attrs}{-for_count_only}) { + return "SELECT TOP $rows $inner_select $sql $grpby_having $order_by_outer"; + } + + # we can't really adjust the order_by columns, as introspection is lacking # resort to simple substitution for my $col (keys %outer_col_aliases) { @@ -227,12 +237,6 @@ sub _Top { $order_by_inner =~ s/\s+$col\s+/$col_aliases{$col}/g; } - - # generate the rest - delete $order->{$_} for qw/order_by _virtual_order_by/; - my $grpby_having = $self->_order_by ($order); - - my $inner_lim = $rows + $offset; $sql = "SELECT TOP $inner_lim $inner_select $sql $grpby_having $order_by_inner";