12.07.2015 Views

6.830 Problem Set 2 (2009) - MIT Database Group

6.830 Problem Set 2 (2009) - MIT Database Group

6.830 Problem Set 2 (2009) - MIT Database Group

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>6.830</strong> <strong>Problem</strong> <strong>Set</strong> 2 Solutions 6c. Suppose the crossover point (from the previous question) between queries 1 and 2 is s 0 . Compare the actualrunning times corresponding to the two alternative query plans at the crossover point. How much do they differ?Inside psql, you can measure the query time by using the \timing command to turn timing on for all queries. Toget accurate timing, you may also wish to redirect output to /dev/null, using the command \o /dev/null;you can stop redirection just by issuing the \o command without a file name. You may also wish to run each queryseveral times, throwing out the first time (which may be longer as data is loaded into the buffer pool) and averagingthe remaining runs.AnswerSELECT researchers.orgFROM researchers, grantsWHERE researchers.id = grants.piAND grants.amount > 31597642;Time: .816 msSELECT researchers.orgFROM researchers, grantsWHERE researchers.id = grants.piAND grants.amount > 31597641;Time: 3.552 msSELECT researchers.orgFROM researchers, grantsWHERE researchers.id = grants.piAND grants.amount > 500000;Time: 9.48 msSELECT researchers.orgFROM researchers, grantsWHERE researchers.id = grants.piAND grants.amount > 499999;Time: 13.61 msd. Based on your answers to the previous two problems, is s 0 actually the best place to switch plans, or is it anoverestimate/underestimate of the best crossover point? If s 0 is not the actual crossover point, can you estimatethe actual best crossover point without running queries against the database? State assumptions underlying youranswer, if any.The crossover between the two plans appears to be incorrect. The index nested loops based join wouldstill have been a better choice (this is probably because, although the query is estimated to produce 27or 28 results, it only produces 4, resulting in fewer index lookups than estimated.)It is hard to accurately estimate the actual crossover point without knowing the number of index lookupsperformed on researchers at various points, but the crossover point will occur when the cost of buildingthe hash table on researchers is less than the cost of this number of lookups.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!