Skip Menu |

This queue is for tickets about the SQL-Abstract CPAN distribution.

Report information
The Basics
Id: 2511
Status: resolved
Priority: 0/
Queue: SQL-Abstract

People
Owner: Nobody in particular
Requestors: mark [...] summersault.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.10
Fixed in: (no value)



Subject: "where" key should be sorted, to allow for better performance
Hello, This is a follow up on and old conversation about performance when compared to DBIx::Abstract module. The issue came up at the time that perhaps the hash key ordering wasn't reliable. After consulting with meryln and tye at PerlMonks, I have a solution. The answer is to sort the keys in the hash so they are in a reliable order. This should be backwards compatible because the keys were already being returned in an apparently random order anyway. This allows you to use SQL::Abstract to prepare a statement once, and then call it repeatedly with just the bind variables. Future hashes passed in with the same keys should sort the same way, and thus return bind variables in the same order. A seperate which list request would be to have a way to explictly order the bits of the SQL statement, for cases when the order could make a difference with the SQL performance. Thanks again for the useful module! Here's my patch to sort the keys. It needs some more testing: --- /usr/local/lib/perl5/site_perl/5.8.0/SQL/Abstract.pm Fri Sep 27 13:06:32 2002 +++ Abstract.pm Tue May 6 10:19:48 2003 @@ -350,7 +350,8 @@ return wantarray ? ($wsql, @sqlv) : $wsql; } elsif (ref $where eq 'HASH') { - while (my($k,$v) = each %$where) { + for my $k (sort keys %$where) { + my $v = $where->{$k}; if (! defined($v)) { # undef = null push @sqlf, "$k $SQL{null}";
From: "Nathan Wiger" <nate [...] wiger.org>
To: <bug-SQL-Abstract [...] rt.cpan.org>
Subject: Re: [cpan #2511] "where" key should be sorted, to allow for better performance
Date: Tue, 6 May 2003 10:09:49 -0700
RT-Send-Cc:
Ok, I will take a look at this. Looks good at first glance. -Nate Show quoted text
----- Original Message ----- From: " via RT" <bug-SQL-Abstract@rt.cpan.org> To: <AdminCc of cpan Ticket #2511 :> Sent: Tuesday, May 06, 2003 8:27 AM Subject: [cpan #2511] "where" key should be sorted, to allow for better performance
> > This message about SQL-Abstract was sent to you by MARKSTOS
<MARKSTOS@cpan.org> via rt.cpan.org
> > Full context and any attached attachments can be found at: > <URL: https://rt.cpan.org/Ticket/Display.html?id=2511 > > > Hello, > > This is a follow up on and old conversation about performance when
compared to DBIx::Abstract module. The issue came up at the time that perhaps the hash key ordering wasn't reliable.
> > After consulting with meryln and tye at PerlMonks, I have a
solution. The answer is to sort the keys in the hash so they are in a reliable order. This should be backwards compatible because the keys were already being returned in an apparently random order anyway.
> > This allows you to use SQL::Abstract to prepare a statement once,
and then call it repeatedly with just the bind variables. Future hashes passed in with the same keys should sort the same way, and thus return bind variables in the same order.
> > A seperate which list request would be to have a way to explictly
order the bits of the SQL statement, for cases when the order could make a difference with the SQL performance.
> > Thanks again for the useful module! Here's my patch to sort the
keys. It needs some more testing:
> > --- /usr/local/lib/perl5/site_perl/5.8.0/SQL/Abstract.pm
Fri Sep 27 13:06:32 2002
> +++ Abstract.pm Tue May 6 10:19:48 2003 > @@ -350,7 +350,8 @@ > return wantarray ? ($wsql, @sqlv) : $wsql; > } > elsif (ref $where eq 'HASH') { > - while (my($k,$v) = each %$where) { > + for my $k (sort keys %$where) { > + my $v = $where->{$k}; > if (! defined($v)) { > # undef = null > push @sqlf, "$k $SQL{null}"; >
Integrated into 1.13, thanks