| Filename | /usr/share/perl5/DBIx/Class/Storage/DBI/mysql.pm |
| Statements | Executed 36016 statements in 167ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 6000 | 2 | 1 | 139ms | 229ms | DBIx::Class::Storage::DBI::mysql::sql_maker |
| 3000 | 1 | 1 | 33.0ms | 5.93s | DBIx::Class::Storage::DBI::mysql::_prep_for_execute |
| 1 | 1 | 1 | 81µs | 3.32ms | DBIx::Class::Storage::DBI::mysql::_run_connection_actions |
| 3 | 3 | 2 | 37µs | 37µs | DBIx::Class::Storage::DBI::mysql::debug (xsub) |
| 1 | 1 | 1 | 24µs | 36µs | DBIx::Class::Storage::DBI::mysql::BEGIN@3 |
| 1 | 1 | 1 | 13µs | 161µs | DBIx::Class::Storage::DBI::mysql::BEGIN@8 |
| 1 | 1 | 1 | 11µs | 21µs | DBIx::Class::Storage::DBI::mysql::BEGIN@4 |
| 1 | 1 | 1 | 11µs | 86µs | DBIx::Class::Storage::DBI::mysql::BEGIN@6 |
| 3 | 3 | 3 | 2µs | 2µs | DBIx::Class::Storage::DBI::mysql::transaction_depth (xsub) |
| 2 | 2 | 2 | 1µs | 1µs | DBIx::Class::Storage::DBI::mysql::disable_sth_caching (xsub) |
| 1 | 1 | 1 | 1µs | 1µs | DBIx::Class::Storage::DBI::mysql::on_connect_call (xsub) |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::_dbh_last_insert_id |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::_exec_svp_begin |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::_exec_svp_release |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::_exec_svp_rollback |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::connect_call_set_strict_mode |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::deployment_statements |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::is_replicating |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::lag_behind_master |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::sqlt_type |
| 0 | 0 | 0 | 0s | 0s | DBIx::Class::Storage::DBI::mysql::with_deferred_fk_checks |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DBIx::Class::Storage::DBI::mysql; | ||||
| 2 | |||||
| 3 | 2 | 52µs | 2 | 48µs | # spent 36µs (24+12) within DBIx::Class::Storage::DBI::mysql::BEGIN@3 which was called:
# once (24µs+12µs) by Class::C3::Componentised::ensure_class_loaded at line 3 # spent 36µs making 1 call to DBIx::Class::Storage::DBI::mysql::BEGIN@3
# spent 12µs making 1 call to strict::import |
| 4 | 2 | 53µs | 2 | 31µs | # spent 21µs (11+10) within DBIx::Class::Storage::DBI::mysql::BEGIN@4 which was called:
# once (11µs+10µs) by Class::C3::Componentised::ensure_class_loaded at line 4 # spent 21µs making 1 call to DBIx::Class::Storage::DBI::mysql::BEGIN@4
# spent 10µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 2 | 136µs | 2 | 160µs | # spent 86µs (11+75) within DBIx::Class::Storage::DBI::mysql::BEGIN@6 which was called:
# once (11µs+75µs) by Class::C3::Componentised::ensure_class_loaded at line 6 # spent 86µs making 1 call to DBIx::Class::Storage::DBI::mysql::BEGIN@6
# spent 75µs making 1 call to base::import |
| 7 | |||||
| 8 | 2 | 1.49ms | 2 | 309µs | # spent 161µs (13+148) within DBIx::Class::Storage::DBI::mysql::BEGIN@8 which was called:
# once (13µs+148µs) by Class::C3::Componentised::ensure_class_loaded at line 8 # spent 161µs making 1 call to DBIx::Class::Storage::DBI::mysql::BEGIN@8
# spent 148µs making 1 call to namespace::clean::import |
| 9 | |||||
| 10 | 1 | 10µs | 1 | 83µs | __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::MySQL'); # spent 83µs making 1 call to DBIx::Class::Storage::DBI::sql_maker_class |
| 11 | 1 | 7µs | 1 | 14µs | __PACKAGE__->sql_limit_dialect ('LimitXY'); # spent 14µs making 1 call to DBIx::Class::Storage::DBI::sql_limit_dialect |
| 12 | 1 | 4µs | 1 | 10µs | __PACKAGE__->sql_quote_char ('`'); # spent 10µs making 1 call to DBIx::Class::Storage::DBI::sql_quote_char |
| 13 | |||||
| 14 | 1 | 5µs | 1 | 17µs | __PACKAGE__->_use_multicolumn_in (1); # spent 17µs making 1 call to DBIx::Class::Storage::DBI::_use_multicolumn_in |
| 15 | |||||
| 16 | sub with_deferred_fk_checks { | ||||
| 17 | my ($self, $sub) = @_; | ||||
| 18 | |||||
| 19 | $self->_do_query('SET FOREIGN_KEY_CHECKS = 0'); | ||||
| 20 | $sub->(); | ||||
| 21 | $self->_do_query('SET FOREIGN_KEY_CHECKS = 1'); | ||||
| 22 | } | ||||
| 23 | |||||
| 24 | sub connect_call_set_strict_mode { | ||||
| 25 | my $self = shift; | ||||
| 26 | |||||
| 27 | # the @@sql_mode puts back what was previously set on the session handle | ||||
| 28 | $self->_do_query(q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|); | ||||
| 29 | $self->_do_query(q|SET SQL_AUTO_IS_NULL = 0|); | ||||
| 30 | } | ||||
| 31 | |||||
| 32 | sub _dbh_last_insert_id { | ||||
| 33 | my ($self, $dbh, $source, $col) = @_; | ||||
| 34 | $dbh->{mysql_insertid}; | ||||
| 35 | } | ||||
| 36 | |||||
| 37 | # spent 5.93s (33.0ms+5.90) within DBIx::Class::Storage::DBI::mysql::_prep_for_execute which was called 3000 times, avg 1.98ms/call:
# 3000 times (33.0ms+5.90s) by DBIx::Class::Storage::DBI::_execute at line 1806 of DBIx/Class/Storage/DBI.pm, avg 1.98ms/call | ||||
| 38 | 3000 | 1.11ms | my $self = shift; | ||
| 39 | #(my $op, $ident, $args) = @_; | ||||
| 40 | |||||
| 41 | # Only update and delete need special double-subquery treatment | ||||
| 42 | # Insert referencing the same table (i.e. SELECT MAX(id) + 1) seems | ||||
| 43 | # to work just fine on MySQL | ||||
| 44 | 3000 | 40.3ms | 3000 | 10.4ms | return $self->next::method(@_) if ( $_[0] eq 'select' or $_[0] eq 'insert' ); # spent 10.4ms making 3000 calls to next::method, avg 3µs/call |
| 45 | |||||
| 46 | |||||
| 47 | # FIXME FIXME FIXME - this is a terrible, gross, incomplete hack | ||||
| 48 | # it should be trivial for mst to port this to DQ (and a good | ||||
| 49 | # exercise as well, since we do not yet have such wide tree walking | ||||
| 50 | # in place). For the time being this will work in limited cases, | ||||
| 51 | # mainly complex update/delete, which is really all we want it for | ||||
| 52 | # currently (allows us to fix some bugs without breaking MySQL in | ||||
| 53 | # the process, and is also crucial for Shadow to be usable) | ||||
| 54 | |||||
| 55 | # extract the source name, construct modification indicator re | ||||
| 56 | my $sm = $self->sql_maker; | ||||
| 57 | |||||
| 58 | my $target_name = $_[1]->from; | ||||
| 59 | |||||
| 60 | if (ref $target_name) { | ||||
| 61 | if ( | ||||
| 62 | ref $target_name eq 'SCALAR' | ||||
| 63 | and | ||||
| 64 | $$target_name =~ /^ (?: | ||||
| 65 | \` ( [^`]+ ) \` #` | ||||
| 66 | | ( [\w\-]+ ) | ||||
| 67 | ) $/x | ||||
| 68 | ) { | ||||
| 69 | # this is just a plain-ish name, which has been literal-ed for | ||||
| 70 | # whatever reason | ||||
| 71 | $target_name = (defined $1) ? $1 : $2; | ||||
| 72 | } | ||||
| 73 | else { | ||||
| 74 | # this is something very complex, perhaps a custom result source or whatnot | ||||
| 75 | # can't deal with it | ||||
| 76 | undef $target_name; | ||||
| 77 | } | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | local $sm->{_modification_target_referenced_re} = | ||||
| 81 | qr/ (?<!DELETE) [\s\)] (?: FROM | JOIN ) \s (?: \` \Q$target_name\E \` | \Q$target_name\E ) [\s\(] /xi | ||||
| 82 | if $target_name; | ||||
| 83 | |||||
| 84 | $self->next::method(@_); | ||||
| 85 | } | ||||
| 86 | |||||
| 87 | # here may seem like an odd place to override, but this is the first | ||||
| 88 | # method called after we are connected *and* the driver is determined | ||||
| 89 | # ($self is reblessed). See code flow in ::Storage::DBI::_populate_dbh | ||||
| 90 | # spent 3.32ms (81µs+3.24) within DBIx::Class::Storage::DBI::mysql::_run_connection_actions which was called:
# once (81µs+3.24ms) by DBIx::Class::Storage::DBI::_populate_dbh at line 1056 of DBIx/Class/Storage/DBI.pm | ||||
| 91 | 1 | 200ns | my $self = shift; | ||
| 92 | |||||
| 93 | # default mysql_auto_reconnect to off unless explicitly set | ||||
| 94 | 1 | 45µs | 5 | 16µs | if ( # spent 12µs making 1 call to DBI::common::FETCH
# spent 2µs making 1 call to DBI::common::STORE
# spent 1µs making 2 calls to DBIx::Class::Storage::DBI::_dbh, avg 600ns/call
# spent 1µs making 1 call to DBIx::Class::Storage::DBI::_dbic_connect_attributes |
| 95 | $self->_dbh->{mysql_auto_reconnect} | ||||
| 96 | and | ||||
| 97 | ! exists $self->_dbic_connect_attributes->{mysql_auto_reconnect} | ||||
| 98 | ) { | ||||
| 99 | $self->_dbh->{mysql_auto_reconnect} = 0; | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | 1 | 18µs | 1 | 8µs | $self->next::method(@_); # spent 8µs making 1 call to next::method |
| 103 | } | ||||
| 104 | |||||
| 105 | # we need to figure out what mysql version we're running | ||||
| 106 | # spent 229ms (139+90.2) within DBIx::Class::Storage::DBI::mysql::sql_maker which was called 6000 times, avg 38µs/call:
# 3000 times (86.6ms+64.7ms) by DBIx::Class::Storage::DBI::_select_args at line 2424 of DBIx/Class/Storage/DBI.pm, avg 50µs/call
# 3000 times (52.5ms+25.6ms) by DBIx::Class::Storage::DBI::_gen_sql_bind at line 1649 of DBIx/Class/Storage/DBI.pm, avg 26µs/call | ||||
| 107 | 6000 | 1.35ms | my $self = shift; | ||
| 108 | |||||
| 109 | # it is critical to get the version *before* calling next::method | ||||
| 110 | # otherwise the potential connect will obliterate the sql_maker | ||||
| 111 | # next::method will populate in the _sql_maker accessor | ||||
| 112 | 6000 | 12.4ms | 6000 | 13.2ms | my $mysql_ver = $self->_server_info->{normalized_dbms_version}; # spent 13.2ms making 6000 calls to DBIx::Class::Storage::DBI::_server_info, avg 2µs/call |
| 113 | |||||
| 114 | 6000 | 59.7ms | 6000 | 30.2ms | my $sm = $self->next::method(@_); # spent 30.2ms making 6000 calls to next::method, avg 5µs/call |
| 115 | |||||
| 116 | # mysql 3 does not understand a bare JOIN | ||||
| 117 | 6000 | 8.78ms | $sm->{_default_jointype} = 'INNER' if $mysql_ver < 4; | ||
| 118 | |||||
| 119 | 6000 | 41.9ms | $sm; | ||
| 120 | } | ||||
| 121 | |||||
| 122 | sub sqlt_type { | ||||
| 123 | return 'MySQL'; | ||||
| 124 | } | ||||
| 125 | |||||
| 126 | sub deployment_statements { | ||||
| 127 | my $self = shift; | ||||
| 128 | my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_; | ||||
| 129 | |||||
| 130 | $sqltargs ||= {}; | ||||
| 131 | |||||
| 132 | if ( | ||||
| 133 | ! exists $sqltargs->{producer_args}{mysql_version} | ||||
| 134 | and | ||||
| 135 | my $dver = $self->_server_info->{normalized_dbms_version} | ||||
| 136 | ) { | ||||
| 137 | $sqltargs->{producer_args}{mysql_version} = $dver; | ||||
| 138 | } | ||||
| 139 | |||||
| 140 | $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest); | ||||
| 141 | } | ||||
| 142 | |||||
| 143 | sub _exec_svp_begin { | ||||
| 144 | my ($self, $name) = @_; | ||||
| 145 | |||||
| 146 | $self->_dbh->do("SAVEPOINT $name"); | ||||
| 147 | } | ||||
| 148 | |||||
| 149 | sub _exec_svp_release { | ||||
| 150 | my ($self, $name) = @_; | ||||
| 151 | |||||
| 152 | $self->_dbh->do("RELEASE SAVEPOINT $name"); | ||||
| 153 | } | ||||
| 154 | |||||
| 155 | sub _exec_svp_rollback { | ||||
| 156 | my ($self, $name) = @_; | ||||
| 157 | |||||
| 158 | $self->_dbh->do("ROLLBACK TO SAVEPOINT $name") | ||||
| 159 | } | ||||
| 160 | |||||
| 161 | sub is_replicating { | ||||
| 162 | my $status = shift->_get_dbh->selectrow_hashref('show slave status'); | ||||
| 163 | return ($status->{Slave_IO_Running} eq 'Yes') && ($status->{Slave_SQL_Running} eq 'Yes'); | ||||
| 164 | } | ||||
| 165 | |||||
| 166 | sub lag_behind_master { | ||||
| 167 | return shift->_get_dbh->selectrow_hashref('show slave status')->{Seconds_Behind_Master}; | ||||
| 168 | } | ||||
| 169 | |||||
| 170 | 1 | 6µs | 1; | ||
| 171 | |||||
| 172 | =head1 NAME | ||||
| 173 | |||||
| 174 | DBIx::Class::Storage::DBI::mysql - Storage::DBI class implementing MySQL specifics | ||||
| 175 | |||||
| 176 | =head1 SYNOPSIS | ||||
| 177 | |||||
| 178 | Storage::DBI autodetects the underlying MySQL database, and re-blesses the | ||||
| 179 | C<$storage> object into this class. | ||||
| 180 | |||||
| 181 | my $schema = MyApp::Schema->connect( $dsn, $user, $pass, { on_connect_call => 'set_strict_mode' } ); | ||||
| 182 | |||||
| 183 | =head1 DESCRIPTION | ||||
| 184 | |||||
| 185 | This class implements MySQL specific bits of L<DBIx::Class::Storage::DBI>, | ||||
| 186 | like AutoIncrement column support and savepoints. Also it augments the | ||||
| 187 | SQL maker to support the MySQL-specific C<STRAIGHT_JOIN> join type, which | ||||
| 188 | you can use by specifying C<< join_type => 'straight' >> in the | ||||
| 189 | L<relationship attributes|DBIx::Class::Relationship::Base/join_type> | ||||
| 190 | |||||
| 191 | |||||
| 192 | It also provides a one-stop on-connect macro C<set_strict_mode> which sets | ||||
| 193 | session variables such that MySQL behaves more predictably as far as the | ||||
| 194 | SQL standard is concerned. | ||||
| 195 | |||||
| 196 | =head1 STORAGE OPTIONS | ||||
| 197 | |||||
| 198 | =head2 set_strict_mode | ||||
| 199 | |||||
| 200 | Enables session-wide strict options upon connecting. Equivalent to: | ||||
| 201 | |||||
| 202 | ->connect ( ... , { | ||||
| 203 | on_connect_do => [ | ||||
| 204 | q|SET SQL_MODE = CONCAT('ANSI,TRADITIONAL,ONLY_FULL_GROUP_BY,', @@sql_mode)|, | ||||
| 205 | q|SET SQL_AUTO_IS_NULL = 0|, | ||||
| 206 | ] | ||||
| 207 | }); | ||||
| 208 | |||||
| 209 | =head1 FURTHER QUESTIONS? | ||||
| 210 | |||||
| 211 | Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>. | ||||
| 212 | |||||
| 213 | =head1 COPYRIGHT AND LICENSE | ||||
| 214 | |||||
| 215 | This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE> | ||||
| 216 | by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can | ||||
| 217 | redistribute it and/or modify it under the same terms as the | ||||
| 218 | 1 | 32µs | L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>. # spent 32µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__ | ||
# spent 37µs within DBIx::Class::Storage::DBI::mysql::debug which was called 3 times, avg 12µs/call:
# once (35µs+0s) by DBIx::Class::Storage::DBI::_query_start at line 913 of Class/Accessor/Grouped.pm
# once (800ns+0s) by DBIx::Class::Storage::DBI::_query_start at line 1764 of DBIx/Class/Storage/DBI.pm
# once (600ns+0s) by DBIx::Class::Storage::DBI::_query_end at line 1771 of DBIx/Class/Storage/DBI.pm | |||||
# spent 1µs within DBIx::Class::Storage::DBI::mysql::disable_sth_caching which was called 2 times, avg 500ns/call:
# once (600ns+0s) by DBIx::Class::Storage::DBI::_prepare_sth at line 1846 of DBIx/Class/Storage/DBI.pm
# once (400ns+0s) by DBIx::Class::Storage::DBI::_prepare_sth at line 913 of Class/Accessor/Grouped.pm | |||||
# spent 1µs within DBIx::Class::Storage::DBI::mysql::on_connect_call which was called:
# once (1µs+0s) by DBIx::Class::Storage::DBI::mysql::_run_connection_actions at line 913 of Class/Accessor/Grouped.pm | |||||
# spent 2µs within DBIx::Class::Storage::DBI::mysql::transaction_depth which was called 3 times, avg 633ns/call:
# once (800ns+0s) by DBIx::Class::Storage::DBI::dbh_do at line 837 of DBIx/Class/Storage/DBI.pm
# once (700ns+0s) by DBIx::Class::Storage::BlockRunner::__ANON__[/usr/share/perl5/DBIx/Class/Storage/BlockRunner.pm:233] at line 159 of DBIx/Class/Storage/BlockRunner.pm
# once (400ns+0s) by DBIx::Class::Storage::DBI::dbh_do at line 913 of Class/Accessor/Grouped.pm |