From: Peter Rabbitson Date: Thu, 29 Mar 2012 02:53:28 +0000 (+0200) Subject: Simplify 3-query skimming limits to omit the last redundant limit X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1b07861d3456bd1695dd7e0c43a07c7efe06cdb2;p=dbsrgits%2FDBIx-Class-Historic.git Simplify 3-query skimming limits to omit the last redundant limit --- diff --git a/lib/DBIx/Class/SQLMaker/LimitDialects.pm b/lib/DBIx/Class/SQLMaker/LimitDialects.pm index dd6bc6d..dde627b 100644 --- a/lib/DBIx/Class/SQLMaker/LimitDialects.pm +++ b/lib/DBIx/Class/SQLMaker/LimitDialects.pm @@ -445,8 +445,7 @@ sub _Top { $lim->{order_by_middle}, ) if $offset; - $sql = sprintf ('SELECT TOP %u %s FROM ( %s ) %s %s', - $rows, + $sql = sprintf ('SELECT %s FROM ( %s ) %s %s', $lim->{selection_outer}, $sql, $lim->{quoted_rs_alias}, @@ -502,12 +501,11 @@ sub _FetchFirst { ) if $offset; - $sql = sprintf ('SELECT %s FROM ( %s ) %s %s FETCH FIRST %u ROWS ONLY', + $sql = sprintf ('SELECT %s FROM ( %s ) %s %s', $lim->{selection_outer}, $sql, $lim->{quoted_rs_alias}, $lim->{order_by_requested}, - $rows, ) if $offset and ( $lim->{order_by_requested} or $lim->{selection_middle} ne $lim->{selection_outer} ); diff --git a/t/sqlmaker/limit_dialects/fetch_first.t b/t/sqlmaker/limit_dialects/fetch_first.t index 3616d6c..fcb08d5 100644 --- a/t/sqlmaker/limit_dialects/fetch_first.t +++ b/t/sqlmaker/limit_dialects/fetch_first.t @@ -141,7 +141,6 @@ for my $ord_set ( FETCH FIRST 2 ROWS ONLY ) me ORDER BY $ord_set->{order_req} - FETCH FIRST 2 ROWS ONLY )", [ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'source' } => 'Library' ] ], @@ -169,7 +168,6 @@ is_same_sql_bind ( FETCH FIRST 2 ROWS ONLY ) me ORDER BY ORDER__BY__1 - FETCH FIRST 2 ROWS ONLY ) me JOIN owners owner ON owner.id = me.owner WHERE ( source = ? ) diff --git a/t/sqlmaker/limit_dialects/toplimit.t b/t/sqlmaker/limit_dialects/toplimit.t index 31a8b09..8ac32fc 100644 --- a/t/sqlmaker/limit_dialects/toplimit.t +++ b/t/sqlmaker/limit_dialects/toplimit.t @@ -166,8 +166,7 @@ for my $ord_set ( is_same_sql_bind( $books_45_and_owners->search ({}, {order_by => $ord_set->{order_by}})->as_query, - "(SELECT TOP 2 - id, source, owner, price, owner__id, owner__name + "(SELECT id, source, owner, price, owner__id, owner__name FROM ( SELECT TOP 2 id, source, owner, price, owner__id, owner__name$o_sel @@ -193,7 +192,7 @@ is_same_sql_bind ( $books_45_and_owners->search ({}, { group_by => 'title', order_by => 'title' })->as_query, '(SELECT me.id, me.source, me.owner, me.price, owner.id, owner.name FROM ( - SELECT TOP 2 id, source, owner, price, ORDER__BY__1 AS title + SELECT id, source, owner, price, ORDER__BY__1 AS title FROM ( SELECT TOP 2 id, source, owner, price, ORDER__BY__1