Jeff North wrote:
| 2d array size: 5000 x 5000
| each element: int 4 bytes
CREATE TABLE `tblArray` (
`fRow` int(11) NOT NULL default '0',
`fCol` int(11) NOT NULL default '0',
KEY `IDXrow` (`fRow`),
KEY `IDXcol` (`fCol`)
) TYPE=MyISAM;
One should add a field for the data at a given array element. And
presumably one would want a 2-d array per record of another table, so
one should add a foreign key referencing the parent table.
CREATE TABLE `tblArray` (
`fRow` int(11) NOT NULL default '0',
`fCol` int(11) NOT NULL default '0',
`elementData` integer,
`parentRef` integer not null references parentTable(pri maryKey)
KEY `IDXrow` (`fRow`),
KEY `IDXcol` (`fCol`)
) TYPE=MyISAM;
Then you could fetch the array as follows:
select fRow, fCol, elementData
from parentTable P inner join tblArray A on P.primaryKey = A.parentRef
You can fetch totals by column as follows:
select fCol, sum(elementData )
from parentTable P inner join tblArray A on P.primaryKey = A.parentRef
group by fCol;
See also chapter 23 of "SQL for Smarties" by Joe Celko. He talks about
storing and using array structures in SQL databases.
Regards,
Bill K.