[CDBI] Null Column Causing Repeated DB Calls

eric.berg at barclayscapital.com eric.berg at barclayscapital.com
Fri Feb 26 17:59:18 GMT 2010


Hey, Aaron.  The problem appears to be that calls to the accessors for columns with null values is the cause for the additional request to the database.

That means that even an assignment, conditional on a "true" value as in 

my $x = $obj->offending_attribute if $obj->offending_attribute;

Still hits the db to get the value, regardless of whether the column is in the Essential or Others column groups.

I wound up doing this:

sub some_name {
    my $self = shift;
    if (my $val = $self->_attrs(qw/some_name/)) {
        return $val;
    } else {
        return;
    }
}

But it seems that I'd have to do that for every column that could ever contain a NULL value.

Eric

> -----Original Message-----
> From: Aaron Dalton [mailto:aaron at daltons.ca] 
> Sent: Friday, February 26, 2010 12:31 PM
> To: classdbi at lists.digitalcraftsmen.net; Berg, Eric: IT (NYK)
> Subject: Re: [CDBI] Null Column Causing Repeated DB Calls
> 
> On 26/02/2010 10:28 AM, Aaron Dalton wrote:
> > On 26/02/2010 9:21 AM, eric.berg at barclayscapital.com wrote:
> >> I'm optimizing one of my cdbi classes and found that one 
> of my columns often contains a NULL value, and when I iterate 
> through a set of results from a search_* query, when I 
> attempt to do assignments of that attribute, cdbi is making 
> another call to the db just to retrieve that value, when it's 
> value is NULL slowing things down considerably.
> >>
> >> I'm about to try to override the accessor for that column, 
> but I'm wondering if there's a way to address this issue 
> within cdbi in general.
> >>
> >> Anybody have any advice on the matter?
> >>
> > 
> > I'm a relative n00b, but can't you just declare that column 
> as "Other"?
> >  That should mean it won't every fetch the value unless explicitly
> > requested.
> > 
> > 
> http://search.cpan.org/~tmtm/Class-DBI-v3.0.17/lib/Class/DBI.p
> m#LAZY_POPULATION
> > 
> 
> Oops!  Re-reading your message, what you would do is set the column as
> "Essential" so it is immediately loaded at construction time, 
> obviating
> the need for separate DBI calls.
> 
> Aaron
> 
> 
_______________________________________________

This e-mail may contain information that is confidential, privileged or otherwise protected from disclosure. If you are not an intended recipient of this e-mail, do not duplicate or redistribute it by any means. Please delete it and any attachments and notify the sender that you have received it in error. Unless specifically indicated, this e-mail is not an offer to buy or sell or a solicitation to buy or sell any securities, investment products or other financial product or service, an official confirmation of any transaction, or an official statement of Barclays. Any views or opinions presented are solely those of the author and do not necessarily represent those of Barclays. This e-mail is subject to terms available at the following link: www.barcap.com/emaildisclaimer. By messaging with Barclays you consent to the foregoing.  Barclays Capital is the investment banking division of Barclays Bank PLC, a company registered in England (number 1026167) with its registered office at 1 Churchill Place, London, E14 5HP.  This email may relate to or be sent from other members of the Barclays Group.
_______________________________________________



More information about the ClassDBI mailing list