From: Peter Rabbitson Date: Sat, 3 Mar 2012 15:56:12 +0000 (+0100) Subject: Optimization - order only on lazy prefetch X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=65ad59ab00bf973e5fd7a375927fd831e6b6e6dc;p=dbsrgits%2FDBIx-Class-Historic.git Optimization - order only on lazy prefetch If the user wants all() without an order_by she doesn't care anyway --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index 4fff77e..70025db 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1268,6 +1268,14 @@ sub _construct_objects { my $rsrc = $self->result_source; my $attrs = $self->_resolved_attrs; + + if (!$fetch_all and ! $attrs->{order_by} and $attrs->{collapse}) { + # default order for collapsing unless the user asked for something + $attrs->{order_by} = [ map { join '.', $attrs->{alias}, $_} $rsrc->primary_columns ]; + $attrs->{_ordered_for_collapse} = 1; + $attrs->{_order_is_artificial} = 1; + } + my $cursor = $self->cursor; # this will be used as both initial raw-row collector AND as a RV of @@ -3545,13 +3553,6 @@ sub _resolved_attrs { } } - if (! $attrs->{order_by} and $attrs->{collapse}) { - # default order for collapsing unless the user asked for something - $attrs->{order_by} = [ map { "$alias.$_" } $source->primary_columns ]; - $attrs->{_ordered_for_collapse} = 1; - $attrs->{_order_is_artificial} = 1; - } - # if both page and offset are specified, produce a combined offset # even though it doesn't make much sense, this is what pre 081xx has # been doing diff --git a/t/90join_torture.t b/t/90join_torture.t index ef5dec5..aa8c3fb 100644 --- a/t/90join_torture.t +++ b/t/90join_torture.t @@ -50,7 +50,6 @@ lives_ok (sub { ON producer_2.producerid = cd_to_producer_2.producer JOIN artist artist ON artist.artistid = me.artist WHERE ( ( producer.name = ? AND producer_2.name = ? ) ) - ORDER BY me.cdid )', [ [ { sqlt_datatype => 'varchar', dbic_colname => 'producer.name', sqlt_size => 100 } diff --git a/t/prefetch/correlated.t b/t/prefetch/correlated.t index 3506027..694cf0b 100644 --- a/t/prefetch/correlated.t +++ b/t/prefetch/correlated.t @@ -45,7 +45,6 @@ is_same_sql_bind( LEFT JOIN track tracks ON tracks.cd = me.cdid WHERE me.artist != ? - ORDER BY me.cdid )', [ @@ -117,7 +116,6 @@ is_same_sql_bind( LEFT JOIN track tracks ON tracks.cd = me.cdid WHERE me.artist != ? - ORDER BY me.cdid )', [ diff --git a/t/prefetch/grouped.t b/t/prefetch/grouped.t index 760e381..27d3865 100644 --- a/t/prefetch/grouped.t +++ b/t/prefetch/grouped.t @@ -296,7 +296,6 @@ for ($cd_rs->all) { GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track ) me JOIN artist artist ON artist.artistid = me.artist - ORDER BY me.cdid )', [], ); @@ -328,7 +327,6 @@ for ($cd_rs->all) { WHERE ( tracks.title != ? ) GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track, artist.artistid, artist.name, artist.rank, artist.charfield - ORDER BY me.cdid )', [ map { [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'tracks.title' } => 'ugabuganoexist' ] } (1,2) diff --git a/t/prefetch/join_type.t b/t/prefetch/join_type.t index aad32ff..817b3b0 100644 --- a/t/prefetch/join_type.t +++ b/t/prefetch/join_type.t @@ -39,7 +39,6 @@ is_same_sql_bind ( JOIN artist artist ON artist.artistid = me.artist LEFT JOIN cd cds ON cds.artist = artist.artistid LEFT JOIN artist artist_2 ON artist_2.artistid = cds.artist - ORDER BY me.cdid )', [], ); diff --git a/t/prefetch/with_limit.t b/t/prefetch/with_limit.t index 1d2aa84..97dffcc 100644 --- a/t/prefetch/with_limit.t +++ b/t/prefetch/with_limit.t @@ -190,7 +190,6 @@ is_same_sql_bind ( JOIN artist artist ON artist.artistid = me.artist WHERE ( ( artist.name = ? AND me.year = ? ) ) - ORDER BY me.cdid )', [ [ { sqlt_datatype => 'varchar', sqlt_size => 100, dbic_colname => 'artist.name' } => 'foo' ], diff --git a/t/sqlmaker/limit_dialects/torture.t b/t/sqlmaker/limit_dialects/torture.t index 3b72154..072e9c6 100644 --- a/t/sqlmaker/limit_dialects/torture.t +++ b/t/sqlmaker/limit_dialects/torture.t @@ -65,7 +65,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [ [ { sqlt_datatype => 'integer' } => 3 ], @@ -107,7 +106,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [ [ { sqlt_datatype => 'integer' } => 1 ], @@ -147,7 +145,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [ [ { sqlt_datatype => 'integer' } => 1 ], @@ -187,7 +184,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [ [ { sqlt_datatype => 'integer' } => 3 ], @@ -290,7 +286,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [ [ { sqlt_datatype => 'integer' } => 2 ], @@ -408,7 +403,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [ [ { sqlt_datatype => 'integer' } => 2 ], @@ -527,7 +521,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [], ], @@ -634,7 +627,6 @@ my $tests = { ) me LEFT JOIN books books ON books.owner = me.id - ORDER BY me.id )', [], ],