Perl Hashes and MySQL database

  • Thread starter Andreas Sonnenbichler
  • Start date
A

Andreas Sonnenbichler

Hello,

maybe, its a too simple question, but I don't know where to start:

I have a extremely big hash (almost 1GB mem), looking like this:
$hash->{$id}->{$row}.

I want to store this hash in ONE MySQL database table, so that $id marks one
db entity, and all keys (in row) are stored together in one other db field.

Like this:
+++++++++++++++++++++++++++++++++++++++++
+ ID + Value +++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++
+ id1 + id1-row1, id1-row2, id1-row3, ...
+ id2 + id2-row1, id1-row3, id1-row7, ...

Is there any FAST possibility. I mean, of course I can concatenate all
row-values and write the resulting hash manually by any loop writeing all
id's. But is there something thats makes it faster? Like tieing or so?

Andreas
 
I

Ingo Wiarda

Andreas said:
I have a extremely big hash (almost 1GB mem), looking like this:
$hash->{$id}->{$row}.

I want to store this hash in ONE MySQL database table, so that $id marks
one db entity, and all keys (in row) are stored together in one other db
field.

Like this:
+++++++++++++++++++++++++++++++++++++++++
+ ID + Value +++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++
+ id1 + id1-row1, id1-row2, id1-row3, ...
+ id2 + id2-row1, id1-row3, id1-row7, ...

Is there any FAST possibility. I mean, of course I can concatenate all
row-values and write the resulting hash manually by any loop writeing all
id's. But is there something thats makes it faster? Like tieing or so?

1. You want all keys in one big string to put them into the Value column.
Seems like you will only accomplish this by concatenation: eg,
join(",", keys $hash->{$id});
2. Tie could make read/write access to the db easier, but not faster, if you
are going to cram the whole hash into the db at once.
3. How fast (and what) is your current approach? Have you tried dumping the
hash to a file and importing it into MySQL via "load data infile" (I used
this for a 160 MB file)?

Ingo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top