I have a 1000×1000 matrix, with some data in each entry.
Is it possible to store it sequentially (ie, a row next to the previous one) in a table? I mean, if I could just access the table “by offset” (just like an array), given I won’t add/delete any entry, I would save space for the key, which is blatantly redundant here.
Is it possible? Thanks!
Tables don’t have an order. There is no sequence to them. The key is not redundant because it tells you how to access your data. If I were to model this I would do it like so:
Now, if you want to get a value by row number and column number then you can quickly get that with:
If you want to get it by an offset then you could use something like:
As for saving storage, you’re talking about 4 bytes per row here, with a matrix that has a maximum of 1M rows. For any serious RDBMS that’s pretty irrelevant.