473,659 Members | 2,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Arrays & storage.....

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
2 1787
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(s ymbol),
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
11768
by: csx | last post by:
Hi everyone! two quick questions relating to arrays. Q1, Is it possible to re-assign array elements? int array = {{2,4}, {4,5}}; array = {2,3}
5
3086
by: Gent | last post by:
I have two questions which are very similar: Is it possible to return an object in C++. Below is part of my code for reference however I am more concerned about the concept. It seems like the function below is returning a pointer to pointers who are GUID. I am trying to write a wrapper to use in my VB code and what I would prefer to do is be able to return an array of GUID. I remember (not sure) that the concept of arrays does not really...
11
4455
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to accomplish. // - - - - - - - - begin code - - - - - - - typedef int sm_t; typedef int bg_t; sm_t sm; bg_t bg;
1
2004
by: Nathan Gilbert | last post by:
I have a function that is returning a 2D array (declared using double pointers) and I want to be able to append a row of data to the beginning and end of this array without having to create a new 2D array and iterate through copy contents from arrays into this new 2D array. Example: int ** someArray; int * topRow; int * bottomRow;
32
2560
by: santosh | last post by:
In following code char str = "asdf" ; str = 's' ; is possible. But char *str = "asdf" ; str = 's' ; is an run-time error. What i understand is *str = "asdf" is stored in Read-only-Memory. Where
6
1743
by: Broeisi | last post by:
Hello, I wrote the tiny progam below just to understand arrays and strings better. I have 2 questions about arrays and strings in C. 1. Why is it that when you want to assign a string to an character array that you must use the strcpy() function?
39
19618
by: Martin Jørgensen | last post by:
Hi, I'm relatively new with C-programming and even though I've read about pointers and arrays many times, it's a topic that is a little confusing to me - at least at this moment: ---- 1) What's the difference between these 3 statements: (i) memcpy(&b, &KoefD, n); // this works somewhere in my code
41
4928
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in the hash are alphabetically sorted if the key happens to be alpha numeric. Which I believe makes sense because it allows for fast lookup of a key.
2
2001
by: Dr Dav | last post by:
Hello all, I'm a physicist whose rewriting a numerical simulation, previously written in IDL, in C with the goal reducing runtime. As you may imagine, my C programming skills are quite poor but I am learning. My problem is this. I had sucessfully written a C code that worked ( with considerable speedup over the IDL version ) using an array size of 100x100. However, I am working towards making the array size closer to 300x300. Since I had...
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8339
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8629
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.