Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^5: For a better efficiency and speed question!

by pvaldes (Chaplain)
on Oct 04, 2011 at 18:11 UTC ( #929623=note: print w/ replies, xml ) Need Help??


in reply to Re^4: For a better efficiency and speed question!
in thread For a better efficiency and speed question!

Nothing wrong really, but you ask for efficiency and speed, and anything counts...

You use: AND ((date + 1 YEAR) < (CURRENT_DATE + 240 DAYS))

Let's see the algoritm. For each record you sum 365 to date and remember this number, then you sum 240 to current date and save this to a new var somewhere in the memory, then you compare both numbers

I'm suggesting this instead: AND ((date + 125 DAYS) < CURRENT_DATE)

Now for each record you sum 125 to date and compare this with current date. You are creating a new var, not two.

Thus you need less memory and is also a little less demanding operation for the CPU. Nothing to care for when you have a few sums but in this context could suppose one advantage


Comment on Re^5: For a better efficiency and speed question!
Select or Download Code
Re^6: For a better efficiency and speed question!
by pvaldes (Chaplain) on Oct 04, 2011 at 18:17 UTC
    And now for the sql question, if not done yet, you should index or reindex your table (the controlnum field is a good candidate to be in the index) and probably use some views in order to check only a part of your table, and simplify the work to perl.
      I didn't understand your logic behind sum of 125 to "date"??

        I'm talking of 125 days of course, but this is not relevant here cause the "problem" is not in the data type, it is in the equation doing the comparison. Incidentally we are talking about a time here, but will be the same using any type of data that can be converted to a number, and that you can sum later to other number.

        if:  (X + 5) < (Y + 4) then: X + 1 < Y

        And all of this leads us to this more compact and probably more desirable form of the query:

        =code my $sql = $dbh->exec_select("SELECT acc,name,date FROM mytable WHERE name != '' AND CURDATE() BETWEEN date + 125 DAYS and date + 365 DAYS AND date BETWEEN '2010-11-11' and '2011-11-11' AND controlnum IN ('00988777','009999','12345','77766','88776','998888 +','2222333','2223999','8877788','9988877','9988888','9998877','999888 +8','9999888','11220000','11223756','22339668','22388577','23334455',' +77665555','88877777','112223333','222339000','223445988','223475699', +'666555555','887777654','88777766666','888777666666') order by date desc"); =cut

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2014-09-18 05:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (108 votes), past polls