From: Peter Rabbitson Date: Mon, 31 May 2010 23:54:17 +0000 (+0000) Subject: Switch away from explicit count-attr lists - just delete what we do not need X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=583a0c658da959793c4cbcc4d882da8550b23f6c;p=dbsrgits%2FDBIx-Class-Historic.git Switch away from explicit count-attr lists - just delete what we do not need --- diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index cba01bc..cdb2cf3 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -1237,14 +1237,12 @@ sub _count_rs { my $rsrc = $self->result_source; $attrs ||= $self->_resolved_attrs; - # only take pieces we need for a simple count - my $tmp_attrs = { map - { $_ => $attrs->{$_} } - qw/ alias from where bind join / - }; + my $tmp_attrs = { %$attrs }; + # take off any limits, record_filter is cdbi, and no point of ordering nor locking a count + delete @{$tmp_attrs}{qw/rows offset order_by record_filter for/}; # overwrite the selector (supplied by the storage) - $tmp_attrs->{select} = $rsrc->storage->_count_select ($rsrc, $tmp_attrs); + $tmp_attrs->{select} = $rsrc->storage->_count_select ($rsrc, $attrs); $tmp_attrs->{as} = 'count'; my $tmp_rs = $rsrc->resultset_class->new($rsrc, $tmp_attrs)->get_column ('count'); @@ -1261,10 +1259,9 @@ sub _count_subq_rs { my $rsrc = $self->result_source; $attrs ||= $self->_resolved_attrs; - my $sub_attrs = { map - { $_ => $attrs->{$_} } - qw/ alias from where bind join group_by having rows offset / - }; + my $sub_attrs = { %$attrs }; + # extra selectors do not go in the subquery and there is no point of ordering it, nor locking it + delete @{$sub_attrs}{qw/collapse select _prefetch_select as order_by for/}; # if we multi-prefetch we group_by primary keys only as this is what we would # get out of the rs via ->next/->all. We *DO WANT* to clobber old group_by regardless @@ -1295,7 +1292,7 @@ sub _count_subq_rs { ->new ($rsrc, $sub_attrs) ->as_subselect_rs ->search ({}, { columns => { count => $rsrc->storage->_count_select ($rsrc, $attrs) } }) - -> get_column ('count'); + ->get_column ('count'); } sub _bool { diff --git a/lib/DBIx/Class/SQLAHacks.pm b/lib/DBIx/Class/SQLAHacks.pm index c1fbb40..392c887 100644 --- a/lib/DBIx/Class/SQLAHacks.pm +++ b/lib/DBIx/Class/SQLAHacks.pm @@ -508,8 +508,6 @@ sub _find_syntax { sub select { my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_; - $self->{"${_}_bind"} = [] for (qw/having from order where/); - if (not ref($table) or ref($table) eq 'SCALAR') { $table = $self->_quote($table); } @@ -522,7 +520,16 @@ sub select { ($sql, @{$self->{where_bind}}) = $self->SUPER::select( $table, $self->_recurse_fields($fields), $where, $rs_attrs, @rest ); - return wantarray ? ($sql, @{$self->{from_bind}}, @{$self->{where_bind}}, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql; + +# this *must* be called, otherwise extra binds will remain in the sql-maker + my @bind = $self->_assemble_binds; + + return wantarray ? ($sql, @bind) : $sql; +} + +sub _assemble_binds { + my $self = shift; + return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/from where having order/); } # Quotes table names, and handles default inserts diff --git a/lib/DBIx/Class/SQLAHacks/Oracle.pm b/lib/DBIx/Class/SQLAHacks/Oracle.pm index 5c407b6..5f77a60 100644 --- a/lib/DBIx/Class/SQLAHacks/Oracle.pm +++ b/lib/DBIx/Class/SQLAHacks/Oracle.pm @@ -24,20 +24,18 @@ sub new { $self->SUPER::new (\%opts); } -sub select { - my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_; - - my $sql = $self->SUPER::select($table, $fields, $where, $rs_attrs, @rest); - - return wantarray ? ($sql, @{$self->{from_bind}}, @{$self->{where_bind}}, @{$self->{_oracle_connect_by_binds}}, @{$self->{having_bind}}, @{$self->{order_bind}} ) : $sql; +sub _assemble_binds { + my $self = shift; + return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/from where oracle_connect_by having order/); } + sub _emulate_limit { my ( $self, $syntax, $sql, $rs_attrs, $rows, $offset ) = @_; my ($cb_sql, @cb_bind) = $self->_connect_by($rs_attrs); $sql .= $cb_sql; - $self->{_oracle_connect_by_binds} = \@cb_bind; + $self->{oracle_connect_by_bind} = \@cb_bind; return $self->SUPER::_emulate_limit($syntax, $sql, $rs_attrs, $rows, $offset); }