Notes06 - CS245:DatabaseSystem Principles...

Info icon This preview shows pages 1–16. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 245 Notes 6 1 CS 245: Database System  Principles Notes 6: Query Processing Steven Whang
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 245 Notes 6 2 Query Processing Q      Query Plan Focus:  Relational System Others?
Image of page 2
CS 245 Notes 6 3 Example Select B,D From R,S Where R.A = “c”     S.E = 2     R.C=S.C
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 245 Notes 6 4 R A B C S C D E a 1 10 10 x 2 b 1 20 20 y 2 c 2 10 30 z 2 d 2 35 40 x 1 e 3 45 50 y 3 Answer B D 2 x
Image of page 4
CS 245 Notes 6 5  How do we execute query? - Do Cartesian product - Select tuples - Do projection One idea
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 245 Notes 6 6 RXS R.A R.B R.C S.C S.D S.E a 1 10 10 x 2 a 1 10 20 y 2 . . C 2 10 10 x 2 . . Bingo! Got one...
Image of page 6
CS 245 Notes 6 7 Relational Algebra  - can be used to    describe plans... Ex:  Plan I Π B,D   σ R.A =“c”  S.E=2   R.C=S.C X R S OR:    Π B,D  [   σ R.A=“c”  S.E=2   R.C = S.C  (RXS)]
Image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 245 Notes 6 8 Another idea: Π B,D    σ R.A = “c”   σ S.E = 2 R   S Plan II natural join
Image of page 8
CS 245 Notes 6 9    R         S A  B  C σ ( R ) σ ( S )      C  D  E a  1  10        A   B  C       C  D  E     10  x  2 b  1  20 c   2  10     10  x  2     20  y  2 c  2  10        20  y  2     30  z  2 d  2  35        30  z  2     40  x  1 e  3  45                                         50  y  3
Image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 245 Notes 6 10 Plan III  Use R.A and S.C Indexes (1) Use R.A index to select R tuples    with R.A = “c” (2) For each R.C value found, use S.C   index to find matching tuples (3) Eliminate S tuples S.E   2 (4) Join matching R,S tuples, project    B,D attributes and place in result
Image of page 10
CS 245 Notes 6 11    R         S A  B  C      C  D  E a  1  10                  10  x  2 b  1  20     20  y  2 c  2  10             30  z  2 d  2  35             40  x  1 e  3  45                                         50  y  3 A C I 1 I 2 =“c” <c,2,10> <10,x,2> check=2? output: <2,x> next tuple: <c,7,15>
Image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 245 Notes 6 12 Overview of Query Optimization
Image of page 12
CS 245 Notes 6 13 parse convert apply laws estimate result sizes consider physical plans estimate costs pick best execute {P1,P2,…..} {(P1,C1),(P2,C2)...} Pi    answer SQL query parse tree logical query plan “improved” l.q.p l.q.p. +sizes statistics
Image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CS 245 Notes 6 14 Example:    SQL query SELECT title FROM StarsIn WHERE starName IN ( SELECT name FROM MovieStar WHERE birthdate LIKE ‘%1960’ ); (Find the movies with stars born in 1960)
Image of page 14
CS 245 Notes 6 15 Example:    Parse Tree <Query> <SFW> SELECT   <SelList>    FROM    <FromList>     WHERE     <Condition> <Attribute>              <RelName>                 <Tuple>  IN  <Query>
Image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern