Finally I decided to add pagination and performance issues had gone away. Still don't know why selecting several thousands is slow, it seems strange for me.