home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / database / theory / 438 < prev    next >
Encoding:
Internet Message Format  |  1992-09-01  |  3.0 KB

  1. Path: sparky!uunet!elroy.jpl.nasa.gov!ames!agate!triplerock.CS.Berkeley.EDU!mao
  2. From: mao@triplerock.CS.Berkeley.EDU (Mike Olson)
  3. Newsgroups: comp.databases.theory
  4. Subject: Re: ordered collections
  5. Date: 2 Sep 1992 00:48:40 GMT
  6. Organization: University of California at Berkeley
  7. Lines: 63
  8. Message-ID: <181318INNqt3@agate.berkeley.edu>
  9. References: <cdk.715362552@neptune> <Btwxq5.MBC@world.std.com>
  10. NNTP-Posting-Host: triplerock.cs.berkeley.edu
  11.  
  12. In <Btwxq5.MBC@world.std.com>, edwards@world.std.com (Jonathan Edwards)
  13. writes
  14.  
  15. > In article <cdk.715362552@neptune> cdk@neptune.dsc.com (Colin Kelley) writes:
  16. > >Recently someone posted a question about implementing FIFO queues in a
  17. > >relational database.  I'm interested in something even more basic:  ordered
  18. > >collections.
  19. > HAH! I'm glad you asked that - this is my personal favorite reason why
  20. > the relational model is a toy (i.e., unhelpful for my real-world needs).
  21. > A general solution that doesn't require large-scale reorganization ever is to
  22. > assign some unique key to every row and use that as an 'address' to build a 
  23. > doubly-linked list via forward and backward 'link' fields. But then you lose
  24. > the ability to have the ordering 'visible' to relational operators.
  25.  
  26. well, if that's all that's holding you back...
  27.  
  28. i think you're confusing a paucity of types and extensibility with a
  29. fundamental flaw in the relational model.  i can produce ordered sets
  30. in postgres in a straightforward way.
  31.  
  32. here's the strategy:  use arbitrary-precision (eg, bcd) decimal numbers,
  33. or arbitrary-length text strings, as the ordering key for the set.  make
  34. this an attribute of every record.  define the following functions inside
  35. the data manager:
  36.  
  37.     after : record-id -> key
  38.     between : record-id, record-id -> key
  39.     before : record-id -> key
  40.  
  41. when you insert a record, you say
  42.  
  43.     append my_relation (name = "mike", age = 30,
  44.                 setloc = between(337, 445))
  45.  
  46. where 337 and 445 are unique record identifiers that identify records in
  47. my_relation; the database system generates these for me when i insert a
  48. new record.
  49.  
  50. my functions after, before, and between identify the two records adjacent
  51. to the new record, and generate a new unique key by examining the setloc
  52. attributes of those records.  i can write the functions to use two-phase
  53. locking to exclude concurrent updates to the same location in the list,
  54. so the solution will be correct.  a btree or hash index can make it fast
  55. to locate existing records and generate new keys.
  56.  
  57. using this strategy, you can still see the ordering using algebraic
  58. operators, you can exploit it (or not) when you retrieve values, and
  59. you can guarantee ordered set semantics.
  60.  
  61. note that i haven't violated the relational model here; the only reason
  62. that i can do this and you can't is that my database system lets me
  63. define new types and operators whenever i want.
  64.  
  65. there's no question that relational databases are ill-suited for some
  66. applications, but this isn't necessarily one of them.
  67.  
  68.                     mike olson
  69.                     project sequoia 2000
  70.                     uc berkeley
  71.                     mao@cs.berkeley.edu
  72.