Faster pages sorting in O(n) database operations