GATE 2005
203 questions
MCQ 2031-mark 203
Questions 161–165 of 203
Let r be a relation instance with schema R = (A, B, C, D). We define and . Let where * denotes natural join. Given that the decomposition of r into and is lossy, which one of the following is TRUE?
Answer: (C)
Let . Take any tuple of r. Its projections are in r1 and is in r2. They agree on A, so they join to give in s. So every tuple of r is in s, that is .
The decomposition is lossy, so s also has extra (spurious) tuples. So the inclusion is proper: .
Example:
Every row of r also appears in s (shown in bold). The other two rows of s are spurious.
- (A) is false, since s is bigger than r.
- (B) , not r, because s has extra tuples.
- (D) joins on all four attributes, so it keeps exactly the tuples in both, which is r. So , not s.
Answer: (C)
The decomposition is lossy, so s also has extra (spurious) tuples. So the inclusion is proper: .
Example:
Every row of r also appears in s (shown in bold). The other two rows of s are spurious.
- (A) is false, since s is bigger than r.
- (B) , not r, because s has extra tuples.
- (D) joins on all four attributes, so it keeps exactly the tuples in both, which is r. So , not s.
Answer: (C)
A database table has 2000 records and occupies 80 disk blocks. Another table has 400 records and occupies 20 disk blocks. These two tables have to be joined as per a specified join condition that needs to be evaluated for every pair of records from these two tables. The memory buffer space available can hold exactly one block of records for and one block of records for simultaneously at any point in time. No index is available on either table.
If, instead of Nested-loop join, Block nested-loop join is used, again with the most appropriate choice of table in the outer loop, the reduction in number of block accesses required for reading the data will be
If, instead of Nested-loop join, Block nested-loop join is used, again with the most appropriate choice of table in the outer loop, the reduction in number of block accesses required for reading the data will be
Answer: (B)
Cost is counted in block accesses, with room for one block of each table in the buffer.
Nested-loop join: read the outer table once, and for every outer record read the whole inner table.
T2 as outer:
T1 as outer:
So T2 is the better outer table and the cost is 32020.
Block nested-loop join: read the outer table once, and for every outer block read the whole inner table.
T2 as outer:
T1 as outer:
The better choice is T2 as outer, with cost 1620.
Reduction .
Answer: (B)
Nested-loop join: read the outer table once, and for every outer record read the whole inner table.
T2 as outer:
T1 as outer:
So T2 is the better outer table and the cost is 32020.
Block nested-loop join: read the outer table once, and for every outer block read the whole inner table.
T2 as outer:
T1 as outer:
The better choice is T2 as outer, with cost 1620.
Reduction .
Answer: (B)
A database table has 2000 records and occupies 80 disk blocks. Another table has 400 records and occupies 20 disk blocks. These two tables have to be joined as per a specified join condition that needs to be evaluated for every pair of records from these two tables. The memory buffer space available can hold exactly one block of records for and one block of records for simultaneously at any point in time. No index is available on either table.
If Nested-loop join algorithm is employed to perform the join, with the most appropriate choice of table to be used in outer loop, the number of block accesses required for reading the data are
If Nested-loop join algorithm is employed to perform the join, with the most appropriate choice of table to be used in outer loop, the number of block accesses required for reading the data are
Answer: (C)
First we must decide which table goes in the outer loop. To keep block accesses low, the table with fewer records should be the outer one, because every outer record needs a pass over the inner table's blocks.
So, with table as the outer table (T2):
- For each of the records
- we need block accesses on the first table, which gives accesses.
- Add block accesses to read the outer table.
Hence the answer is
Correct answer: C.
In an inventory management system implemented at a trading corporation, there are several tables designed to hold all the information. Amongst these, the following two tables hold information on which items are supplied by which suppliers, and which warehouse keeps which items along with the stock-level of these items.
Supply = (supplierid, itemcode)
Inventory = (itemcode, warehouse, stocklevel)
For a specific information required by the management, following SQL query has been written
For the warehouse at Nagpur, this query will find all suppliers wh
Supply = (supplierid, itemcode)
Inventory = (itemcode, warehouse, stocklevel)
For a specific information required by the management, following SQL query has been written
Select distinct STMP.supplierid
From Supply as STMP
Where not unique (Select ITMP.supplierid
From Inventory, Supply as ITMP
Where STMP.supplierid = ITMP.supplierid
And ITMP.itemcode = Inventory.itemcode
And Inventory.warehouse = 'Nagpur'); For the warehouse at Nagpur, this query will find all suppliers wh
Answer: (D)
NOT UNIQUE is true when the subquery result contains a repeated row. UNIQUE is true for an empty result and for a result with no repeated row.
For a supplier s in the outer query, the subquery returns s's supplierid once for each item that s supplies and that the Nagpur warehouse keeps (the item code matches an Inventory row with warehouse = 'Nagpur'). Taking (itemcode, warehouse) as identifying an Inventory row, each such item gives one row.
- 0 such items: empty result, UNIQUE is true, NOT UNIQUE is false, so s is not selected.
- exactly 1 such item: one row, no repeat, so s is not selected.
- 2 or more such items: the same supplierid repeats, NOT UNIQUE is true, so s is selected.
So the query finds suppliers that supply two or more items kept at Nagpur. (A), (B) and (C) are wrong because suppliers with no item or exactly one item are not selected.
Answer: (D)
For a supplier s in the outer query, the subquery returns s's supplierid once for each item that s supplies and that the Nagpur warehouse keeps (the item code matches an Inventory row with warehouse = 'Nagpur'). Taking (itemcode, warehouse) as identifying an Inventory row, each such item gives one row.
- 0 such items: empty result, UNIQUE is true, NOT UNIQUE is false, so s is not selected.
- exactly 1 such item: one row, no repeat, so s is not selected.
- 2 or more such items: the same supplierid repeats, NOT UNIQUE is true, so s is selected.
So the query finds suppliers that supply two or more items kept at Nagpur. (A), (B) and (C) are wrong because suppliers with no item or exactly one item are not selected.
Answer: (D)
A table 'student' with schema (roll, name, hostel, marks), and another table 'hobby' with schema (roll, hobbyname) contains records as shown below:
The following SQL query is executed on the above tables:
Relations S and H with the same schema as those of these two tables respectively contain the same information as tuples. A new relation S is obtained by the following relational algebra operation:
The difference between the number of rows output by the SQL statement and the number of tuples in S' is
The following SQL query is executed on the above tables:
select hostel
from student natural join hobby
where marks >= 75 and roll between 2000 and 3000; Relations S and H with the same schema as those of these two tables respectively contain the same information as tuples. A new relation S is obtained by the following relational algebra operation:
The difference between the number of rows output by the SQL statement and the number of tuples in S' is
Answer: (B)
SQL query. The natural join is on roll. It keeps students with marks 75 and roll between 2000 and 3000. These are 2369, 2581, 2643, 2872, 2926 and 2959. (2154 has 68 marks and 2711 has 72, so they are out.) Each student gives one row for each hobby:
2369 (hostel 7), 2581 (6), 2643 chess (5), 2643 hockey (5), 2872 (5), 2926 (5), 2959 (7).
Roll 2643 appears twice because it has two hobbies. The query selects hostel and has no DISTINCT, so it outputs 7 rows.
Relational algebra S'. The selection gives the same students (no student has marks exactly 75 or roll exactly 2000 or 3000, so and make no difference here). The projection on hostel in relational algebra works on sets, so it removes duplicates and leaves the hostels 5, 6 and 7. So S' has 3 tuples.
Difference .
Answer: (B)
2369 (hostel 7), 2581 (6), 2643 chess (5), 2643 hockey (5), 2872 (5), 2926 (5), 2959 (7).
Roll 2643 appears twice because it has two hobbies. The query selects hostel and has no DISTINCT, so it outputs 7 rows.
Relational algebra S'. The selection gives the same students (no student has marks exactly 75 or roll exactly 2000 or 3000, so and make no difference here). The projection on hostel in relational algebra works on sets, so it removes duplicates and leaves the hostels 5, 6 and 7. So S' has 3 tuples.
Difference .
Answer: (B)