By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,793 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

Arrays & storage.....

P: n/a
Hi

I have few questions in realtion to arrays, I assume that
they are not available as a data type, is this correct ?
The reason why is that I want to store a large amount
of data for a paticular record and a bit concered about the
size of record. (I assuming that an array of 1000 ints will be
smaller than 1000 records of
table dailyclose ( varchar Symbol, int beta ). Is this a fair
assumption ? (I'm not actually concerned with seek time
but rather the physical record size)
Is there any way around my problem or is it time to optimise my
directory structure to ensure that I can large systems.

Thanks
David
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
LeTubs wrote:
I have few questions in realtion to arrays, I assume that
they are not available as a data type, is this correct ?


I believe that is correct. I find no mention of array column types in
the MySQL documentation. FWIW, arrays are not standard SQL data types,
they are extensions offered in some RDBMS implementations.

One workaround would be to store an array in a BLOB column, and leave it
up to your application code to store the array correctly and to fetch it
correctly. But this wouldn't be SQL support for arrays because you
probably can't fetch an individual array element in a SELECT, or update
an individual array element in an UPDATE, or reference individual array
elements in conditions.

Defining a one-to-many table to store each of the 1000 ints per record
would cost more storage space, because you'd need a foreign key field
referencing the parent table. This would add up quickly if you have
many records. Still more space would be required if you also need to
note the position in the array for each element; that is, if the order
of the elements is important. I infer from your example that you'd need
to record the close date for each element:
CREATE TABLE dailyclose (
VARCHAR symbol(20) # =< 1+20 bytes
REFERENCES stock_or_fund(symbol),
INT beta, # 4 bytes
DATE close_date # 3 bytes
);

On the other hand, hard disks are amazingly inexpensive these days, and
buying a new 120GB disk might be cheaper than the amount of extra
programming time it would cost you to work around the lack of array
support in SQL. ;-) There's sometimes a tradeoff between storage
expense, computational expense, and code development expense. Don't get
too focused on just one of these and ignore the others!

And another advantage of the one-to-many table is that you aren't
constrained to 1,000 entries; it can keep growing to as many entries as
you have data for. Also, doing slices for a given calendar year or
other conditions would be pretty easy, since you'd have a DATE field.

Regards,
Bill K.

Jul 20 '05 #2

P: n/a
LeTubs wrote:
The reason why is that I want to store a large amount
of data for a paticular record and a bit concered about the
size of record. (I assuming that an array of 1000 ints will be
smaller than 1000 records of
table dailyclose ( varchar Symbol, int beta ). Is this a fair
assumption ?


You could try it to see which is larger, but I would suggest you to add
data into several rows, instead of putting it all into one row.

Benefits:
- Faster search is perhaps not needed now, but when it is needed, person
to implement that, doesn't need to learn ancient curses to curse you. (
I have seen this in my work. )
- Database structure is much more clear for others to read and see how
it works. This is the first thing you should think of, and only make
more complex structure if it is really needed.

And benefits if putting all data into single row(s):
- AFAIK there is no array-type in MySQL. So you would have to save
integers in a binary format. I can almost promise that that would take
less space on hard drive, I would guess that 20% of disk space would be
saved, but you really should test this to get better results.

(Assuming that data would be saved in binary format with only numbers in
data, no separators. And assuming int is 4 times larger than varchar.
And assuming that table structure would contain no indexes and each row
would only take as much space as the data needs, no more.)
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.