Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: How to count rows using DBI & mysql - Performance results

by jepri (Parson)
on Jun 11, 2001 at 20:20 UTC ( #87565=note: print w/ replies, xml ) Need Help??


in reply to Re: How to count rows using DBI & mysql - Performance results
in thread How to count rows using DBI & mysql - Performance results

This trick has caused me problems. At one point I had Tie::DBI crashing when it got an error from the POSTGRESQL database saying the the database couldn't insert a row. I don't know why, but I had to work around by doing the SQL myself :(

Also, talking coding style, finding out if you can do something by seeing if it throws an error is probably a worse option than checking for it cleanly in the first place.

____________________
Jeremy
I didn't believe in evil until I dated it.


Comment on Re: Re: How to count rows using DBI & mysql - Performance results
Re: Re: Re: How to count rows using DBI & mysql - Performance results
by Zaxo (Archbishop) on Jun 11, 2001 at 23:11 UTC

    My point was to demonstrate the property of unique indexes which prevent duplication: a safety measure. I never said to use the error for program control. In fact I didn't exhibit any DBI code at all.

    In practice, with the index in place:

    my $known_dep=$dbi->prepare_cached("select 1 from depends where usedby +=? and uses=?"); sub known_dep ($$) {#prototype because we have a fixed number of place +holders $known_dep->execute(@_); $known_dep->rows; # 1 or 0 for unique index. }

    For frequent operations, we can improve performance with the sth->bind_params() method.

    We search on an index, using a pre-prepared statement handle with placeholders. That will be fast.

    I didn't mention before that NULL in multiindexes is only available in MyISAM tables.

    After Compline,
    Zaxo

Re: Re: Re: How to count rows using DBI & mysql - Performance results
by elwarren (Curate) on Jun 11, 2001 at 23:14 UTC
    It is definitly a coding style question, because we do it all over the place with PL/SQL in Oracle. Though this would not generate an error, just an exception. We use the same technique to see if a query a row from cache, if it returns an exception then we hit the table instead.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://87565]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2014-08-27 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (233 votes), past polls