home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / database / 6373 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  2.3 KB

  1. Xref: sparky comp.databases:6373 comp.databases.theory:409 comp.databases.oracle:1401
  2. Path: sparky!uunet!mcsun!uknet!keele!csa09
  3. From: csa09@seq1.keele.ac.uk (Paul Singleton)
  4. Newsgroups: comp.databases,comp.databases.theory,comp.databases.oracle
  5. Subject: Re: Is this a bug or a limitation of the SQL language
  6. Message-ID: <3884@keele.keele.ac.uk>
  7. Date: 27 Aug 92 15:47:01 GMT
  8. References: <BtJKIG.2K5@watdragon.uwaterloo.ca>
  9. Organization: University of Keele, England
  10. Lines: 63
  11.  
  12. The problems with
  13.  
  14. >   |select * from emp 
  15. >   |where salary between
  16. >   |(select salary from emp where ename = 'Larry')
  17. >   |and
  18. >   |(select salary from emp where ename = 'John')
  19.  
  20. partly stem from SQL being insufficiently _abstract_: there are
  21. unnecessarily many ways to express the same query.
  22.  
  23. After some experience with Prolog, I now resort to a predicate-calculus-like
  24. notation at the thinking-on-paper stage, e.g.
  25.  
  26.     answer( A, B, C, D, E, F, G, H) :-
  27.         emp( _, 'Larry', _, _, _, S1, _, _),
  28.         emp( _, 'John', _, _, _, S2, _, _),
  29.         emp( A, B, C, D, E, F, G, H),
  30.         between( S1, S2, F).
  31.  
  32. Now I'm not seriously proposing that as a query language, and maybe I'm
  33. just familiar with that idiom anyway, but it seems closer to the truth
  34. of what I want, with fewer premature evaluation decisions.
  35. (the less said about Prolog's efficiency in this case, the better :-)    
  36.  
  37. A better example:
  38.  
  39.     answer( A) :-
  40.         table1( A),
  41.         not table2( A).
  42.  
  43. which has as least three SQL equivalents (and three plans under Oracle V6):
  44.  
  45.     select A from TABLE1
  46.     minus select A from TABLE2;
  47.  
  48.         projection
  49.          \--minus
  50.              \--sort(unique)
  51.              |   \--table access(full) TABLE1
  52.              \--sort(unique)
  53.                  \--table access(full) TABLE2
  54.  
  55.     select A from TABLE1 X
  56.     where A not in ( select A from TABLE2 where A =X.A );
  57.  
  58.         filter
  59.          \--table access(full) TABLE1
  60.          \--table access(full) TABLE2
  61.  
  62.     select A from TABLE1
  63.     where not exists ( select A from TABLE2 );
  64.  
  65.         filter
  66.          \--table access(full) TABLE1
  67.          \--index(range scan) TABLE2_INDEX
  68.  
  69. I want to be able to say WHAT I WANT, without having to decide HOW TO GET IT.
  70. ----
  71.   __   __    Paul Singleton (Mr)           JANET: paul@uk.ac.keele.cs
  72.  |__) (__    Computer Science Dept.        other: paul@cs.keele.ac.uk
  73.  |  .  __).  Keele University, Newcastle,    tel: +44 (0)782 621111 x7355
  74.              Staffs ST5 5BG, ENGLAND         fax: +44 (0)782 713082
  75.