Consider an SQL query that specifies duplicate elimination via anDISTINCT clause. Because duplicate elimination often requires annexpensive sort of the query result, it is often worthwhile to identifynunnecessary DISTINCT clauses and avoid the sort altogether. We prove annecessary and sufficient condition for deciding if a query requiresnduplicate elimination. The condition exploits knowledge about keys,ntable constraints, and query predicates. Because the condition cannotnalways be tested efficiently, we offer a practical algorithm that testsna simpler, sufficient condition. We consider applications of thisncondition for various types of queries, and show that we can exploitnthis condition in both relational and nonregulation database systems
展开▼