Incrementally Computing Ordered Answers of Acyclic Conjunctive Queries

Evaluations of SQL queries with the ORDER BY clause is considered. The naive approach of first computing the result and then sorting the tuples is not suitable for Web applications, since the result could be very large while users expect to get quickly the top-k tuples. Tractability, in this case, amounts to enumerating answers in sorted order with polynomial delay, under query-and-data complexity. It is proved that an efficient algorithm for finding the top-ranked tuple of a conjunctive query is a sufficient (and not just necessary) condition for tractability. Several classes of orders are shown to have this property when queries are acyclic.