Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

Database cache 500 points

Hi Experts!

I want to cache a recordset of 500,000 records with 7 fields in it (date, stock, open, high, low, close, volume).  Assume the first field is the date, and the second field is a stock.

I was thinking I could put them into an array.  However I am worried that I will not be able to sort these records effieciently.  Like if I wanted to find IBM from 1-1-01 to 1-1-02.  Or if i wanted to all stocks and their respective prices on 1-1-01.  

I know this has been done before and I dont want to reinvent the wheel here.  What is the best way to cache all this info into memery, and still have the functionality of doing simple select queries?

Thanks for your help!


0
OptionsMM
Asked:
OptionsMM
  • 2
1 Solution
 
AxterCommented:
The right solution is to have multiple indexes for your database.
Each field that you need to look-up, have it set as an index in your database table.

Your database then should be able to query the information quickly.

What database are you using?
0
 
OptionsMMAuthor Commented:
I am not interested in indices (it is only one large table).
Can I cache the whole table using arrays?


0
 
AxterCommented:
>>I am not interested in indices (it is only one large table).
>>Can I cache the whole table using arrays?

If you have the RAM, yes.
But accessing the data would not be as efficient as it would be if you indexed the table.

You don't need multiple talbes to justify indexing a table.
Many databases only have one table and multiple indexes associated with the one table.

An index is a method that allows you to access a record in the table very fast using a field other then the primary filed.

If you want to put the record into RAM you can use a vector<> template class, however you're going to need a lot of RAM to hold 500,000.  And this method will still not access the data quickly.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now