Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27.

Similar presentations


Presentation on theme: "LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27."— Presentation transcript:

1 LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27

2 Announcement HOMEWORK #4 –Due: 6/9 Thur. (2 weeks left) FINAL EXAM –6/14 Tues. 17:00 PROJECT #1 –Due: 6/17 Fri.

3 movieLens Database 1,000,209 3,883 6,040 idgenderageoccup ation zipcode 1F11048067 2M561670072 3M251555117 …………… idtitlegenres 1Toy StoryAnimation|Child ren’s|Comedy 21Waiting to Exhale Comedy|Drama 104Get ShortyAction|Comedy| Drama ………. useridmovieidratingts (timestamp) 115978824268 2211978299839 31044978298486 …………

4 Table Access Full mysql> EXPLAIN SELECT * FROM users; +----+-------------+-------+------+---------------+------+---------+------+------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+------+-------+ | 1 | SIMPLE | users | ALL | NULL | NULL | NULL | NULL | 5891 | | +----+-------------+-------+------+---------------+------+---------+------+------+-------+ 1 row in set (0.00 sec) mysql> SHOW SESSION STATUS LIKE 'Last_query_cost'; +-----------------+-------------+ | Variable_name | Value | +-----------------+-------------+ | Last_query_cost | 1196.199000 | +-----------------+-------------+ 1 row in set (0.02 sec) users http://dev.mysql.com/doc/refman/5.0/en/explain-output.html

5 Index Full Scan mysql> EXPLAIN SELECT * FROM users ORDER BY id; +-------------+-------+-------+---------------+---------+---------+------+------+-------+ | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------------+-------+-------+---------------+---------+---------+------+------+-------+ | SIMPLE | users | index | NULL | PRIMARY | 4 | NULL | 5891 | | +-------------+-------+-------+---------------+---------+---------+------+------+-------+ 1 row in set (0.00 sec) (id column is omitted) mysql> SHOW SESSION STATUS LIKE 'Last_query_cost'; +-----------------+-------------+ | Variable_name | Value | +-----------------+-------------+ | Last_query_cost | 7087.199000 | +-----------------+-------------+ 1 row in set (0.03 sec) users

6 Index Unique Scan mysql> EXPLAIN SELECT * FROM users WHERE id = 300; +-------------+-------+-------+---------------+---------+---------+-------+------+-------+ | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------------+-------+-------+---------------+---------+---------+-------+------+-------+ | SIMPLE | users | const | PRIMARY | PRIMARY | 4 | const | 1 | | +-------------+-------+-------+---------------+---------+---------+-------+------+-------+ 1 row in set (0.00 sec) (id column is omitted) mysql> SHOW SESSION STATUS LIKE 'Last_query_cost'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | Last_query_cost | 0.000000 | +-----------------+----------+ 1 row in set (0.03 sec) users

7 Index Range Scan mysql> EXPLAIN SELECT * FROM users WHERE id BETWEEN 100 AND 1000; +-------------+-------+-------+---------------+---------+---------+------+------+---------+ | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------------+-------+-------+---------------+---------+---------+------+------+---------+ | SIMPLE | users | range | PRIMARY | PRIMARY | 4 | NULL | 1728 | Using | | where | +-------------+-------+-------+---------------+---------+---------+------+------+---------+ 1 row in set (0.00 sec) (id column is omitted) mysql> SHOW SESSION STATUS LIKE 'Last_query_cost'; +-----------------+------------+ | Variable_name | Value | +-----------------+------------+ | Last_query_cost | 694.051654 | +-----------------+------------+ 1 row in set (0.03 sec) users

8 Index Fast Full Scan mysql> EXPLAIN SELECT id FROM users; +-------------+-------+-------+---------------+---------+---------+------+------+---------+ | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +-------------+-------+-------+---------------+---------+---------+------+------+---------+ | SIMPLE | users | index | NULL | PRIMARY | 4 | NULL | 5891 | Using | | index | +-------------+-------+-------+---------------+---------+---------+------+------+---------+ 1 row in set (0.00 sec) (id column is omitted) mysql> SHOW SESSION STATUS LIKE 'Last_query_cost'; +-----------------+-------------+ | Variable_name | Value | +-----------------+-------------+ | Last_query_cost | 1196.199000 | +-----------------+-------------+ 1 row in set (0.02 sec) users

9 Join mysql> EXPLAIN SELECT * FROM users, ratings WHERE users.id = ratings.userid; +-------------+---------+------+---------------+---------+---------+----------+------+ | select_type | table | type | possible_keys | key | key_len | ref | rows | +-------------+---------+------+---------------+---------+---------+----------+------+ | SIMPLE | users | ALL | PRIMARY | NULL | NULL | NULL | 5915 | | SIMPLE | ratings | ref | PRIMARY | PRIMARY | 4 | users.id | 61 | +-------------+---------+------+---------------+---------+---------+----------+------+ 2 rows in set (0.00 sec) (id, extra columns are omitted) mysql> SHOW SESSION STATUS LIKE 'Last_query_cost'; +-----------------+---------------+ | Variable_name | Value | +-----------------+---------------+ | Last_query_cost | 432994.999000 | +-----------------+---------------+ 1 row in set (0.05 sec) UsersRatings

10 3-way Join mysql> EXPLAIN SELECT * FROM users, ratings, movies -> WHERE users.id = ratings.userid AND ratings.movieid = movies.id; +-------------+---------+--------+-------------------+---------+---------+-----------------+------+ | select_type | table | type | possible_keys | key | key_len | ref | rows | +-------------+---------+--------+-------------------+---------+---------+-----------------+------+ | SIMPLE | users | ALL | PRIMARY | NULL | NULL | NULL | 5915 | | SIMPLE | ratings | ref | PRIMARY, | PRIMARY | 4 | users.id | 61 | | fk_ratings_movies | | SIMPLE | movies | eq_ref | PRIMARY | PRIMARY | 4 | ratings.movieid | 1 | +-------------+---------+--------+-------------------+---------+---------+-----------------+------+ 3 rows in set (0.00 sec) (id, extra columns are omitted) mysql> SHOW SESSION STATUS LIKE 'Last_query_cost'; +-----------------+---------------+ | Variable_name | Value | +-----------------+---------------+ | Last_query_cost | 433055.999000 | +-----------------+---------------+ 1 row in set (0.00 sec) MoviesRatings Users

11 Oracle with SQL*Plus Oracle Database 10g Express Edition –with SQL*Plus $ sqlplus SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 27 00:04:06 2011 Copyright (c) 1982, 2005, Oracle. All rights reserved. Enter user-name: student Enter password: csed421 Connected to: Oracle Database 10g Express Edition Release 10.2.0.1.0 – Production SQL> _

12 Autotrace in SQL*Plus To get a report on the execution path used by the SQL optimizer and the statement execution statistics – ≒ EXPLAIN in MySQL SQL> set autotrace on –Query result + Execution plan + Statistics SQL> set autotrace traceonly –Execution plan + Statistics ( + Query execution in background) SQL> set autotrace traceonly explain –Execution plan SQL> set autotrace off http://download.oracle.com/docs/cd/B10500_01/server.920/a96533/autotrac.htm

13 Execution Plan CategoriesSubjects Classes

14 Demos Scan –Table Access Full –Index Full Scan –Index Unique Scan –Index Range Scan –Index Fast Full Scan Join –Hash Join –Nested Loop Join –Sort Merge Join –3-way Join

15 Table Access Full Users

16 Index Full Scan Users

17 Index Unique Scan Users

18 Index Range Scan Users

19 Index Fast Full Scan Users

20 Hash Join Cost: 900 + 7 + α = 921 UsersRatings

21 Nested Loop Join Cost: 1000K * 1 + 900 + α = 1002K UsersRatings

22 Sort Merge Join Cost: 32 + 5936 + α = 5969 UsersRatings

23 3-way Join MoviesRatings Users

24 3-way Outer Join UsersRatings Movies

25 Internal Sort

26 External Sort

27 Analyze Statistics of Table SQL> analyze table table_name compute statistics; SQL> analyze index index_name validate structure;


Download ppt "LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27."

Similar presentations


Ads by Google