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

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!sdd.hp.com!hplabs!ucbvax!HPLWK.HPL.HP.COM!albert
  2. From: albert@HPLWK.HPL.HP.COM (Joseph Albert)
  3. Newsgroups: comp.databases
  4. Subject: Re: Proposed Bug in Sybase 4.2
  5. Message-ID: <9208200432.AA06288@hplwk.hpl.hp.com>
  6. Date: 20 Aug 92 04:32:59 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Lines: 86
  9.  
  10. References: <1992Aug19.180433.16976@infonode.ingr.com>
  11. Sender: 
  12. Followup-To: 
  13. Distribution: 
  14. Organization: Hewlett-Packard Laboratories -- Database Technology Dept
  15. Keywords: 
  16.  
  17. In article <1992Aug19.180433.16976@infonode.ingr.com> srb@barakam.b17d.ingr.com (Sreedhar Barakam) writes:
  18. >I have a Sybase 4.2 server(on SunOS 4.1.2) which has two tables
  19. >t1,t2. They are populated like this:
  20. >
  21. >  t1  t2
  22. >  c1  c1
  23. >  1   1
  24. >      2
  25. >      3
  26. >      4
  27. >      5
  28. >      6
  29. >      7
  30. >      8
  31. >      9
  32. >     10
  33. >
  34. >For both of the following queries:
  35. >
  36. > select t1.c1 from t1,t2 where t1.c1 < t2.c1  
  37. >select * from t1 where c1 <any (select c1 from t2)
  38. >
  39. >The results are:
  40. > c1
  41. > -----------
  42. >           1
  43. >           1
  44. >           1
  45. >           1
  46. >           1
  47. >           1
  48. >           1
  49. >           1
  50. >           1
  51.  
  52. This is NOT a bug, but the correct answer to the query according to the
  53. specified semantics of SQL. (If you don't agree with the semantics of
  54. SQL, that is a different issue.)
  55.  
  56. When you write a query, 
  57.  
  58. SELECT t1.c1 FROM t1,t2 WHERE t1.c1 < t2.c1  
  59.  
  60. you are asking for a result which could be defined by:
  61.  
  62. 1. take the cross product of t1 and t2
  63. 2. select those tuples from this cross product in which t1.c1 < t2.c2
  64. 3. project the result of step 2 onto the column t1.c1
  65.  
  66. of course, the dbms does not have to compute according to this 3-step
  67. procedure, i'm just using it to define the correct result.
  68.  
  69. the query you seem to be interested in is either:
  70.  
  71. a. select all t1 tuples for which there exists a t2 tuple with t1.c1 < t2.c1
  72.  
  73. -or-
  74.  
  75. b. select all t1 tuples for which t1.c1 is smaller than the c1 field of
  76.    every t2 tuple.
  77.  
  78. such existential and universal quantification is most naturally expressed
  79. in the domain calculus, but, alas, for better or worse we are stuck with
  80. SQL as a standard. in SQL, one uses the EXISTS function, which is really
  81. a test for emptiness of a correlated subquery (which can be used to construct
  82. queries semantically equivalent to any query requiring a quantifier in
  83. relational calculus):
  84.  
  85. a. SELECT c1 FROM t1 WHERE EXISTS (SELECT * FROM t2 WHERE t1.c1 < t2.c1);
  86.  
  87. b. SELECT c1 FROM t1 WHERE NOT EXISTS 
  88.                 (SELECT * FROM t2 WHERE ((t1.c1 > t2.c2) OR (t1.c1 = t2.c2)));
  89.  
  90.  
  91. I'm surprised that the Sybase customer support people thought that
  92. this was a bug.
  93.  
  94. Joseph Albert
  95. albert@hplabs.hp.com
  96.