Optimized SQLite sort