Exercise #17 |
||
Get the laptop models that have a speed smaller than the speed of any PC. Result set: type, model, speed. Mistakes made here have mostly to do with overusing join operations. The most glaring example, the author believes, is the following query:
Here, the FROM clause refers to the Cartesian product of three tables! While using the Product table can be justified to some extent, since you need to display the equipment type in this task, the PC table can safely be excluded from the query – it won't affect the result. Obviously, this solution is not optimal in terms of performance. Besides, memory issues may arise, since the cardinality of the intermediate result can grow huge even for relatively small tables. Remember, the cardinality of the Cartesian product is equal to the product of the cardinalities of its operands. E.g., the Cartesian product of three tables with 100, 500 and 1000 records will contain 50000000 rows! Nevertheless, this solution is correct, since the DISTINCT statement eliminates all duplicates generated by the Cartesian product. |