Re: database theory

new topic     » goto parent     » topic index » view thread      » older message » newer message

On Fri, 20 Nov 1998 10:37:13 -0500, Alan Tu <ATU5713 at COMPUSERVE.COM> wrote:

>In the Euphoria package somewhere, (it might have been in the demo
>program), it said that to create a large database one would use seek and
>where.  Could someone please explain to me how that would be done to access
>a database?  Thanks.
>
Hi, Alan:

In a large database, for example, 50,000 names and addresses,
you have more data than will fit into memory comfortably.
Plus, even if you could load it in all at once, the disk
activity would take a long time. Same when saving the updated
data.

Therefore, it is better to read/write a single record at a
time, making disk i/o very quick.
If you keep a sorted list of keys, you can find any
record in the file with 8 seeks or less - doing a binary
search.

The difficulty here is that Euphoria stores variable
length records (sequences). How do you know which byte in the
file is the first byte of Alan Tu's name and address?
Two solutions: the easy one, and the one that I don't want
to bother writing:

Easy one: write all records to the same, fixed length.
Let's say a name and address record is always 256 bytes long.
You want the 3rd name in the file, so you seek byte
(256 * 3), and read 256 bytes. This also makes updates
to the file easy, since you're just writing 256 new bytes
over 256 old.

The other way involves a "linked list" approach, with
variable length records, where the record length is stored
in the record,or in a separate index file, so you can
"leapfrog" that record and be at the beginning of the  next.
This can get really complex fast.

Suppose you have to change Alan Tu's name to Alan W. Tu?
Now your record is longer than before, so if you put it back
where it was, you will overwrite part of the next record.
What to do? There are books written on this.

Regards,
Irv

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu