home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / database / sybase / 372 < prev    next >
Encoding:
Text File  |  1992-11-20  |  4.2 KB  |  117 lines

  1. Newsgroups: comp.databases.sybase
  2. Path: sparky!uunet!cs.utexas.edu!uwm.edu!zaphod.mps.ohio-state.edu!wupost!gumby!destroyer!sol.ctr.columbia.edu!news.cs.columbia.edu!leland
  3. From: leland@cs.columbia.edu (Lee Woodbury)
  4. Subject: Re: multiple EXISTS subqueries under Sybase 4.8
  5. Message-ID: <By19Go.AwH@cs.columbia.edu>
  6. Keywords: EXISTS, 4.8, sun4, sunos 4.1.1
  7. Sender: news@cs.columbia.edu (The Daily News)
  8. Organization: Columbia University, Dept. of Computer Science, NYC
  9. References: <1992Nov14.174847.29576@lamont.ldgo.columbia.edu> <1992Nov15.144258.18635@panix.com>
  10. Date: Fri, 20 Nov 1992 21:09:59 GMT
  11. Lines: 104
  12.  
  13. In article <1992Nov15.144258.18635@panix.com> dbenua@panix.com (David Benua) writes:
  14. >In <1992Nov14.174847.29576@lamont.ldgo.columbia.edu> msolda@lamont.ldgo.columbia.edu (M Solda) writes:
  15. >
  16. >>does anyone know if there is a limitation in the number of EXIST subqueries
  17. >>that can be in a single query?  i have a query with an EXISTS and a NOT EXISTS
  18. >>joined by an OR, but only the rows that meet the EXISTS criteria are reported.
  19.  
  20. We found (using version 4.2) a similar error that may or may not be
  21. independent of Solda's.  Specifically, any query that has three (and
  22. presumably more, though we didn't check) NOT EXISTS conditions doesn't
  23. work in general.  You *may* get the right response depending on the
  24. order of the NOT EXISTS clauses and on the data in the database. 
  25.  
  26. Interested parties will find under my signature below a short,
  27. self-contained script demonstrating the error.  In the script, the
  28. same query is given six different ways (representing the six possible
  29. orderings of the three NOT EXISTS clauses).  You'll see that the
  30. responses vary (for the data given below, the query should return
  31. no tuples).
  32.  
  33. I'd be interested to know how the script behaves on versions later than
  34. 4.2.
  35.  
  36. We never found a workaround.  We're developing an OPS5-to-SQL compiler
  37. that generates SQL queries, so rather than figure out some arcane mess
  38. whereby the compiler would have to detect and generate alternatives,
  39. we just modified the source program that caused the problem and moved
  40. on.  (It doesn't come up much.)  But I'd be interested to hear anybody
  41. else's new ideas on the matter.
  42.  
  43. Leland Woodbury
  44. leland@cs.columbia.edu
  45.  
  46. ----------------------------------------------------------------------
  47. /* create the three relations */
  48. create table room (number char(8), capacity int)
  49. create table group_clear (something int)
  50. create table group_move (anything int)
  51.  
  52. /* insert data */
  53. insert room values ("H201", 1)
  54. insert room values ("H213", 3)
  55. insert room values ("D12", 2)
  56. insert room values ("D101", 1)
  57. insert room values ("M313", 3)
  58. insert room values ("M104", 4)
  59. insert room values ("M122", 2)
  60. insert room values ("B104", 4)
  61. insert group_clear values (0)
  62.  
  63. /* try query with various orderings of the 'not exists' conditions */
  64.  
  65. /* 1 and 2 and 3 */
  66. select * from room room1
  67. where    
  68.     not exists (select * from room room2
  69.         where room2.capacity > room1.capacity)
  70.     and not exists (select * from group_clear)
  71.     and not exists (select * from group_move)
  72.  
  73. /* 1 and 3 and 2 */
  74. select * from room room1
  75. where    
  76.     not exists (select * from room room2
  77.         where room2.capacity > room1.capacity)
  78.     and not exists (select * from group_move)
  79.     and not exists (select * from group_clear)
  80.  
  81. /* 2 and 1 and 3 */
  82. select * from room room1
  83. where    
  84.     not exists (select * from group_clear)
  85.     and not exists (select * from room room2
  86.         where room2.capacity > room1.capacity)
  87.     and not exists (select * from group_move)
  88.  
  89. /* 2 and 3 and 1 */
  90. select * from room room1
  91. where    
  92.     not exists (select * from group_clear)
  93.     and not exists (select * from group_move)
  94.     and not exists (select * from room room2
  95.         where room2.capacity > room1.capacity)
  96.  
  97. /* 3 and 1 and 2 */
  98. select * from room room1
  99. where    
  100.     not exists (select * from group_move)
  101.     and not exists (select * from room room2
  102.         where room2.capacity > room1.capacity)
  103.     and not exists (select * from group_clear)
  104.  
  105. /* 3 and 2 and 1 */
  106. select * from room room1
  107. where    
  108.     not exists (select * from group_move)
  109.     and not exists (select * from group_clear)
  110.     and not exists (select * from room room2
  111.         where room2.capacity > room1.capacity)
  112. -- 
  113. INTERNET: leland@cs.columbia.edu
  114.   USENET: ...!columbia!cs.columbia.edu!leland
  115.   BITNET: leland%cs.columbia.edu@cuvmb
  116.   USMAIL: Columbia Univ., 457 CS, 500 W. 120 St., NYC 10027-6699
  117.