Quote identifiers

Hello.
Quote all identifiers with DBI.
Best regards. Ruslan.

quote_identifier.patch (1.31 KB)

Hello.
Quote all identifiers with DBI.
Best regards. Ruslan.

Any reason you’re assigning $self->dbi to $dbi and using that?

Jesse Vincent wrote:

Hello.
Quote all identifiers with DBI.
Best regards. Ruslan.

Any reason you’re assigning $self->dbi to $dbi and using that?
you mean dbh? yes, it’s required, because quote_identifier like quote is
method of the database handle not statement.

Any reason you’re assigning $self->dbi to $dbi and using that?
you mean dbh? yes, it’s required, because quote_identifier like quote is
method of the database handle not statement.

Er. Sorry. There’s code of the form:

my $dbh = $self->dbh;

$dbh->quote_identifier();

Since it’s just a reference, I don’t quite understand the point.

Jesse Vincent wrote:

Any reason you’re assigning $self->dbi to $dbi and using that?

you mean dbh? yes, it’s required, because quote_identifier like quote is
method of the database handle not statement.

Er. Sorry. There’s code of the form:

my $dbh = $self->dbh;

$dbh->quote_identifier();

Since it’s just a reference, I don’t quite understand the point.

Speed. See next benchmark
#!/usr/bin/perl -w

use strict;
use Benchmark qw(cmpthese);
my $obj = new Dummy;

cmpthese (-6, {
‘with $dbh’ => sub { $obj->w_cache(); },
‘without $dbh’ => sub { $obj->wo_cache() },
});

package Dummy;

sub new { return bless { dbh => { foo => ‘bar’ } }, ‘Dummy’ }
sub dbh { my $self = shift; return $self->{‘dbh’} }

sub w_cache {
my $self = shift;
my $dbh = $self->dbh;
for(1…5) { my $x = $dbh->{foo} }
}
sub wo_cache {
my $self = shift;
for(1…5) {my $x = $self->dbh->{foo} }
}
Results:
Rate without $dbh with $dbh
without $dbh 43465/s – -40%
with $dbh 72127/s 66% –

Something similar happens in sub Insert I call quote_identifier in map
context for each column, also dbh sub in SB::Handle more complex then in
benchmark.

Similar situation in UpdateRecordValue.

Speed. See next benchmark

At the expense of clarity. I hate perl’s method dispatch
performance. Will you update the patch with a comment about why
you’re doing something that looks like it should be optimized away so
that someone else doesn’t “fix” it?

             Rate without $dbh    with $dbh

without $dbh 43465/s – -40%
with $dbh 72127/s 66% –

Something similar happens in sub Insert I call quote_identifier in map
context for each column, also dbh sub in SB::Handle more complex then
in benchmark.

Potential Micro-optimization. How often are these really called?

Benchmarks that show improvements in tight loops are great, and I love
them, but when the code isn’t actually run in a tight loop, it’s kind
of meaningless.

For this kind of statement I’d guess that the time required to
actually run the kind of database queries we run greatly dwarfs the
time saved by using a temporary. Kind of like a shortcut that saves 5
minutes out of a five hour drive.

-R

Jesse Vincent wrote:

Speed. See next benchmark

At the expense of clarity. I hate perl’s method dispatch
performance. Will you update the patch with a comment about why
you’re doing something that looks like it should be optimized away so
that someone else doesn’t “fix” it?
I resubmit patch where thing looks like you want. Done more complex test
that insert 5000 records into SQLite DB. Same time results for both
variants.

quote_identifier.patch (1.22 KB)

Thanks. Applied.On Sun, Jan 23, 2005 at 01:54:30AM +0300, Ruslan U. Zakirov wrote:

Jesse Vincent wrote:

Speed. See next benchmark

At the expense of clarity. I hate perl’s method dispatch
performance. Will you update the patch with a comment about why
you’re doing something that looks like it should be optimized away so
that someone else doesn’t “fix” it?
I resubmit patch where thing looks like you want. Done more complex test
that insert 5000 records into SQLite DB. Same time results for both
variants.

#!/usr/bin/perl -w

use strict;
use Benchmark qw(cmpthese);
my $obj = new Dummy;

cmpthese (-6, {
‘with $dbh’ => sub { $obj->w_cache(); },
‘without $dbh’ => sub { $obj->wo_cache() },
});

package Dummy;

sub new { return bless { dbh => { foo => ‘bar’ } }, ‘Dummy’ }
sub dbh { my $self = shift; return $self->{‘dbh’} }

sub w_cache {
my $self = shift;
my $dbh = $self->dbh;
for(1…5) { my $x = $dbh->{foo} }
}
sub wo_cache {
my $self = shift;
for(1…5) {my $x = $self->dbh->{foo} }
}
Results:
Rate without $dbh with $dbh
without $dbh 43465/s – -40%
with $dbh 72127/s 66% –

Something similar happens in sub Insert I call quote_identifier in map
context for each column, also dbh sub in SB::Handle more complex then in
benchmark.

Similar situation in UpdateRecordValue.