SELECT Bars.address FROM Drinkers, Bars WHERE Drinkers.name = 'joe' AND Drinkers.frequents = Bars.name;we might use an index on Drinkers.name to help us find the tuple for drinker Joe quickly. We might also like an index on Bars.name, so we can take all the bars Joe frequents and quickly find the tuples for those bars to read their addresses.
In Oracle, you can get an index by the command:
CREATE INDEX <IndexName> ON <RelName>(<Attribute List>) TABLESPACE indexes;Note:
If the attribute list 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, for example. An illustration of the CREATE INDEX command is
CREATE INDEX DrinkerInd ON Drinkers(name) TABLESPACE indexes; CREATE INDEX BarInd ON Bars(name) TABLESPACE indexes;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 at least two useful indexes for your PDA. Run your queries from part (1) on your large database with the indexes and without the indexes. To time your commands, you may issue the following commands to sqlplus:
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.
Sometimes, (1) or (2) are easier at first, but after figuring it out, you can write a single query with subqueries. Any of these three approaches are OK for the problem set.
All queries should be written in standard SQL2.
Suppose we have a relation Bids(bidder,price,quantity), representing bids for 10 Beanie Babies. In this problem, you should assume that there may be several different bidders bidding the same price, perhaps for different numbers of items.
Hint: Start by constructing a table that gives for each price, the total number bid at that price. You have to join this table with itself to get another table that gives, for each price, the total number bid at that price or higher.
Bids(auctionID, bidder, price, quantity) Auctions(auctionID, seller, item, quantity, expires) Ratings(seller, stars)The relations and attributes should be self explanatory, except perhaps for the last relation, which is intended to be a table of ratings that sellers have received from buyers. Each seller mentioned in Auctions has received 0 or more ratings, and each rating is in the form of a number of stars, from 1 to 5.