Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^5: find difference in dates/items in same column

by dragonchild (Archbishop)
on Nov 15, 2008 at 17:18 UTC ( #723806=note: print w/replies, xml ) Need Help??

in reply to Re^4: find difference in dates/items in same column
in thread find difference in dates/items in same column

Ok - I'm interested now. I'm going to assume that the following is the table definition:
CREATE TABLE `test` ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,`brand` VARCHAR(255) NOT NULL ,`date` DATE NOT NULL ,INDEX (`brand`,`date`) ,INDEX (`date`,`brand`) );
Given that, you can do something assuming that the number of reads is at least 20x the number of writes (otherwise it's really not that performant). Basically, the idea is to maintain the `rank` column on each INSERT, UPDATE, or DELETE. Your writes get slow, but your reads get fast. This, essentially, is a cache. You can do this maintenance either in code or using a trigger. MySQL has triggers, so that works out nicely.

My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^6: find difference in dates/items in same column
by zerocred (Beadle) on Nov 15, 2008 at 22:32 UTC
    I think your brand/date and reverse date/brand index is a great idea for this and all sorts of other applications! I hadn't thought to set them up quite that way in this case.

    To maintain the rank would mean searching backward through the table to find the last 'brand' entry and its corresponding rank. I'll investgate triggers and think about how to do it when the new records are being inserted rather than after the fact.

    Thanks for all the help! it has been great... Apologies for contaminating a perl forum with what turned out to be a SQL question!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://723806]
[arc444]: hi. Anyone know how to filter the list of methods returned when querying an object in the perl debugger ?
[arc444]: for example : m $obj | grep 'blah'

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2018-01-24 10:33 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (257 votes). Check out past polls.