← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 13:50:58 2016
Reported on Fri Jan 8 13:51:29 2016

Filename/usr/share/perl5/DBIx/Class/SQLMaker.pm
StatementsExecuted 606021 statements in 1.48s
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
6900042663ms1.48sDBIx::Class::SQLMaker::::_quoteDBIx::Class::SQLMaker::_quote
6300021565ms1.86sDBIx::Class::SQLMaker::::_recurse_fieldsDBIx::Class::SQLMaker::_recurse_fields (recurses: max depth 1, inclusive time 1.57s)
300011142ms3.79sDBIx::Class::SQLMaker::::selectDBIx::Class::SQLMaker::select
300011120ms138msDBIx::Class::SQLMaker::::_order_byDBIx::Class::SQLMaker::_order_by
600021102ms232msDBIx::Class::SQLMaker::::_from_chunk_to_sqlDBIx::Class::SQLMaker::_from_chunk_to_sql (recurses: max depth 1, inclusive time 65.8ms)
30001129.4ms300msDBIx::Class::SQLMaker::::_tableDBIx::Class::SQLMaker::_table
30001123.7ms23.7msDBIx::Class::SQLMaker::::_assemble_bindsDBIx::Class::SQLMaker::_assemble_binds
30001120.1ms271msDBIx::Class::SQLMaker::::_recurse_fromDBIx::Class::SQLMaker::_recurse_from
30001119.2ms251msDBIx::Class::SQLMaker::::_gen_from_blocksDBIx::Class::SQLMaker::_gen_from_blocks
360002113.8ms13.8msDBIx::Class::SQLMaker::::CORE:matchDBIx::Class::SQLMaker::CORE:match (opcode)
30001112.7ms12.7msDBIx::Class::SQLMaker::::_parse_rs_attrsDBIx::Class::SQLMaker::_parse_rs_attrs
11131µs40µsDBIx::Class::SQLMaker::::BEGIN@67DBIx::Class::SQLMaker::BEGIN@67
11117µs24µsDBIx::Class::SQLMaker::::BEGIN@3DBIx::Class::SQLMaker::BEGIN@3
11112µs29µsDBIx::Class::SQLMaker::::BEGIN@70DBIx::Class::SQLMaker::BEGIN@70
11112µs34µsDBIx::Class::SQLMaker::::BEGIN@41DBIx::Class::SQLMaker::BEGIN@41
11112µs18µsDBIx::Class::SQLMaker::::BEGIN@39DBIx::Class::SQLMaker::BEGIN@39
11110µs3.60msDBIx::Class::SQLMaker::::BEGIN@34DBIx::Class::SQLMaker::BEGIN@34
1119µs49µsDBIx::Class::SQLMaker::::BEGIN@42DBIx::Class::SQLMaker::BEGIN@42
1118µs113µsDBIx::Class::SQLMaker::::BEGIN@43DBIx::Class::SQLMaker::BEGIN@43
1117µs11µsDBIx::Class::SQLMaker::::BEGIN@4DBIx::Class::SQLMaker::BEGIN@4
0000s0sDBIx::Class::SQLMaker::::__ANON__[:75]DBIx::Class::SQLMaker::__ANON__[:75]
0000s0sDBIx::Class::SQLMaker::::__ANON__[:80]DBIx::Class::SQLMaker::__ANON__[:80]
0000s0sDBIx::Class::SQLMaker::::_generate_join_clauseDBIx::Class::SQLMaker::_generate_join_clause
0000s0sDBIx::Class::SQLMaker::::_join_conditionDBIx::Class::SQLMaker::_join_condition
0000s0sDBIx::Class::SQLMaker::::_lock_selectDBIx::Class::SQLMaker::_lock_select
0000s0sDBIx::Class::SQLMaker::::_quote_charsDBIx::Class::SQLMaker::_quote_chars
0000s0sDBIx::Class::SQLMaker::::_quoting_enabledDBIx::Class::SQLMaker::_quoting_enabled
0000s0sDBIx::Class::SQLMaker::::_split_order_chunkDBIx::Class::SQLMaker::_split_order_chunk
0000s0sDBIx::Class::SQLMaker::::_where_op_NESTDBIx::Class::SQLMaker::_where_op_NEST
0000s0sDBIx::Class::SQLMaker::::_where_op_multicolumn_inDBIx::Class::SQLMaker::_where_op_multicolumn_in
0000s0sDBIx::Class::SQLMaker::::insertDBIx::Class::SQLMaker::insert
0000s0sDBIx::Class::SQLMaker::::throw_exceptionDBIx::Class::SQLMaker::throw_exception
0000s0sSQL::Abstract::::belch SQL::Abstract::belch
0000s0sSQL::Abstract::::puke SQL::Abstract::puke
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package DBIx::Class::SQLMaker;
2
3239µs230µs
# spent 24µs (17+6) within DBIx::Class::SQLMaker::BEGIN@3 which was called: # once (17µs+6µs) by base::import at line 3
use strict;
# spent 24µs making 1 call to DBIx::Class::SQLMaker::BEGIN@3 # spent 6µs making 1 call to strict::import
4250µs215µs
# spent 11µs (7+4) within DBIx::Class::SQLMaker::BEGIN@4 which was called: # once (7µs+4µs) by base::import at line 4
use warnings;
# spent 11µs making 1 call to DBIx::Class::SQLMaker::BEGIN@4 # spent 4µs making 1 call to warnings::import
5
6=head1 NAME
7
8DBIx::Class::SQLMaker - An SQL::Abstract-based SQL maker class
9
10=head1 DESCRIPTION
11
12This module is a subclass of L<SQL::Abstract> and includes a number of
13DBIC-specific workarounds, not yet suitable for inclusion into the
14L<SQL::Abstract> core. It also provides all (and more than) the functionality
15of L<SQL::Abstract::Limit>, see L<DBIx::Class::SQLMaker::LimitDialects> for
16more info.
17
18Currently the enhancements to L<SQL::Abstract> are:
19
20=over
21
22=item * Support for C<JOIN> statements (via extended C<table/from> support)
23
24=item * Support of functions in C<SELECT> lists
25
26=item * C<GROUP BY>/C<HAVING> support (via extensions to the order_by parameter)
27
28=item * Support of C<...FOR UPDATE> type of select statement modifiers
29
30=back
31
32=cut
33
341116µs10s
# spent 3.60ms (10µs+3.59) within DBIx::Class::SQLMaker::BEGIN@34 which was called: # once (10µs+3.59ms) by base::import at line 38
use base qw/
# spent 3.59ms making 1 call to base::import, recursion: max depth 1, sum of overlapping time 3.59ms
35 DBIx::Class::SQLMaker::LimitDialects
36 SQL::Abstract
37 DBIx::Class
38167µs13.60ms/;
# spent 3.60ms making 1 call to DBIx::Class::SQLMaker::BEGIN@34
39238µs223µs
# spent 18µs (12+6) within DBIx::Class::SQLMaker::BEGIN@39 which was called: # once (12µs+6µs) by base::import at line 39
use mro 'c3';
# spent 18µs making 1 call to DBIx::Class::SQLMaker::BEGIN@39 # spent 6µs making 1 call to mro::import
40
41253µs256µs
# spent 34µs (12+22) within DBIx::Class::SQLMaker::BEGIN@41 which was called: # once (12µs+22µs) by base::import at line 41
use Sub::Name 'subname';
# spent 34µs making 1 call to DBIx::Class::SQLMaker::BEGIN@41 # spent 22µs making 1 call to Exporter::import
42225µs289µs
# spent 49µs (9+40) within DBIx::Class::SQLMaker::BEGIN@42 which was called: # once (9µs+40µs) by base::import at line 42
use DBIx::Class::Carp;
# spent 49µs making 1 call to DBIx::Class::SQLMaker::BEGIN@42 # spent 40µs making 1 call to DBIx::Class::Carp::import
432279µs2218µs
# spent 113µs (8+105) within DBIx::Class::SQLMaker::BEGIN@43 which was called: # once (8µs+105µs) by base::import at line 43
use namespace::clean;
# spent 113µs making 1 call to DBIx::Class::SQLMaker::BEGIN@43 # spent 105µs making 1 call to namespace::clean::import
44
45135µs1219µs__PACKAGE__->mk_group_accessors (simple => qw/quote_char name_sep limit_dialect/);
# spent 219µs making 1 call to Class::Accessor::Grouped::mk_group_accessors
46
47sub _quoting_enabled {
48 ( defined $_[0]->{quote_char} and length $_[0]->{quote_char} ) ? 1 : 0
49}
50
51# for when I need a normalized l/r pair
52sub _quote_chars {
53
54 # in case we are called in the old !!$sm->_quote_chars fashion
55 return () if !wantarray and ( ! defined $_[0]->{quote_char} or ! length $_[0]->{quote_char} );
56
57 map
58 { defined $_ ? $_ : '' }
59 ( ref $_[0]->{quote_char} ? (@{$_[0]->{quote_char}}) : ( ($_[0]->{quote_char}) x 2 ) )
60 ;
61}
62
63# FIXME when we bring in the storage weaklink, check its schema
64# weaklink and channel through $schema->throw_exception
65sub throw_exception { DBIx::Class::Exception->throw($_[1]) }
66
67
# spent 40µs (31+9) within DBIx::Class::SQLMaker::BEGIN@67 which was called: # once (31µs+9µs) by base::import at line 81
BEGIN {
68 # reinstall the belch()/puke() functions of SQL::Abstract with custom versions
69 # that use DBIx::Class::Carp/DBIx::Class::Exception instead of plain Carp
702162µs246µs
# spent 29µs (12+17) within DBIx::Class::SQLMaker::BEGIN@70 which was called: # once (12µs+17µs) by base::import at line 70
no warnings qw/redefine/;
# spent 29µs making 1 call to DBIx::Class::SQLMaker::BEGIN@70 # spent 17µs making 1 call to warnings::unimport
71
72 *SQL::Abstract::belch = subname 'SQL::Abstract::belch' => sub (@) {
73 my($func) = (caller(1))[3];
74 carp "[$func] Warning: ", @_;
75122µs16µs };
# spent 6µs making 1 call to Sub::Name::subname
76
77 *SQL::Abstract::puke = subname 'SQL::Abstract::puke' => sub (@) {
78 my($func) = (caller(1))[3];
79 __PACKAGE__->throw_exception("[$func] Fatal: " . join ('', @_));
80117µs13µs };
# spent 3µs making 1 call to Sub::Name::subname
8112.16ms140µs}
# spent 40µs making 1 call to DBIx::Class::SQLMaker::BEGIN@67
82
83# the "oh noes offset/top without limit" constant
84# limited to 31 bits for sanity (and consistency,
85# since it may be handed to the like of sprintf %u)
86#
87# Also *some* builds of SQLite fail the test
88# some_column BETWEEN ? AND ?: 1, 4294967295
89# with the proper integer bind attrs
90#
91# Implemented as a method, since ::Storage::DBI also
92# refers to it (i.e. for the case of software_limit or
93# as the value to abuse with MSSQL ordered subqueries)
94sub __max_int () { 0x7FFFFFFF };
95
96# we ne longer need to check this - DBIC has ways of dealing with it
97# specifically ::Storage::DBI::_resolve_bindattrs()
98sub _assert_bindval_matches_bindtype () { 1 };
99
100# poor man's de-qualifier
101
# spent 1.48s (663ms+821ms) within DBIx::Class::SQLMaker::_quote which was called 69000 times, avg 22µs/call: # 60000 times (573ms+718ms) by DBIx::Class::SQLMaker::_recurse_fields at line 238, avg 22µs/call # 3000 times (34.6ms+37.8ms) by SQL::Abstract::__ANON__[/usr/share/perl5/SQL/Abstract.pm:941] at line 937 of SQL/Abstract.pm, avg 24µs/call # 3000 times (35.0ms+33.4ms) by DBIx::Class::SQLMaker::_from_chunk_to_sql at line 442, avg 23µs/call # 3000 times (20.2ms+32.3ms) by DBIx::Class::SQLMaker::_from_chunk_to_sql at line 423, avg 17µs/call
sub _quote {
10269000640ms69000187ms $_[0]->next::method( ( $_[0]{_dequalify_idents} and ! ref $_[1] )
# spent 187ms making 69000 calls to next::method, avg 3µs/call
103 ? $_[1] =~ / ([^\.]+) $ /x
104 : $_[1]
105 );
106}
107
108sub _where_op_NEST {
109 carp_unique ("-nest in search conditions is deprecated, you most probably wanted:\n"
110 .q|{..., -and => [ \%cond0, \@cond1, \'cond2', \[ 'cond3', [ col => bind ] ], etc. ], ... }|
111 );
112
113 shift->next::method(@_);
114}
115
116# Handle limit-dialect selection
117
# spent 3.79s (142ms+3.65) within DBIx::Class::SQLMaker::select which was called 3000 times, avg 1.26ms/call: # 3000 times (142ms+3.65s) by DBIx::Class::Storage::DBI::_gen_sql_bind at line 1649 of DBIx/Class/Storage/DBI.pm, avg 1.26ms/call
sub select {
11830002.31ms my ($self, $table, $fields, $where, $rs_attrs, $limit, $offset) = @_;
119
120
121300013.0ms30001.86s ($fields, @{$self->{select_bind}}) = $self->_recurse_fields($fields);
# spent 1.86s making 3000 calls to DBIx::Class::SQLMaker::_recurse_fields, avg 619µs/call
122
1233000958µs if (defined $offset) {
124 $self->throw_exception('A supplied offset must be a non-negative integer')
125 if ( $offset =~ /\D/ or $offset < 0 );
126 }
12730001.48ms $offset ||= 0;
128
12930001.23ms if (defined $limit) {
130 $self->throw_exception('A supplied limit must be a positive integer')
131 if ( $limit =~ /\D/ or $limit <= 0 );
132 }
133 elsif ($offset) {
134 $limit = $self->__max_int;
135 }
136
137
1383000623µs my ($sql, @bind);
13930002.20ms if ($limit) {
140 # this is legacy code-flow from SQLA::Limit, it is not set in stone
141
142 ($sql, @bind) = $self->next::method ($table, $fields, $where);
143
144 my $limiter;
145
146 if( $limiter = $self->can ('emulate_limit') ) {
147 carp_unique(
148 'Support for the legacy emulate_limit() mechanism inherited from '
149 . 'SQL::Abstract::Limit has been deprecated, and will be removed when '
150 . 'DBIC transitions to Data::Query. If your code uses this type of '
151 . 'limit specification please file an RT and provide the source of '
152 . 'your emulate_limit() implementation, so an acceptable upgrade-path '
153 . 'can be devised'
154 );
155 }
156 else {
157 my $dialect = $self->limit_dialect
158 or $self->throw_exception( "Unable to generate SQL-limit - no limit dialect specified on $self" );
159
160 $limiter = $self->can ("_$dialect")
161 or $self->throw_exception(__PACKAGE__ . " does not implement the requested dialect '$dialect'");
162 }
163
164 $sql = $self->$limiter (
165 $sql,
166 { %{$rs_attrs||{}}, _selector_sql => $fields },
167 $limit,
168 $offset
169 );
170 }
171 else {
172300022.8ms300010.9ms ($sql, @bind) = $self->next::method ($table, $fields, $where, $rs_attrs);
# spent 10.9ms making 3000 calls to next::method, avg 4µs/call
173 }
174
17530004.49ms push @{$self->{where_bind}}, @bind;
176
177# this *must* be called, otherwise extra binds will remain in the sql-maker
17830007.07ms300023.7ms my @all_bind = $self->_assemble_binds;
# spent 23.7ms making 3000 calls to DBIx::Class::SQLMaker::_assemble_binds, avg 8µs/call
179
18030002.09ms $sql .= $self->_lock_select ($rs_attrs->{for})
181 if $rs_attrs->{for};
182
183300016.5ms return wantarray ? ($sql, @all_bind) : $sql;
184}
185
186
# spent 23.7ms within DBIx::Class::SQLMaker::_assemble_binds which was called 3000 times, avg 8µs/call: # 3000 times (23.7ms+0s) by DBIx::Class::SQLMaker::select at line 178, avg 8µs/call
sub _assemble_binds {
18730001.36ms my $self = shift;
188300035.8ms return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/pre_select select from where group having order limit/);
189}
190
19113µsmy $for_syntax = {
192 update => 'FOR UPDATE',
193 shared => 'FOR SHARE',
194};
195sub _lock_select {
196 my ($self, $type) = @_;
197
198 my $sql;
199 if (ref($type) eq 'SCALAR') {
200 $sql = "FOR $$type";
201 }
202 else {
203 $sql = $for_syntax->{$type} || $self->throw_exception( "Unknown SELECT .. FOR type '$type' requested" );
204 }
205
206 return " $sql";
207}
208
209# Handle default inserts
210sub insert {
211# optimized due to hotttnesss
212# my ($self, $table, $data, $options) = @_;
213
214 # SQLA will emit INSERT INTO $table ( ) VALUES ( )
215 # which is sadly understood only by MySQL. Change default behavior here,
216 # until SQLA2 comes with proper dialect support
217 if (! $_[2] or (ref $_[2] eq 'HASH' and !keys %{$_[2]} ) ) {
218 my @bind;
219 my $sql = sprintf(
220 'INSERT INTO %s DEFAULT VALUES', $_[0]->_quote($_[1])
221 );
222
223 if ( ($_[3]||{})->{returning} ) {
224 my $s;
225 ($s, @bind) = $_[0]->_insert_returning ($_[3]);
226 $sql .= $s;
227 }
228
229 return ($sql, @bind);
230 }
231
232 next::method(@_);
233}
234
235
# spent 1.86s (565ms+1.29) within DBIx::Class::SQLMaker::_recurse_fields which was called 63000 times, avg 29µs/call: # 60000 times (282ms+-282ms) by DBIx::Class::SQLMaker::_recurse_fields at line 244, avg 0s/call # 3000 times (283ms+1.57s) by DBIx::Class::SQLMaker::select at line 121, avg 619µs/call
sub _recurse_fields {
2366300017.7ms my ($self, $fields) = @_;
2376300016.0ms my $ref = ref $fields;
23863000230ms600001.29s return $self->_quote($fields) unless $ref;
# spent 1.29s making 60000 calls to DBIx::Class::SQLMaker::_quote, avg 22µs/call
23930001.84ms return $$fields if $ref eq 'SCALAR';
240
24130001.40ms if ($ref eq 'ARRAY') {
2423000719µs my (@select, @bind);
24330003.36ms for my $field (@$fields) {
2446000082.4ms600000s my ($select, @new_bind) = $self->_recurse_fields($field);
# spent 1.57s making 60000 calls to DBIx::Class::SQLMaker::_recurse_fields, avg 26µs/call, recursion: max depth 1, sum of overlapping time 1.57s
2456000017.9ms push @select, $select;
2466000028.2ms push @bind, @new_bind;
247 }
248300015.3ms return (join(', ', @select), @bind);
249 }
250 elsif ($ref eq 'HASH') {
251 my %hash = %$fields; # shallow copy
252
253 my $as = delete $hash{-as}; # if supplied
254
255 my ($func, $rhs, @toomany) = %hash;
256
257 # there should be only one pair
258 if (@toomany) {
259 $self->throw_exception( "Malformed select argument - too many keys in hash: " . join (',', keys %$fields ) );
260 }
261
262 if (lc ($func) eq 'distinct' && ref $rhs eq 'ARRAY' && @$rhs > 1) {
263 $self->throw_exception (
264 'The select => { distinct => ... } syntax is not supported for multiple columns.'
265 .' Instead please use { group_by => [ qw/' . (join ' ', @$rhs) . '/ ] }'
266 .' or { select => [ qw/' . (join ' ', @$rhs) . '/ ], distinct => 1 }'
267 );
268 }
269
270 my ($rhs_sql, @rhs_bind) = $self->_recurse_fields($rhs);
271 my $select = sprintf ('%s( %s )%s',
272 $self->_sqlcase($func),
273 $rhs_sql,
274 $as
275 ? sprintf (' %s %s', $self->_sqlcase('as'), $self->_quote ($as) )
276 : ''
277 );
278
279 return ($select, @rhs_bind);
280 }
281 elsif ( $ref eq 'REF' and ref($$fields) eq 'ARRAY' ) {
282 return @{$$fields};
283 }
284 else {
285 $self->throw_exception( $ref . qq{ unexpected in _recurse_fields()} );
286 }
287}
288
289
290# this used to be a part of _order_by but is broken out for clarity.
291# What we have been doing forever is hijacking the $order arg of
292# SQLA::select to pass in arbitrary pieces of data (first the group_by,
293# then pretty much the entire resultset attr-hash, as more and more
294# things in the SQLA space need to have more info about the $rs they
295# create SQL for. The alternative would be to keep expanding the
296# signature of _select with more and more positional parameters, which
297# is just gross. All hail SQLA2!
298
# spent 12.7ms within DBIx::Class::SQLMaker::_parse_rs_attrs which was called 3000 times, avg 4µs/call: # 3000 times (12.7ms+0s) by DBIx::Class::SQLMaker::_order_by at line 327, avg 4µs/call
sub _parse_rs_attrs {
29930001.34ms my ($self, $arg) = @_;
300
30130001.53ms my $sql = '';
302
30330001.75ms if ($arg->{group_by}) {
304 if ( my ($group_sql, @group_bind) = $self->_recurse_fields($arg->{group_by}) ) {
305 $sql .= $self->_sqlcase(' group by ') . $group_sql;
306 push @{$self->{group_bind}}, @group_bind;
307 }
308 }
309
31030001.82ms if (defined $arg->{having}) {
311 my ($frag, @bind) = $self->_recurse_where($arg->{having});
312 push(@{$self->{having_bind}}, @bind);
313 $sql .= $self->_sqlcase(' having ') . $frag;
314 }
315
31630001.65ms if (defined $arg->{order_by}) {
317 $sql .= $self->_order_by ($arg->{order_by});
318 }
319
320300011.6ms return $sql;
321}
322
323
# spent 138ms (120+17.8) within DBIx::Class::SQLMaker::_order_by which was called 3000 times, avg 46µs/call: # 3000 times (120ms+17.8ms) by SQL::Abstract::where at line 479 of SQL/Abstract.pm, avg 46µs/call
sub _order_by {
32430001.89ms my ($self, $arg) = @_;
325
326 # check that we are not called in legacy mode (order_by as 4th argument)
32730000117ms3000017.8ms if (ref $arg eq 'HASH' and not grep { $_ =~ /^-(?:desc|asc)/i } keys %$arg ) {
# spent 12.7ms making 3000 calls to DBIx::Class::SQLMaker::_parse_rs_attrs, avg 4µs/call # spent 5.17ms making 27000 calls to DBIx::Class::SQLMaker::CORE:match, avg 191ns/call
328 return $self->_parse_rs_attrs ($arg);
329 }
330 else {
331 my ($sql, @bind) = $self->next::method($arg);
332 push @{$self->{order_bind}}, @bind;
333 return $sql;
334 }
335}
336
337sub _split_order_chunk {
338 my ($self, $chunk) = @_;
339
340 # strip off sort modifiers, but always succeed, so $1 gets reset
341 $chunk =~ s/ (?: \s+ (ASC|DESC) )? \s* $//ix;
342
343 return (
344 $chunk,
345 ( $1 and uc($1) eq 'DESC' ) ? 1 : 0,
346 );
347}
348
349
# spent 300ms (29.4+271) within DBIx::Class::SQLMaker::_table which was called 3000 times, avg 100µs/call: # 3000 times (29.4ms+271ms) by DBIx::Class::SQLMaker::select at line 430 of SQL/Abstract.pm, avg 100µs/call
sub _table {
350# optimized due to hotttnesss
351# my ($self, $from) = @_;
35230002.48ms if (my $ref = ref $_[1] ) {
353300013.6ms3000271ms if ($ref eq 'ARRAY') {
# spent 271ms making 3000 calls to DBIx::Class::SQLMaker::_recurse_from, avg 90µs/call
354 return $_[0]->_recurse_from(@{$_[1]});
355 }
356 elsif ($ref eq 'HASH') {
357 return $_[0]->_recurse_from($_[1]);
358 }
359 elsif ($ref eq 'REF' && ref ${$_[1]} eq 'ARRAY') {
360 my ($sql, @bind) = @{ ${$_[1]} };
361 push @{$_[0]->{from_bind}}, @bind;
362 return $sql
363 }
364 }
365 return $_[0]->next::method ($_[1]);
366}
367
368sub _generate_join_clause {
369 my ($self, $join_type) = @_;
370
371 $join_type = $self->{_default_jointype}
372 if ! defined $join_type;
373
374 return sprintf ('%s JOIN ',
375 $join_type ? $self->_sqlcase($join_type) : ''
376 );
377}
378
379
# spent 271ms (20.1+251) within DBIx::Class::SQLMaker::_recurse_from which was called 3000 times, avg 90µs/call: # 3000 times (20.1ms+251ms) by DBIx::Class::SQLMaker::_table at line 353, avg 90µs/call
sub _recurse_from {
38030001.24ms my $self = shift;
381300023.8ms3000251ms return join (' ', $self->_gen_from_blocks(@_) );
# spent 251ms making 3000 calls to DBIx::Class::SQLMaker::_gen_from_blocks, avg 84µs/call
382}
383
384
# spent 251ms (19.2+232) within DBIx::Class::SQLMaker::_gen_from_blocks which was called 3000 times, avg 84µs/call: # 3000 times (19.2ms+232ms) by DBIx::Class::SQLMaker::_recurse_from at line 381, avg 84µs/call
sub _gen_from_blocks {
38530002.26ms my ($self, $from, @joins) = @_;
386
38730007.57ms3000232ms my @fchunks = $self->_from_chunk_to_sql($from);
# spent 232ms making 3000 calls to DBIx::Class::SQLMaker::_from_chunk_to_sql, avg 77µs/call
388
38930002.81ms for (@joins) {
390 my ($to, $on) = @$_;
391
392 # check whether a join type exists
393 my $to_jt = ref($to) eq 'ARRAY' ? $to->[0] : $to;
394 my $join_type;
395 if (ref($to_jt) eq 'HASH' and defined($to_jt->{-join_type})) {
396 $join_type = $to_jt->{-join_type};
397 $join_type =~ s/^\s+ | \s+$//xg;
398 }
399
400 my @j = $self->_generate_join_clause( $join_type );
401
402 if (ref $to eq 'ARRAY') {
403 push(@j, '(', $self->_recurse_from(@$to), ')');
404 }
405 else {
406 push(@j, $self->_from_chunk_to_sql($to));
407 }
408
409 my ($sql, @bind) = $self->_join_condition($on);
410 push(@j, ' ON ', $sql);
411 push @{$self->{from_bind}}, @bind;
412
413 push @fchunks, join '', @j;
414 }
415
416300013.3ms return @fchunks;
417}
418
419
# spent 232ms (102+129) within DBIx::Class::SQLMaker::_from_chunk_to_sql which was called 6000 times, avg 39µs/call: # 3000 times (88.8ms+143ms) by DBIx::Class::SQLMaker::_gen_from_blocks at line 387, avg 77µs/call # 3000 times (13.3ms+-13.3ms) by DBIx::Class::SQLMaker::_from_chunk_to_sql at line 442, avg 0s/call
sub _from_chunk_to_sql {
42060002.45ms my ($self, $fromspec) = @_;
421
422600026.2ms return join (' ', do {
42360009.40ms300052.5ms if (! ref $fromspec) {
# spent 52.5ms making 3000 calls to DBIx::Class::SQLMaker::_quote, avg 17µs/call
424 $self->_quote($fromspec);
425 }
426 elsif (ref $fromspec eq 'SCALAR') {
427 $$fromspec;
428 }
429 elsif (ref $fromspec eq 'REF' and ref $$fromspec eq 'ARRAY') {
430 push @{$self->{from_bind}}, @{$$fromspec}[1..$#$$fromspec];
431 $$fromspec->[0];
432 }
433 elsif (ref $fromspec eq 'HASH') {
434 my ($as, $table, $toomuch) = ( map
435900039.1ms90008.59ms { $_ => $fromspec->{$_} }
# spent 8.59ms making 9000 calls to DBIx::Class::SQLMaker::CORE:match, avg 954ns/call
436300015.7ms ( grep { $_ !~ /^\-/ } keys %$fromspec )
437 );
438
4393000987µs $self->throw_exception( "Only one table/as pair expected in from-spec but an exra '$toomuch' key present" )
440 if defined $toomuch;
441
44230008.80ms600068.4ms ($self->_from_chunk_to_sql($table), $self->_quote($as) );
# spent 68.4ms making 3000 calls to DBIx::Class::SQLMaker::_quote, avg 23µs/call # spent 65.8ms making 3000 calls to DBIx::Class::SQLMaker::_from_chunk_to_sql, avg 22µs/call, recursion: max depth 1, sum of overlapping time 65.8ms
443 }
444 else {
445 $self->throw_exception('Unsupported from refkind: ' . ref $fromspec );
446 }
447 });
448}
449
450sub _join_condition {
451 my ($self, $cond) = @_;
452
453 # Backcompat for the old days when a plain hashref
454 # { 't1.col1' => 't2.col2' } meant ON t1.col1 = t2.col2
455 if (
456 ref $cond eq 'HASH'
457 and
458 keys %$cond == 1
459 and
460 (keys %$cond)[0] =~ /\./
461 and
462 ! ref ( (values %$cond)[0] )
463 ) {
464 carp_unique(
465 "ResultSet {from} structures with conditions not conforming to the "
466 . "SQL::Abstract syntax are deprecated: you either need to stop abusing "
467 . "{from} altogether, or express the condition properly using the "
468 . "{ -ident => ... } operator"
469 );
470 $cond = { keys %$cond => { -ident => values %$cond } }
471 }
472 elsif ( ref $cond eq 'ARRAY' ) {
473 # do our own ORing so that the hashref-shim above is invoked
474 my @parts;
475 my @binds;
476 foreach my $c (@$cond) {
477 my ($sql, @bind) = $self->_join_condition($c);
478 push @binds, @bind;
479 push @parts, $sql;
480 }
481 return join(' OR ', @parts), @binds;
482 }
483
484 return $self->_recurse_where($cond);
485}
486
487# This is hideously ugly, but SQLA does not understand multicol IN expressions
488# FIXME TEMPORARY - DQ should have native syntax for this
489# moved here to raise API questions
490#
491# !!! EXPERIMENTAL API !!! WILL CHANGE !!!
492sub _where_op_multicolumn_in {
493 my ($self, $lhs, $rhs) = @_;
494
495 if (! ref $lhs or ref $lhs eq 'ARRAY') {
496 my (@sql, @bind);
497 for (ref $lhs ? @$lhs : $lhs) {
498 if (! ref $_) {
499 push @sql, $self->_quote($_);
500 }
501 elsif (ref $_ eq 'SCALAR') {
502 push @sql, $$_;
503 }
504 elsif (ref $_ eq 'REF' and ref $$_ eq 'ARRAY') {
505 my ($s, @b) = @$$_;
506 push @sql, $s;
507 push @bind, @b;
508 }
509 else {
510 $self->throw_exception("ARRAY of @{[ ref $_ ]}es unsupported for multicolumn IN lhs...");
511 }
512 }
513 $lhs = \[ join(', ', @sql), @bind];
514 }
515 elsif (ref $lhs eq 'SCALAR') {
516 $lhs = \[ $$lhs ];
517 }
518 elsif (ref $lhs eq 'REF' and ref $$lhs eq 'ARRAY' ) {
519 # noop
520 }
521 else {
522 $self->throw_exception( ref($lhs) . "es unsupported for multicolumn IN lhs...");
523 }
524
525 # is this proper...?
526 $rhs = \[ $self->_recurse_where($rhs) ];
527
528 for ($lhs, $rhs) {
529 $$_->[0] = "( $$_->[0] )"
530 unless $$_->[0] =~ /^ \s* \( .* \) \s* $/xs;
531 }
532
533 \[ join( ' IN ', shift @$$lhs, shift @$$rhs ), @$$lhs, @$$rhs ];
534}
535
536=head1 FURTHER QUESTIONS?
537
538Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
539
540=head1 COPYRIGHT AND LICENSE
541
542This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
543by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
544redistribute it and/or modify it under the same terms as the
545L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
546
547=cut
548
54916µs1168µs1;
# spent 168µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__
 
# spent 13.8ms within DBIx::Class::SQLMaker::CORE:match which was called 36000 times, avg 382ns/call: # 27000 times (5.17ms+0s) by DBIx::Class::SQLMaker::_order_by at line 327, avg 191ns/call # 9000 times (8.59ms+0s) by DBIx::Class::SQLMaker::_from_chunk_to_sql at line 435, avg 954ns/call
sub DBIx::Class::SQLMaker::CORE:match; # opcode