Sie sind auf Seite 1von 5

Enrollment No : 499840 Name : JAGADEESWARA RAO ENNI

Assignment 7: Indexing and Query Processing


CREATE TABLE comments ( id integer NOT NULL , from_user_id integer NOT NULL default '0', to_user_id integer NOT NULL default '0', item_id integer NOT NULL default '0', rating integer default NULL, date varchar(25) default NULL, comment text, PRIMARY KEY (id)); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "comments_pkey" for table "comments" Query returned successfully with no result in 313 ms. 1. created a new table called comments. 2. inserte(100000 rows) into the comments table 3. Run the command analyze; output: Query returned successfully with no result in 1265 ms. 4. select * from comments where ID = 99999; output: 99999;778249;862311;99999;3;"2001-10-17 22:37:59";"This is a comment above average. You can trust this seller even " Total query runtime: 31 ms. 1 row retrieved. Total query runtime: 4 ms. Total query runtime: 13 ms. 1 row retrieved.

Enrollment No : 499840 Name : JAGADEESWARA RAO ENNI

select * from comments where rating = 5 and item_id = 99982; output: 99982;529834;725450;99982;5;"2001-10-17 22:37:53";"This is an exc" Total query runtime: 24 ms. 1 row retrieved. 5. explain select * from comments where rating = 5 and item_id = 99982; output: "Seq Scan on comments (cost=0.00..4164.00 rows=1 width=78)" " Filter: ((rating = 5) AND (item_id = 99982))" explain select * from comments where ID = 99999; output: "Index Scan using comments_pkey on comments (cost=0.00..8.29 rows=1 width=78)" " Index Cond: (id = 99999)" 6. create index comments_rating on comments(rating); output: Query returned successfully with no result in 202 ms. 7. select * from comments where ID = 99999; output: Total query runtime: 2 ms. 1 row retrieved.

Enrollment No : 499840 Name : JAGADEESWARA RAO ENNI select * from comments where rating = 5 and item_id = 99982; output: Total query runtime: 15 ms. 1 row retrieved. 8. create index comments_id on comments(item_id); output: Query returned successfully with no result in 182 ms. select * from comments where ID = 99999; output: 99999;778249;862311;99999;3;"2001-10-17 22:37:59";"This is a comment above average. You can trust this seller even " Total query runtime: 13 ms. 1 row retrieved. select * from comments where rating = 5 and item_id = 99982; output: Total query runtime: 12 ms. 1 row retrieved. 9. explain select * from comments where rating = 5; output: "Bitmap Heap Scan on comments (cost=330.38..3242.97 rows=19887 width=78)" " Recheck Cond: (rating = 5)" " -> Bitmap Index Scan on comments_rating (cost=0.00..325.41 rows=19887 width=0)" " Index Cond: (rating = 5)"

explain select * from comments where rating = 5 and comment = 'Q' output: "Bitmap Heap Scan on comments (cost=325.42..3287.73 rows=53 width=78)"

Enrollment No : 499840 Name : JAGADEESWARA RAO ENNI " Recheck Cond: (rating = 5)" " Filter: (comment = 'Q'::text)" " -> Bitmap Index Scan on comments_rating (cost=0.00..325.41 rows=19887 width=0)" " Index Cond: (rating = 5)"

Query Evaluation Plans

1. drop the tables in university Schema. 2. inserte( rows) into the university Schema table 3. Run the following Queries 1. select * from takes natural join student; output: Total query runtime: 3012 ms. 30000 rows retrieved. 2. select * from takes natural join student where ID = '1234'; output: Total query runtime: 2 ms. 0 rows retrieved. 3.select ID, count(*) from takes group by ID; output: Total query runtime: 72 ms. 2000 rows retrieved. 4. select * from student, instructor where student.id = instructor.id and student.id = '1234' output: Total query runtime: 12 ms.

Enrollment No : 499840 Name : JAGADEESWARA RAO ENNI 0 rows retrieved. 5. select * from student, instructor where upper(student.id) = upper(instructor.id) and student.id = '1234' output: Total query runtime: 12 ms. 0 rows retrieved.

Das könnte Ihnen auch gefallen