Presentation is loading. Please wait.

Presentation is loading. Please wait.

6.830/6.814 Lecture 5 Database Internals Continued September 17, 2014.

Similar presentations


Presentation on theme: "6.830/6.814 Lecture 5 Database Internals Continued September 17, 2014."— Presentation transcript:

1 6.830/6.814 Lecture 5 Database Internals Continued September 17, 2014

2 Database Internals Outline Front End Admission Control Connection Management (sql) Parser (parse tree) Rewriter (parse tree) Planner & Optimizer (query plan) Executor Query System Storage System Access Methods Lock Manager Buffer Manager Log Manager Last time This time

3 Flattening Example Flatten this query (departments where number of machines is more than number of employees): SELECT dept.name FROM dept WHERE dept.num-of-machines ≥ (SELECT COUNT(emp.*) FROM emp WHERE dept.name=emp.dept_name) What happens if there is a department with no employees?

4 Answer SELECT dept.name FROM dept LEFT OUTER JOIN emp ON (dept.name=emp.dept_name ) GROUP BY dept.name HAVING dept.num-of-machines < COUNT(emp.*) SELECT dept.name FROM dept,emp WHERE dept.name=emp.dept_name GROUP BY dept.name HAVING dept.num-of-machines < COUNT(emp.*) “Query rewrite rules in IBM DB2 Universal Database”

5 Plan Formulation emp (eno, ename, sal, dno) dept (dno, dname, bldg) kids (kno, eno, kname, bday) SELECT ename, count(*) FROM emp, dept, kids AND emp.dno=dept.dno AND kids.eno=emp.eno AND emp.sal > AND dept.name = 'eecs' GROUP BY ename HAVING count(*) > 7

6 Query Plans Example create table dept (dno int primary key, bldg int); insert into dept (dno, bldg) select x.id, (random() * 10)::int FROM generate_series(0,100000) AS x(id); create table emp (eno int primary key, dno int references dept(dno), sal int, ename varchar); insert into emp (eno, dno, sal, ename) select x.id, (random() * )::int, (random() * 55000)::int, 'emp' || x.id from generate_series(0, ) AS x(id); create table kids (kno int primary key, eno int references emp(eno), kname varchar); insert into kids (kno,eno,kname) select x.id, (random() * )::int, 'kid' || x.id from generate_series(0, ) AS x(id);

7 Iterator Interface void open (); Tuple next (); void close ();

8 Scan Scan(tableName) this.tableName = tableName open(): f = fopen(this.tableName) next(): tuple = readTuple(f) return tuple

9 Filter Filter(pred,child): this.pred = pred this.child = child open(): this.child.open() next(): do: tuple = child.next() if (tuple == null) return null if (pred(tuple)) return tuple

10 Nested Loops Join Join(outer,inner,pred) for t1 in outer: for t2 in inner: if p(t1,t2) emit join(t1,t2) Problem: If inner is a sub-query, e.g. C D, have to continually recompute it, or store it to disk (materialize it) If inner is just a base relation (e.g., C or D), then no need for additional materialization


Download ppt "6.830/6.814 Lecture 5 Database Internals Continued September 17, 2014."

Similar presentations


Ads by Google