home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!elroy.jpl.nasa.gov!ames!agate!triplerock.CS.Berkeley.EDU!mao
- From: mao@triplerock.CS.Berkeley.EDU (Mike Olson)
- Newsgroups: comp.databases.theory
- Subject: Re: ordered collections
- Date: 2 Sep 1992 00:48:40 GMT
- Organization: University of California at Berkeley
- Lines: 63
- Message-ID: <181318INNqt3@agate.berkeley.edu>
- References: <cdk.715362552@neptune> <Btwxq5.MBC@world.std.com>
- NNTP-Posting-Host: triplerock.cs.berkeley.edu
-
- In <Btwxq5.MBC@world.std.com>, edwards@world.std.com (Jonathan Edwards)
- writes
-
- > In article <cdk.715362552@neptune> cdk@neptune.dsc.com (Colin Kelley) writes:
- >
- > >Recently someone posted a question about implementing FIFO queues in a
- > >relational database. I'm interested in something even more basic: ordered
- > >collections.
- >
- > HAH! I'm glad you asked that - this is my personal favorite reason why
- > the relational model is a toy (i.e., unhelpful for my real-world needs).
- >
- > A general solution that doesn't require large-scale reorganization ever is to
- > assign some unique key to every row and use that as an 'address' to build a
- > doubly-linked list via forward and backward 'link' fields. But then you lose
- > the ability to have the ordering 'visible' to relational operators.
-
- well, if that's all that's holding you back...
-
- i think you're confusing a paucity of types and extensibility with a
- fundamental flaw in the relational model. i can produce ordered sets
- in postgres in a straightforward way.
-
- here's the strategy: use arbitrary-precision (eg, bcd) decimal numbers,
- or arbitrary-length text strings, as the ordering key for the set. make
- this an attribute of every record. define the following functions inside
- the data manager:
-
- after : record-id -> key
- between : record-id, record-id -> key
- before : record-id -> key
-
- when you insert a record, you say
-
- append my_relation (name = "mike", age = 30,
- setloc = between(337, 445))
-
- where 337 and 445 are unique record identifiers that identify records in
- my_relation; the database system generates these for me when i insert a
- new record.
-
- my functions after, before, and between identify the two records adjacent
- to the new record, and generate a new unique key by examining the setloc
- attributes of those records. i can write the functions to use two-phase
- locking to exclude concurrent updates to the same location in the list,
- so the solution will be correct. a btree or hash index can make it fast
- to locate existing records and generate new keys.
-
- using this strategy, you can still see the ordering using algebraic
- operators, you can exploit it (or not) when you retrieve values, and
- you can guarantee ordered set semantics.
-
- note that i haven't violated the relational model here; the only reason
- that i can do this and you can't is that my database system lets me
- define new types and operators whenever i want.
-
- there's no question that relational databases are ill-suited for some
- applications, but this isn't necessarily one of them.
-
- mike olson
- project sequoia 2000
- uc berkeley
- mao@cs.berkeley.edu
-