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

  1. Xref: sparky comp.databases:6346 comp.databases.theory:401 comp.databases.oracle:1385
  2. Newsgroups: comp.databases,comp.databases.theory,comp.databases.oracle
  3. Path: sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watdragon.uwaterloo.ca!watdragon!gnpaulle
  4. From: gnpaulle@maytag.uwaterloo.ca (Glenn Paulley)
  5. Subject: Re: Is this a bug or a limitation of the SQL language
  6. In-Reply-To: hellers@wisc.edu's message of 26 Aug 92 00:13:05 GMT
  7. Message-ID: <BtLuFp.Kp6@watdragon.uwaterloo.ca>
  8. Sender: news@watdragon.uwaterloo.ca (USENET News System)
  9. Organization: University of Waterloo
  10. References: <1992Aug23.074048.16681@prism.poly.edu>
  11.     <1992Aug24.100941.24827@dk.oracle.com>
  12.     <JOEY.92Aug24091348@elysium.berkeley.edu>
  13.     <BtJKIG.2K5@watdragon.uwaterloo.ca>
  14.     <HELLERS.92Aug25181305@cleo.wisc.edu>
  15. Date: Wed, 26 Aug 1992 19:07:00 GMT
  16. Lines: 76
  17.  
  18. In article <HELLERS.92Aug25181305@cleo.wisc.edu> hellers@wisc.edu (Joseph Hellerstein) writes:
  19.  
  20. > In article <BtJKIG.2K5@watdragon.uwaterloo.ca> gnpaulle@maytag.uwaterloo.ca (Glenn Paulley) writes:
  21. >    > [I wrote:]
  22. >    >   |select * from emp 
  23. >    >   |where salary between
  24. >    >   |(select salary from emp where ename = 'Larry')
  25. >    >   |and
  26. >    >   |(select salary from emp where ename = 'John')
  27. >    > You want to avoid subqueries whenever possible.  To get what you need,
  28. >    > try the following:
  29. >    2) Sahil's query, if optimized using subqueries for the where predicate,
  30. >    will probably execute much faster than doing a three-way join (the
  31. >    conjuncts in the where clause are single-value lookups; if ename is
  32. >    indexed, for example, the entire result can be found using two indexed
  33. >    retrievals, and a single table scan.... no joins, no sorts). 
  34.  
  35. >This is incorrect.  Subquery processing is identical to *one kind* of
  36. >join processing, namely nested-loop with the subquery as the inner.
  37. >Hence joins will always do at least as well as subqueries, and often
  38. >better, since the space of paths for the optimizer to choose from is
  39. >larger.  To argue that subquery processing is simpler than join
  40. >processing is just wrong.  It's a kind of join processing itself, with
  41. >restricted output semantics.
  42.  
  43. 100% agreed. However, the scalar subqueries above are not correlated, so
  44. I still fail to see how join processing could perform better than (basically)
  45. a single scan- nested loops aren't required. Again, I'm assuming that 
  46. ename is indexed, or in some way it's possible to determine Larry 
  47. and John's salary quickly.
  48.  
  49. As an aside:
  50.  
  51. As pointed out by map@sequent.com (Michael Perry) these two
  52. scalar subqueries must return single rows, or a run-time error occurs.
  53. Also, a good point is made by kent@manzi.unx.sas.com (Paul Kent) that
  54. the semantics of BETWEEN are questionable. My copy of the ISO 
  55. SQL2 standard (ISO/IEC JTC1/SC21 N5215, December 1, 1990)
  56. says that "x BETWEEN y AND z" is equivalent to "x>=y AND x<=z"; thus a 
  57. NULL result will occur if John earns less than Larry (as correctly assumed
  58. by Paul). 
  59.  
  60. Both of the above also affect your join version in the same way, so
  61. there's no problem there.
  62.  
  63. > And see the paper by Pirahesh, Hellerstein, and Hasan in SIGMOD '92
  64. > which demonstrates that subquery-to-join *can* be done correctly (and
  65. > is done automatically in Starburst) for all existential subqueries
  66. > that are Boolean Factors (i.e. IN, ANY, or EXISTS subqueries that are
  67. > outer conjuncts of the WHERE clause, not nested under NOT or OR, etc.)
  68.  
  69. I realize this (I have seen your paper, and others, on this subject).
  70. The point I was trying to make is that I don't believe such transformations
  71. are possible for *all* forms of subqueries (eg. universal quantification
  72. and/or negation), so the heuristic isn't true in all cases (but is true in
  73. this one).
  74.  
  75. > You have to be careful, but the rewrite I gave him will work
  76. > correctly, may well speed up his query, and may even sneak by his
  77. > limited parser.
  78.  
  79. Yes. Again, agreed.
  80.  
  81. I must say it's a pleasure to discuss these issues with someone of Mr.
  82. Hellerstein's reputation. I follow your results on Starburst query
  83. rewrite optimization, and other papers on Starburst, with interest.
  84.  
  85. Best regards.
  86.  
  87. --
  88. -- G. N. (Glenn) Paulley                 | Computer Science Department
  89. -- USENET: gnpaulle@bluebox.uwaterloo.ca | University of Waterloo
  90. -- Phone: (519) 885-1211 x3490           | 200 University Avenue
  91. -- Fax: (519) 885-1208   Office: DC3142  | Waterloo, Ontario, Canada N2L 3G1
  92.