If you have modified your design because of feedbacks from the instructor (or any other reason), please explain the reasons in your report.
SELECT Bars.addresswe might use an index on Frequents.drinker to help us find the tuple for drinker Fred quickly. We might also like an index on Bars.name, so we can take all the bars Fred frequents and quickly find the tuples for those bars to read their addresses.
FROM Frequents, Bars
WHERE Frequents.drinker = 'fred'
AND Frequents.bar = Bars.name;
In PostgreSQL, you can get an index by the command:
CREATE INDEX <IndexName> ON <RelationName>(<Attribute List>);Note:
If the attribute list for an index contains more than one attribute, then the index requires values for all the listed attributes to find a tuple. That situation might be helpful if the attributes together form a key.
An illustration of the CREATE INDEX command is
CREATE INDEX FreqDrinkerInd ON Frequents(drinker);which creates the two indexes mentioned above. To get rid of an index, you can say DROP INDEX followed by the name of the index. Notice that each index must have a name, even though we only refer to the name if we want to drop the index.
CREATE INDEX BarInd ON Bars(name);
Now, you are ready to run your experiments. Create at least two useful indexes for your PDA. Run your queries from previous lab on your large database with the indexes and without the indexes. To time your commands, you may type \timing after logging into PostgreSQL. This will start the timer and show the running time for each of your queries in milliseconds.
Naturally these times may be affected by external factors such as system load, etc. Still, you should see a dramatic difference between the execution times with indexes and the times without. Turn in a script showing your commands to create indexes, and showing the relative times of query execution with and without indexes.
Note: Often, students discover that indexes appear to slow down the execution of queries. There are two issues you should consider: